Subversion Repositories SmartDukaan

Rev

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

Rev 21483 Rev 21485
Line 18... Line 18...
18
import org.springframework.web.bind.annotation.RequestBody;
18
import org.springframework.web.bind.annotation.RequestBody;
19
import org.springframework.web.bind.annotation.RequestMapping;
19
import org.springframework.web.bind.annotation.RequestMapping;
20
import org.springframework.web.bind.annotation.RequestMethod;
20
import org.springframework.web.bind.annotation.RequestMethod;
21
import org.springframework.web.bind.annotation.RequestParam;
21
import org.springframework.web.bind.annotation.RequestParam;
22
 
22
 
23
import com.auth0.jwt.JWT;
-
 
24
import com.spice.profitmandi.common.ResponseCodeHolder;
23
import com.spice.profitmandi.common.ResponseCodeHolder;
25
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
24
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
26
import com.spice.profitmandi.common.model.ProfitMandiConstants;
25
import com.spice.profitmandi.common.model.ProfitMandiConstants;
27
import com.spice.profitmandi.common.model.UserInfo;
26
import com.spice.profitmandi.common.model.UserInfo;
28
import com.spice.profitmandi.common.util.JWTUtil;
27
import com.spice.profitmandi.common.util.JWTUtil;
29
import com.spice.profitmandi.dao.entity.Permission;
28
import com.spice.profitmandi.dao.entity.Permission;
-
 
29
import com.spice.profitmandi.dao.entity.Retailer;
30
import com.spice.profitmandi.dao.entity.Role;
30
import com.spice.profitmandi.dao.entity.Role;
31
import com.spice.profitmandi.dao.entity.User;
31
import com.spice.profitmandi.dao.entity.User;
32
import com.spice.profitmandi.dao.entity.UserRole;
32
import com.spice.profitmandi.dao.entity.UserRole;
33
import com.spice.profitmandi.dao.enumuration.RoleType;
33
import com.spice.profitmandi.dao.enumuration.RoleType;
34
import com.spice.profitmandi.dao.repository.PermissionRepository;
34
import com.spice.profitmandi.dao.repository.PermissionRepository;
-
 
35
import com.spice.profitmandi.dao.repository.RetailerRepository;
35
import com.spice.profitmandi.dao.repository.RoleRepository;
36
import com.spice.profitmandi.dao.repository.RoleRepository;
-
 
37
import com.spice.profitmandi.dao.repository.UserAccountRepository;
-
 
38
import com.spice.profitmandi.dao.repository.UserCart;
36
import com.spice.profitmandi.dao.repository.UserRepository;
39
import com.spice.profitmandi.dao.repository.UserRepository;
37
import com.spice.profitmandi.dao.repository.UserRoleRepository;
40
import com.spice.profitmandi.dao.repository.UserRoleRepository;
38
import com.spice.profitmandi.web.enumuration.UserStatus;
41
import com.spice.profitmandi.web.enumuration.UserStatus;
39
import com.spice.profitmandi.web.model.ProfitMandiResponse;
42
import com.spice.profitmandi.web.model.ProfitMandiResponse;
40
import com.spice.profitmandi.web.model.ResponseStatus;
43
import com.spice.profitmandi.web.model.ResponseStatus;
Line 63... Line 66...
63
 
66
 
64
	@Autowired
67
	@Autowired
65
	UserRepository userRepository;
68
	UserRepository userRepository;
66
 
69
 
67
	@Autowired
70
	@Autowired
-
 
71
	RetailerRepository retailerRepository;
-
 
72
 
-
 
73
	@Autowired
68
	RoleRepository roleRepository;
74
	RoleRepository roleRepository;
69
 
75
 
70
	@Autowired
76
	@Autowired
71
	UserRoleRepository userRoleRepository;
77
	UserRoleRepository userRoleRepository;
72
 
78
 
73
	@Autowired
79
	@Autowired
-
 
80
	UserAccountRepository userAccountRepository;
-
 
81
 
-
 
82
	@Autowired
74
	PermissionRepository permissionRepository;
83
	PermissionRepository permissionRepository;
75
 
84
 
76
	@Autowired
85
	@Autowired
77
	GoogleLoginProcessor googleLoginProcessor;
86
	GoogleLoginProcessor googleLoginProcessor;
78
 
87
 
Line 139... Line 148...
139
				@Override
148
				@Override
140
				public boolean test(Role t) {
149
				public boolean test(Role t) {
141
					return t.getType().equals(RoleType.RETAILER);
150
					return t.getType().equals(RoleType.RETAILER);
142
				}
151
				}
143
			})) {
152
			})) {
144
				// TODO: This should be from retailer Table
153
				UserCart uc  = userAccountRepository.getUserCart(userInfo.getUserId());
145
				// if retailer is activated and migrated is 0 then verified
154
				Retailer retailer  = retailerRepository.selectById(uc.getUserId());
146
				// retailer
-
 
147
				// if retailer is not activated and and migrated is 0 then not
155
				// if retailer is activated 1 then verified retailer
148
				// verified retailer
-
 
149
				// if retailer is activated and migrated is 1 then retailer is
156
				// else if migrated is 1 then old retailer
150
				// retailer.
157
				// else retailer is not verifed
151
				if (user.isActivated()) {
158
				if (retailer.isActive()) {
152
					responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.VERIFIED_RETAILER.getValue());
159
					responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.VERIFIED_RETAILER.getValue());
-
 
160
				} else if (retailer.isMigrated()){
-
 
161
					responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.RETAILER.getValue());
153
				} else {
162
				} else {
154
					responseMap.put(ProfitMandiConstants.NEW_AUTH_TOKEN, UserStatus.NOT_VERIFIED_RETAILER.getValue());
163
					responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_VERIFIED_RETAILER.getValue());
155
				}
164
				}
156
			} else if (user.getRoles().stream().anyMatch(new Predicate<Role>() {
165
			} else if (user.getRoles().stream().anyMatch(new Predicate<Role>() {
157
				@Override
166
				@Override
158
				public boolean test(Role t) {
167
				public boolean test(Role t) {
159
					return t.getType().equals(RoleType.USER);
168
					return t.getType().equals(RoleType.USER);
160
				}
169
				}
161
			})) {
170
			})) {
162
				responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.REGISTERED.getValue());
171
				responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.REGISTERED.getValue());
163
			} else {
172
			} else {
164
				responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.RETAILER.getValue());
173
				responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED.getValue());
-
 
174
				responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
165
			}
175
			}
166
		} else {
-
 
167
			responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED.getValue());
-
 
168
			responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
-
 
169
		}
176
		}
170
 
177
 
171
		return responseSender.ok(responseMap);
178
		return responseSender.ok(responseMap);
172
 
179
 
173
	}
180
	}