| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service;
|
1 |
package com.spice.profitmandi.service;
|
| 2 |
|
2 |
|
| 3 |
import java.nio.charset.StandardCharsets;
|
- |
|
| 4 |
import java.util.ArrayList;
|
- |
|
| 5 |
|
- |
|
| 6 |
import org.apache.commons.lang.RandomStringUtils;
|
- |
|
| 7 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 8 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 9 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 10 |
import org.springframework.mail.javamail.JavaMailSender;
|
- |
|
| 11 |
import org.springframework.stereotype.Component;
|
- |
|
| 12 |
|
- |
|
| 13 |
import com.google.common.hash.Hashing;
|
3 |
import com.google.common.hash.Hashing;
|
| 14 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
4 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 15 |
import com.spice.profitmandi.common.util.Utils;
|
5 |
import com.spice.profitmandi.common.util.Utils;
|
| 16 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
6 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 17 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
7 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 18 |
import com.spice.profitmandi.dao.entity.user.Promoter;
|
8 |
import com.spice.profitmandi.dao.entity.user.Promoter;
|
| 19 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
9 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 20 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
10 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 21 |
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
|
11 |
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
|
| - |
|
12 |
import org.apache.commons.lang.RandomStringUtils;
|
| - |
|
13 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
14 |
import org.apache.logging.log4j.Logger;
|
| - |
|
15 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
16 |
import org.springframework.mail.javamail.JavaMailSender;
|
| - |
|
17 |
import org.springframework.stereotype.Component;
|
| 22 |
|
18 |
|
| - |
|
19 |
import java.nio.charset.StandardCharsets;
|
| - |
|
20 |
import java.util.ArrayList;
|
| 23 |
import java.util.List;
|
21 |
import java.util.List;
|
| 24 |
import java.util.stream.Collectors;
|
22 |
import java.util.stream.Collectors;
|
| 25 |
|
23 |
|
| 26 |
@Component
|
24 |
@Component
|
| 27 |
public class AuthServiceImpl implements AuthService {
|
25 |
public class AuthServiceImpl implements AuthService {
|
| Line 85... |
Line 83... |
| 85 |
} catch (Exception e) {
|
83 |
} catch (Exception e) {
|
| 86 |
throw new ProfitMandiBusinessException("Password Reset Email", emailOrMobile,
|
84 |
throw new ProfitMandiBusinessException("Password Reset Email", emailOrMobile,
|
| 87 |
"Could not send password reset mail. Password Could not be reset");
|
85 |
"Could not send password reset mail. Password Could not be reset");
|
| 88 |
}
|
86 |
}
|
| 89 |
authUser.setPassword(getHash256(password));
|
87 |
authUser.setPassword(getHash256(password));
|
| 90 |
authRepository.persist(authUser);
|
- |
|
| 91 |
}
|
88 |
}
|
| 92 |
|
89 |
|
| 93 |
@Override
|
90 |
@Override
|
| 94 |
public void changePassword(String emailOrMobile, String oldPassword, String newPassword)
|
91 |
public void changePassword(String emailOrMobile, String oldPassword, String newPassword)
|
| 95 |
throws ProfitMandiBusinessException {
|
92 |
throws ProfitMandiBusinessException {
|
| 96 |
if (authRepository.authenticate(emailOrMobile, getHash256(oldPassword))) {
|
93 |
if (authRepository.authenticate(emailOrMobile, getHash256(oldPassword))) {
|
| 97 |
AuthUser authUser = authRepository.selectByEmailOrMobile(emailOrMobile);
|
94 |
AuthUser authUser = authRepository.selectByEmailOrMobile(emailOrMobile);
|
| 98 |
authUser.setPassword(getHash256(newPassword));
|
95 |
authUser.setPassword(getHash256(newPassword));
|
| 99 |
authRepository.persist(authUser);
|
- |
|
| 100 |
} else {
|
96 |
} else {
|
| 101 |
throw new ProfitMandiBusinessException("Authentication", "Credentials", "Invalid email/mobile or password");
|
97 |
throw new ProfitMandiBusinessException("Authentication", "Credentials", "Invalid email/mobile or password");
|
| 102 |
}
|
98 |
}
|
| 103 |
}
|
99 |
}
|
| 104 |
|
100 |
|
| Line 108... |
Line 104... |
| 108 |
authRepository.selectByEmailOrMobile(authUser.getEmailId());
|
104 |
authRepository.selectByEmailOrMobile(authUser.getEmailId());
|
| 109 |
} catch (ProfitMandiBusinessException pbse) {
|
105 |
} catch (ProfitMandiBusinessException pbse) {
|
| 110 |
try {
|
106 |
try {
|
| 111 |
authRepository.selectByEmailOrMobile(authUser.getMobileNumber());
|
107 |
authRepository.selectByEmailOrMobile(authUser.getMobileNumber());
|
| 112 |
} catch (ProfitMandiBusinessException e) {
|
108 |
} catch (ProfitMandiBusinessException e) {
|
| 113 |
authRepository.persist(authUser);
|
109 |
//authRepository.persist(authUser);
|
| 114 |
this.resetPassword(authUser.getEmailId());
|
110 |
this.resetPassword(authUser.getEmailId());
|
| 115 |
return;
|
111 |
return;
|
| 116 |
}
|
112 |
}
|
| 117 |
throw new ProfitMandiBusinessException("Mobile", authUser.getMobileNumber(), "Mobile number already exist");
|
113 |
throw new ProfitMandiBusinessException("Mobile", authUser.getMobileNumber(), "Mobile number already exist");
|
| 118 |
}
|
114 |
}
|