Subversion Repositories SmartDukaan

Rev

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

Rev 35262 Rev 35272
Line 3... Line 3...
3
import com.fasterxml.jackson.annotation.JsonProperty;
3
import com.fasterxml.jackson.annotation.JsonProperty;
4
import com.fasterxml.jackson.databind.ObjectMapper;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
import com.spice.profitmandi.common.ResponseCodeHolder;
5
import com.spice.profitmandi.common.ResponseCodeHolder;
6
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
6
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
7
import com.spice.profitmandi.common.model.*;
7
import com.spice.profitmandi.common.model.*;
8
import com.spice.profitmandi.common.util.JWTUtil;
-
 
9
import com.spice.profitmandi.common.util.Utils;
8
import com.spice.profitmandi.common.util.Utils;
10
import com.spice.profitmandi.common.web.client.RestClient;
9
import com.spice.profitmandi.common.web.client.RestClient;
11
import com.spice.profitmandi.common.web.util.ResponseSender;
10
import com.spice.profitmandi.common.web.util.ResponseSender;
12
import com.spice.profitmandi.dao.entity.auth.AuthUser;
11
import com.spice.profitmandi.dao.entity.auth.AuthUser;
13
import com.spice.profitmandi.dao.entity.dtr.*;
12
import com.spice.profitmandi.dao.entity.dtr.*;
Line 28... Line 27...
28
import com.spice.profitmandi.dao.repository.dtr.*;
27
import com.spice.profitmandi.dao.repository.dtr.*;
29
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
28
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
30
import com.spice.profitmandi.dao.repository.user.AddressRepository;
29
import com.spice.profitmandi.dao.repository.user.AddressRepository;
31
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
30
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
32
import com.spice.profitmandi.service.AuthService;
31
import com.spice.profitmandi.service.AuthService;
-
 
32
import com.spice.profitmandi.service.authentication.JWTUtil;
33
import com.spice.profitmandi.service.authentication.RoleManager;
33
import com.spice.profitmandi.service.authentication.RoleManager;
34
import com.spice.profitmandi.service.user.RetailerService;
34
import com.spice.profitmandi.service.user.RetailerService;
35
import com.spice.profitmandi.service.user.StoreTimelineTatService;
35
import com.spice.profitmandi.service.user.StoreTimelineTatService;
36
import com.spice.profitmandi.service.user.UserService;
36
import com.spice.profitmandi.service.user.UserService;
37
import com.spice.profitmandi.web.controller.checkout.OrderController;
-
 
38
import com.spice.profitmandi.web.enumuration.UserStatus;
37
import com.spice.profitmandi.web.enumuration.UserStatus;
39
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
38
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
40
import com.spice.profitmandi.web.req.RefferalEarning;
39
import com.spice.profitmandi.web.req.RefferalEarning;
41
import com.spice.profitmandi.web.req.RefferalEarningModel;
40
import com.spice.profitmandi.web.req.RefferalEarningModel;
42
import com.spice.profitmandi.web.req.UserRequest;
41
import com.spice.profitmandi.web.req.UserRequest;
Line 75... Line 74...
75
@Controller
74
@Controller
76
@Transactional(rollbackFor = Throwable.class)
75
@Transactional(rollbackFor = Throwable.class)
77
public class UserController {
76
public class UserController {
78
 
77
 
79
    @Autowired
78
    @Autowired
-
 
79
    JWTUtil jwtUtil;
-
 
80
 
-
 
81
    @Autowired
80
    private ResponseSender<?> responseSender;
82
    private ResponseSender<?> responseSender;
81
 
83
 
82
    //Changed to 2000 as per policy
84
    //Changed to 2000 as per policy
83
    private static final int PER_REFERRAL_EARNING=2000;
85
    private static final int PER_REFERRAL_EARNING=2000;
84
 
86
 
Line 160... Line 162...
160
    public ResponseEntity<?> googleLogin(HttpServletRequest request, @RequestBody GoogleLoginRequest loginRequest) throws Exception {
162
    public ResponseEntity<?> googleLogin(HttpServletRequest request, @RequestBody GoogleLoginRequest loginRequest) throws Exception {
161
        String email = loginRequest.getEmail() != null ? loginRequest.getEmail() : googleLoginProcessor.process(loginRequest.getToken());
163
        String email = loginRequest.getEmail() != null ? loginRequest.getEmail() : googleLoginProcessor.process(loginRequest.getToken());
162
        return responseSender.ok(getAuthTokenMap(email, loginRequest));
164
        return responseSender.ok(getAuthTokenMap(email, loginRequest));
163
    }
165
    }
164
 
166
 
165
    @RequestMapping(value = "/user/unregistered", method = RequestMethod.GET)
167
    @RequestMapping(value = "/user/token/unregistered", method = RequestMethod.GET)
166
    public ResponseEntity<?> unregisteredToken() throws Exception {
168
    public ResponseEntity<?> unregisteredToken() throws Exception {
167
        Map<String, Object> responseMap = new HashMap<>();
169
        Map<String, Object> responseMap = new HashMap<>();
168
        //responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create());
170
        responseMap.put(ProfitMandiConstants.TOKEN, jwtUtil.create());
169
        responseMap.put(ProfitMandiConstants.REGISTERED, false);
171
        responseMap.put(ProfitMandiConstants.REGISTERED, false);
170
        return responseSender.ok(responseMap);
172
        return responseSender.ok(responseMap);
171
    }
173
    }
172
 
174
 
173
    @RequestMapping(value = ProfitMandiConstants.URL_B2B_APP_VERSION, method = RequestMethod.GET)
175
    @RequestMapping(value = ProfitMandiConstants.URL_B2B_APP_VERSION, method = RequestMethod.GET)
Line 222... Line 224...
222
                    com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectByEmailId(Utils.SYSTEM_PARTNER);
224
                    com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectByEmailId(Utils.SYSTEM_PARTNER);
223
                    retailerId = user.getId();
225
                    retailerId = user.getId();
224
                }
226
                }
