Subversion Repositories SmartDukaan

Rev

Rev 34664 | Rev 35170 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34664 Rev 34794
Line 155... Line 155...
155
 
155
 
156
    @Autowired
156
    @Autowired
157
    JavaMailSender mailSender;
157
    JavaMailSender mailSender;
158
 
158
 
159
    @RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, method = RequestMethod.POST)
159
    @RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, method = RequestMethod.POST)
160
    public ResponseEntity<?> googleLogin(HttpServletRequest request, @RequestBody GoogleLoginRequest googleLoginRequest) throws Exception {
160
    public ResponseEntity<?> googleLogin(HttpServletRequest request, @RequestBody GoogleLoginRequest loginRequest) throws Exception {
161
        String email = googleLoginRequest.getEmail() != null ? googleLoginRequest.getEmail() : googleLoginProcessor.process(googleLoginRequest.getToken());
161
        String email = loginRequest.getEmail() != null ? loginRequest.getEmail() : googleLoginProcessor.process(loginRequest.getToken());
162
        return responseSender.ok(getAuthTokenMap(email));
162
        return responseSender.ok(getAuthTokenMap(email, loginRequest));
163
    }
163
    }
164
 
164
 
165
    private Map<String, Object> getAuthTokenMap(String email) throws Exception {
165
    private Map<String, Object> getAuthTokenMap(String email, GoogleLoginRequest loginRequest) throws Exception {
166
        String name = authService.getNameByEmailId(email);
166
        String name = authService.getNameByEmailId(email);
167
 
167
 
168
        Map<String, Object> responseMap = new HashMap<>(2);
168
        Map<String, Object> responseMap = new HashMap<>(2);
169
        LOGGER.info("User Name from getNameByEmailId({}) is {}", email, name);
169
        LOGGER.info("User Name from getNameByEmailId({}) is {}", email, name);
170
        if (name != null) {
170
        if (name != null) {
171
            User registeredUser = null;
171
            User registeredUser = null;
172
            AuthUser authUser = authRepository.selectByGmailId(email);
172
            AuthUser authUser = authRepository.selectByGmailId(email);
-
 
173
            if (loginRequest.getPassword() != null) {
-
 
174
                registeredUser = userService.authenticate(email, loginRequest.getPassword());
173
            if (authUser != null) {
175
            } else if (authUser != null) {
174
                registeredUser = userRepository.selectByEmailId(authUser.getEmailId());
176
                registeredUser = userRepository.selectByEmailId(authUser.getEmailId());
175
            } else if (promoterRepository.selectMappedByEmailId(email) != null) {
177
            } else if (promoterRepository.selectMappedByEmailId(email) != null) {
176
                Promoter promoter = promoterRepository.selectMappedByEmailId(email);
178
                Promoter promoter = promoterRepository.selectMappedByEmailId(email);
177
                int userId = userAccountRepository.selectUserIdByRetailerId(promoter.getRetailerId());
179
                int userId = userAccountRepository.selectUserIdByRetailerId(promoter.getRetailerId());
178
                registeredUser = userRepository.selectById(userId);
180
                registeredUser = userRepository.selectById(userId);
Line 194... Line 196...
194
                if (authUserPartnerSet != null && authUserPartnerSet.size() > 0) {
196
                if (authUserPartnerSet != null && authUserPartnerSet.size() > 0) {
195
                    retailerId = authUserPartnerSet.stream().findFirst().get();
197
                    retailerId = authUserPartnerSet.stream().findFirst().get();
196
                    FofoStore fs = fofoStoreRepository.selectByRetailerId(retailerId);
198
                    FofoStore fs = fofoStoreRepository.selectByRetailerId(retailerId);
197
                    retailerId = partnerTypeChangeService.getBestPartner(fs.getWarehouseId());
199
                    retailerId = partnerTypeChangeService.getBestPartner(fs.getWarehouseId());
198
                } else {
200
                } else {
199
                    com.spice.profitmandi.dao.entity.user.User user = userUserRepository
201
                    com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectByEmailId(Utils.SYSTEM_PARTNER);
200
                            .selectByEmailId(Utils.SYSTEM_PARTNER);
-
 
201
                    retailerId = user.getId();
202
                    retailerId = user.getId();
202
                }
203
                }
203
            }
204
            }
204
            responseMap.put(ProfitMandiConstants.TOKEN,
205
            responseMap.put(ProfitMandiConstants.TOKEN,
205
                    JWTUtil.create(email, registeredUser.getId(), retailerId, roleTypes));
206
                    JWTUtil.create(email, registeredUser.getId(), retailerId, roleTypes));
Line 209... Line 210...
209
            return responseMap;
210
            return responseMap;
210
        }
211
        }
211
 
212
 
212
        User user = null;
213
        User user = null;
213
        try {
214
        try {
-
 
215
            if (loginRequest.getPassword() != null) {
-
 
216
                user = userService.authenticate(email, loginRequest.getPassword());
-
 
217
            } else {
214
            user = userRepository.selectByEmailId(email);
218
                user = userRepository.selectByEmailId(email);
-
 
219
            }
215
        } catch (ProfitMandiBusinessException profitMandiBusinessException) {
220
        } catch (ProfitMandiBusinessException profitMandiBusinessException) {
216
 
221
 
217
        }
222
        }
218
        if (user == null) {
223
        if (user == null) {
219
            try {
224
            try {
Line 242... Line 247...
242
            throws ProfitMandiBusinessException {
247
            throws ProfitMandiBusinessException {
243
        LOGGER.info("StoreCode {}", storeCode);
248
        LOGGER.info("StoreCode {}", storeCode);
244
        return responseSender.ok(googleLoginProcessor.processStore(storeCode));
249
        return responseSender.ok(googleLoginProcessor.processStore(storeCode));
245
    }
250
    }
246
 
251
 
-
 
252
    @RequestMapping(value = ProfitMandiConstants.URL_USER_FORGOT_PASSWORD, method = RequestMethod.POST)
-
 
253
    public ResponseEntity<?> forgotPassword(@RequestBody GoogleLoginRequest loginRequest) throws Exception {
-
 
254
        userService.resetPassword(loginRequest.getEmail());
-
 
255
        return responseSender.ok(true);
-
 
256
    }
-
 
257
 
-
 
258
    @RequestMapping(value = ProfitMandiConstants.URL_USER_CHANGE_PASSWORD, method = RequestMethod.POST)
-
 
259
    public ResponseEntity<?> changePassword(@RequestBody EmailPassword emailPassword) throws Exception {
-
 
260
        User user = userService.authenticate(emailPassword.getEmail(), emailPassword.getPassword());
-
 
261
        if (user != null){
-
 
262
            boolean response = userService.changePassword(user, emailPassword.getNewPassword());
-
 
263
            return responseSender.ok(response);
-
 
264
        }
-
 
265
        return responseSender.ok(false);
-
 
266
    }
-
 
267
 
247
    @RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_IS_EXPIRED, method = RequestMethod.GET)
268
    @RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_IS_EXPIRED, method = RequestMethod.GET)
248
    public ResponseEntity<?> tokenIsExpired(HttpServletRequest request, @RequestParam(name = "token") String token)
269
    public ResponseEntity<?> tokenIsExpired(HttpServletRequest request, @RequestParam(name = "token") String token)
249
            throws ProfitMandiBusinessException {
270
            throws ProfitMandiBusinessException {
250
        LOGGER.info("requested url : " + request.getRequestURL().toString());
271
        LOGGER.info("requested url : " + request.getRequestURL().toString());
251
        return responseSender.ok(JWTUtil.isExpired(token));
272
        return responseSender.ok(JWTUtil.isExpired(token));
Line 335... Line 356...
335
                com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(uc.getUserId());
356
                com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(uc.getUserId());
336
                if (saholicUser.getAddressId() != null) {
357
                if (saholicUser.getAddressId() != null) {
337
                    Address address = addressRepository.selectById(saholicUser.getAddressId());
358
                    Address address = addressRepository.selectById(saholicUser.getAddressId());
338
                    responseMap.put(ProfitMandiConstants.ADDRESS, address);
359
                    responseMap.put(ProfitMandiConstants.ADDRESS, address);
339
                }
360
                }
340
                // if retailer is activated 1 then verified retailer
-
 
341
                // else if migrated is 1 then old retailer
-
 
342
                // also lets incoporte old process i.e is user is activated then also retailer
-
 
343
                // is verified retailer
-
 
344
                // else retailer is not verifed
-
 
-
 
361
 
345
                if (retailer.isActive() || user.isActivated()) {
362
                if (retailer.isActive() || user.isActivated()) {
346
                    if (roleManager.isPartner(roleIdsSet)) {
363
                    if (roleManager.isPartner(roleIdsSet)) {
347
                        FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(saholicUser.getId());
364
                        FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(saholicUser.getId());
348
                        if (fofoStore.isActive()) {
365
                        if (fofoStore.isActive()) {
349
                            responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.FOFO.getValue());
366
                            responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.FOFO.getValue());
Line 548... Line 565...
548
        userRepository.persist(user);
565
        userRepository.persist(user);
549
        return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1001"));
566
        return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1001"));
550
    }
567
    }
551
 
568
 
552
    @RequestMapping(value = ProfitMandiConstants.URL_ADMIN_TOKEN, method = RequestMethod.POST)
569
    @RequestMapping(value = ProfitMandiConstants.URL_ADMIN_TOKEN, method = RequestMethod.POST)
553
    public ResponseEntity<?> getAdminToken(HttpServletRequest request,
-
 
554
                                           @RequestParam(name = "adminToken") String adminToken, @RequestParam(name = "emailId") String emailId)
570
    public ResponseEntity<?> getAdminToken(HttpServletRequest request, @RequestParam(name = "adminToken") String adminToken, @RequestParam(name = "emailId") String emailId) throws Exception {
555
            throws Exception {
-
 
556
        LOGGER.info("requested url : " + request.getRequestURL().toString());
571
        LOGGER.info("requested url : " + request.getRequestURL().toString());
557
        if (!adminToken.equals(validAdminToken)) {
572
        if (!adminToken.equals(validAdminToken)) {
558
            return responseSender.forbidden(null);
573
            return responseSender.forbidden(null);
559
        }
574
        }
-
 
575
        GoogleLoginRequest loginRequest = new GoogleLoginRequest();
-
 
576
        loginRequest.setToken(adminToken);
-
 
577
        loginRequest.setEmail(emailId);
-
 
578
        loginRequest.setType("Internal");
560
 
579
 
561
        return responseSender.ok(this.getAuthTokenMap(emailId));
580
        return responseSender.ok(this.getAuthTokenMap(emailId, loginRequest));
562
 
581
 
563
    }
582
    }
564
 
583
 
565
    @RequestMapping(value = "/mobileappsettings")
584
    @RequestMapping(value = "/mobileappsettings")
566
    public ResponseEntity<?> mobileAppSettings(HttpServletRequest request, @RequestParam(name = "t") int timestamp,
585
    public ResponseEntity<?> mobileAppSettings(HttpServletRequest request, @RequestParam(name = "t") int timestamp, @RequestParam(name = "imeinumber") String imeinumber) throws ProfitMandiBusinessException, ClientProtocolException, IOException {
567
                                               @RequestParam(name = "imeinumber") String imeinumber)
-
 
568
            throws ProfitMandiBusinessException, ClientProtocolException, IOException {
-
 
569
 
-
 
570
        final String uri = "http://192.168.158.89/mobileappsettings?t=" + timestamp + "&imeinumber=" + imeinumber;
586
        final String uri = "http://192.168.158.89/mobileappsettings?t=" + timestamp + "&imeinumber=" + imeinumber;
571
        final String BASIC_AUTH = "Basic " + Base64.getEncoder().encodeToString("dtr:dtr18Feb2015".getBytes());
587
        final String BASIC_AUTH = "Basic " + Base64.getEncoder().encodeToString("dtr:dtr18Feb2015".getBytes());
572
        Map<String, String> headers = new HashMap<>();
588
        Map<String, String> headers = new HashMap<>();
573
        Map<String, String> params = new HashMap<>();
589
        Map<String, String> params = new HashMap<>();
574
        headers.put("Authorization", BASIC_AUTH);
590
        headers.put("Authorization", BASIC_AUTH);