Subversion Repositories SmartDukaan

Rev

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

Rev 29269 Rev 29282
Line 37... Line 37...
37
	@Autowired
37
	@Autowired
38
	AuthRepository authRepository;
38
	AuthRepository authRepository;
39
 
39
 
40
	@Autowired
40
	@Autowired
41
	JavaMailSender mailSender;
41
	JavaMailSender mailSender;
42
	
42
 
43
	@Autowired
43
	@Autowired
44
	PromoterRepository promoterRepository;
44
	PromoterRepository promoterRepository;
45
	
45
 
46
	@Autowired
46
	@Autowired
47
	UserRepository userRepository;
47
	UserRepository userRepository;
48
 
48
 
49
	private String getHash256(String originalString) {
49
	private String getHash256(String originalString) {
50
		return Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
50
		return Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
51
	}
51
	}
52
	
52
 
53
	@Override
53
	@Override
54
	public List<Integer> getDirectReportee(int authId) {
54
	public List<Integer> getDirectReportees(int authId) {
55
		List<Integer> totalReportee = new ArrayList<>();
-
 
56
		totalReportee.add(authId);
-
 
57
		List<AuthUser> authUsers =authRepository.selectManagerByAuthUserId(authId);
55
		List<AuthUser> authUsers = authRepository.selectAllByManagerAuthId(authId);
58
		List<Integer>authIds = authUsers.stream().map(x->x.getId()).collect(Collectors.toList());
56
		List<Integer> authIds = authUsers.stream().map(x -> x.getId()).collect(Collectors.toList());
59
	
-
 
60
		
-
 
61
		totalReportee.addAll(authIds);
-
 
62
		
-
 
63
		if (!authIds.isEmpty()) {
-
 
64
			
-
 
65
			List<Integer> authAllReportee =this.getAllReportee(authIds);
57
		LOGGER.info("Auth Id == {}, All Reportees === {}", authId, authIds);
66
			totalReportee.addAll(authAllReportee);
-
 
67
		
-
 
68
		}
-
 
69
		
-
 
70
		return totalReportee;
58
		return authIds;
71
	}
59
	}
72
	
60
 
73
   public List<Integer> getAllReportee(List<Integer> authIds) {
61
	public List<Integer> getAllReportees(int authId) {
74
	   
62
 
75
	   List<Integer> totalUsers = new ArrayList<>();
63
		List<Integer> allReportees = new ArrayList<>();
76
		
64
 
77
	   List<Integer> reporteeIds = authRepository.selectManagerByAuthUserIds(authIds).stream().map(x->x.getId()).collect(Collectors.toList());
65
		List<Integer> directReporteeIds = this.getDirectReportees(authId);
78
	   
-
 
79
	   
-
 
80
		
-
 
81
		if(!reporteeIds.isEmpty())
66
		allReportees.addAll(directReporteeIds);
82
		{
-
 
83
			totalUsers.addAll(reporteeIds);
67
		for (int directReporteeId : directReporteeIds) {
84
			
-
 
85
			this.getAllReportee(reporteeIds);
68
			allReportees.addAll(this.getAllReportees(directReporteeId));
86
		}
69
		}
87
	  
-
 
88
		return totalUsers;
70
		return allReportees;
89
	}
71
	}
90
	
-
 
91
 
72
 
92
	@Override
73
	@Override
93
	public boolean authenticate(String emailOrMobile, String password) {
74
	public boolean authenticate(String emailOrMobile, String password) {
94
		return authRepository.authenticate(emailOrMobile, getHash256(password));
75
		return authRepository.authenticate(emailOrMobile, getHash256(password));
95
	}
76
	}
Line 123... Line 104...
123
 
104
 
124
	@Override
105
	@Override
125
	public void addAuthUser(AuthUser authUser) throws ProfitMandiBusinessException {
106
	public void addAuthUser(AuthUser authUser) throws ProfitMandiBusinessException {
126
		try {
107
		try {
127
			authRepository.selectByEmailOrMobile(authUser.getEmailId());
108
			authRepository.selectByEmailOrMobile(authUser.getEmailId());
128
		} catch(ProfitMandiBusinessException pbse) {
109
		} catch (ProfitMandiBusinessException pbse) {
129
			try {
110
			try {
130
				authRepository.selectByEmailOrMobile(authUser.getMobileNumber());
111
				authRepository.selectByEmailOrMobile(authUser.getMobileNumber());
131
			} catch(ProfitMandiBusinessException e) {
112
			} catch (ProfitMandiBusinessException e) {
132
				authRepository.persist(authUser);
113
				authRepository.persist(authUser);
133
				this.resetPassword(authUser.getEmailId());
114
				this.resetPassword(authUser.getEmailId());
134
				return;
115
				return;
135
			}
116
			}
136
			throw new ProfitMandiBusinessException("Mobile", authUser.getMobileNumber(), "Mobile number already exist");
117
			throw new ProfitMandiBusinessException("Mobile", authUser.getMobileNumber(), "Mobile number already exist");
137
		}	
118
		}
138
		throw new ProfitMandiBusinessException("Email", authUser.getEmailId(), "Email Id already exist");
119
		throw new ProfitMandiBusinessException("Email", authUser.getEmailId(), "Email Id already exist");
139
 
120
 
140
	}
121
	}
141
 
122
 
142
	private String getRandomString() {
123
	private String getRandomString() {
Line 149... Line 130...
149
 
130
 
150
	@Override
131
	@Override
151
	public String getNameByEmailId(String email) {
132
	public String getNameByEmailId(String email) {
152
		AuthUser authUser = authRepository.selectByGmailId(email);
133
		AuthUser authUser = authRepository.selectByGmailId(email);
153
		String userName = null;
134
		String userName = null;
154
		
135
 
155
		if(authUser != null) {
136
		if (authUser != null) {
156
			userName = authUser.getFirstName() + " " + authUser.getLastName();
137
			userName = authUser.getFirstName() + " " + authUser.getLastName();
157
		} else {
138
		} else {
158
			if(promoterRepository.isExistByEmailId(email)) {
139
			if (promoterRepository.isExistByEmailId(email)) {
159
				Promoter promoter = promoterRepository.selectByEmailId(email);
140
				Promoter promoter = promoterRepository.selectByEmailId(email);
160
				userName = promoter.getName();
141
				userName = promoter.getName();
161
				
142
 
162
			} else if(userRepository.isExistBySecondryEmailId(email)){
143
			} else if (userRepository.isExistBySecondryEmailId(email)) {
163
				try {
144
				try {
164
					User user = userRepository.selectBySecondryEmailId(email);
145
					User user = userRepository.selectBySecondryEmailId(email);
165
					userName = user.getFirstName() + " " + user.getLastName();
146
					userName = user.getFirstName() + " " + user.getLastName();
166
				} catch(Exception e) {
147
				} catch (Exception e) {
167
					e.printStackTrace();
148
					e.printStackTrace();
168
				}
149
				}
169
			}
150
			}
170
		}
151
		}
171
		LOGGER.info("User Name from getNameByEmailId({}) is {}", email, userName);
152
		LOGGER.info("User Name from getNameByEmailId({}) is {}", email, userName);
172
		return userName;
153
		return userName;
173
	}
154
	}
174
 
155
 
175
 
-
 
176
}
156
}
177
157