225
            }
227
            }
226
            responseMap.put(ProfitMandiConstants.TOKEN,
228
            responseMap.put(ProfitMandiConstants.TOKEN,
227
                    JWTUtil.create(email, registeredUser.getId(), retailerId, roleTypes));
229
                    jwtUtil.create(email, registeredUser.getId(), retailerId, roleTypes));
228
            LOGGER.info("Param value for email, registeredUser.getId(), retailerId, roleTypes are {}, {}, {} and {}",
230
            LOGGER.info("Param value for email, registeredUser.getId(), retailerId, roleTypes are {}, {}, {} and {}",
229
                    email, registeredUser.getId(), retailerId, Arrays.asList(roleTypes));
231
                    email, registeredUser.getId(), retailerId, Arrays.asList(roleTypes));
230
            responseMap.put(ProfitMandiConstants.REGISTERED, true);
232
            responseMap.put(ProfitMandiConstants.REGISTERED, true);
231
            return responseMap;
233
            return responseMap;
232
        }
234
        }
Line 243... Line 245...
243
        }
245
        }
244
        if (user == null) {
246
        if (user == null) {
245
            try {
247
            try {
246
                user = userRepository.selectByEmailId(email);
248
                user = userRepository.selectByEmailId(email);
247
            } catch (ProfitMandiBusinessException profitMandiBusinessException) {
249
            } catch (ProfitMandiBusinessException profitMandiBusinessException) {
248
                responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(email));
250
                responseMap.put(ProfitMandiConstants.TOKEN, jwtUtil.create(email));
249
                responseMap.put(ProfitMandiConstants.REGISTERED, false);
251
                responseMap.put(ProfitMandiConstants.REGISTERED, false);
250
            }
252
            }
251
        } else {
253
        } else {
252
            List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
254
            List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
253
            int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
255
            int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
254
            String[] roleTypes = new String[roleIds.size()];
256
            String[] roleTypes = new String[roleIds.size()];
255
            int index = 0;
257
            int index = 0;
256
            for (int roleId : roleIds) {
258
            for (int roleId : roleIds) {
257
                roleTypes[index++] = String.valueOf(roleId);
259
                roleTypes[index++] = String.valueOf(roleId);
258
            }
260
            }
259
            responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), retailerId, roleTypes));
261
            responseMap.put(ProfitMandiConstants.TOKEN, jwtUtil.create(user.getId(), retailerId, roleTypes));
260
            responseMap.put(ProfitMandiConstants.REGISTERED, true);
262
            responseMap.put(ProfitMandiConstants.REGISTERED, true);
261
        }
263
        }
262
 
264
 
263
        return responseMap;
265
        return responseMap;
264
    }
266
    }
Line 288... Line 290...
288
 
290
 
289
    @RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_IS_EXPIRED, method = RequestMethod.GET)
291
    @RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_IS_EXPIRED, method = RequestMethod.GET)
290
    public ResponseEntity<?> tokenIsExpired(HttpServletRequest request, @RequestParam(name = "token") String token)
292
    public ResponseEntity<?> tokenIsExpired(HttpServletRequest request, @RequestParam(name = "token") String token)
291
            throws ProfitMandiBusinessException {
293
            throws ProfitMandiBusinessException {
292
        LOGGER.info("requested url : " + request.getRequestURL().toString());
294
        LOGGER.info("requested url : " + request.getRequestURL().toString());
293
        return responseSender.ok(JWTUtil.isExpired(token));
295
        return responseSender.ok(jwtUtil.isExpired(token));
294
    }
296
    }
295
 
297
 
296
    @RequestMapping(value = ProfitMandiConstants.URL_USER_DETAIL_BY_TOKEN, method = RequestMethod.GET)
298
        @RequestMapping(value = ProfitMandiConstants.URL_USER_DETAIL_BY_TOKEN, method = RequestMethod.GET)
297
    @ApiImplicitParams({
299
    @ApiImplicitParams({
298
            @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
300
            @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
299
    public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
301
    public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
300
        Map<String, Object> responseMap = new HashMap<>();
302
        Map<String, Object> responseMap = new HashMap<>();
301
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
303
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
Line 359... Line 361...
359
 
361
 
360
            int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
362
            int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
361
            // generate new token if roles have been updated
363
            // generate new token if roles have been updated
362
            if (userInfo.getRoleIds() == null || roleIds.size() != userInfo.getRoleIds().size()) {
364
            if (userInfo.getRoleIds() == null || roleIds.size() != userInfo.getRoleIds().size()) {
363
                String[] roleIdStrings = roleIds.stream().map(String::valueOf).toArray(String[]::new);
365
                String[] roleIdStrings = roleIds.stream().map(String::valueOf).toArray(String[]::new);
364
                String newToken = JWTUtil.create(user.getId(), retailerId, roleIdStrings);
366
                String newToken = jwtUtil.create(user.getId(), retailerId, roleIdStrings);
365
                responseMap.put("newAuthToken", newToken);
367
                responseMap.put("newAuthToken", newToken);
366
            }
368
            }
367
 
369
 
368
            // if user is retailer
370
            // if user is retailer
369
            Set<Integer> roleIdsSet = new HashSet<>(roleIds);
371
            Set<Integer> roleIdsSet = new HashSet<>(roleIds);