Subversion Repositories SmartDukaan

Rev

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

Rev 24492 Rev 29269
Line 1... Line 1...
1
package com.spice.profitmandi.service;
1
package com.spice.profitmandi.service;
2
 
2
 
3
import java.nio.charset.StandardCharsets;
3
import java.nio.charset.StandardCharsets;
-
 
4
import java.util.ArrayList;
4
 
5
 
5
import org.apache.commons.lang.RandomStringUtils;
6
import org.apache.commons.lang.RandomStringUtils;
6
import org.apache.logging.log4j.LogManager;
7
import org.apache.logging.log4j.LogManager;
7
import org.apache.logging.log4j.Logger;
8
import org.apache.logging.log4j.Logger;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.beans.factory.annotation.Autowired;
Line 17... Line 18...
17
import com.spice.profitmandi.dao.entity.user.Promoter;
18
import com.spice.profitmandi.dao.entity.user.Promoter;
18
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
19
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
19
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
20
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
20
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
21
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
21
 
22
 
-
 
23
import java.util.List;
-
 
24
import java.util.stream.Collectors;
-
 
25
 
22
@Component
26
@Component
23
public class AuthServiceImpl implements AuthService {
27
public class AuthServiceImpl implements AuthService {
24
 
28
 
25
	// private static final String RESET_PASSWORD_BODY = "Dear %s, your password has
29
	// private static final String RESET_PASSWORD_BODY = "Dear %s, your password has
26
	// been reset. Please click this <a href=\"%s\">link</a> to reset your
30
	// been reset. Please click this <a href=\"%s\">link</a> to reset your
Line 43... Line 47...
43
	UserRepository userRepository;
47
	UserRepository userRepository;
44
 
48
 
45
	private String getHash256(String originalString) {
49
	private String getHash256(String originalString) {
46
		return Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
50
		return Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
47
	}
51
	}
-
 
52
	
-
 
53
	@Override
-
 
54
	public List<Integer> getDirectReportee(int authId) {
-
 
55
		List<Integer> totalReportee = new ArrayList<>();
-
 
56
		totalReportee.add(authId);
-
 
57
		List<AuthUser> authUsers =authRepository.selectManagerByAuthUserId(authId);
-
 
58
		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);
-
 
66
			totalReportee.addAll(authAllReportee);
-
 
67
		
-
 
68
		}
-
 
69
		
-
 
70
		return totalReportee;
-
 
71
	}
-
 
72
	
-
 
73
   public List<Integer> getAllReportee(List<Integer> authIds) {
-
 
74
	   
-
 
75
	   List<Integer> totalUsers = new ArrayList<>();
-
 
76
		
-
 
77
	   List<Integer> reporteeIds = authRepository.selectManagerByAuthUserIds(authIds).stream().map(x->x.getId()).collect(Collectors.toList());
-
 
78
	   
-
 
79
	   
-
 
80
		
-
 
81
		if(!reporteeIds.isEmpty())
-
 
82
		{
-
 
83
			totalUsers.addAll(reporteeIds);
-
 
84
			
-
 
85
			this.getAllReportee(reporteeIds);
-
 
86
		}
-
 
87
	  
-
 
88
		return totalUsers;
-
 
89
	}
-
 
90
	
48
 
91
 
49
	@Override
92
	@Override
50
	public boolean authenticate(String emailOrMobile, String password) {
93
	public boolean authenticate(String emailOrMobile, String password) {
51
		return authRepository.authenticate(emailOrMobile, getHash256(password));
94
		return authRepository.authenticate(emailOrMobile, getHash256(password));
52
	}
95
	}