| Line 7... |
Line 7... |
| 7 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
7 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 8 |
import com.spice.profitmandi.dao.entity.user.Promoter;
|
8 |
import com.spice.profitmandi.dao.entity.user.Promoter;
|
| 9 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
9 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 10 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
10 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 11 |
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
|
11 |
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
|
| - |
|
12 |
import com.spice.profitmandi.service.user.UserService;
|
| 12 |
import org.apache.commons.lang.RandomStringUtils;
|
13 |
import org.apache.commons.lang.RandomStringUtils;
|
| 13 |
import org.apache.logging.log4j.LogManager;
|
14 |
import org.apache.logging.log4j.LogManager;
|
| 14 |
import org.apache.logging.log4j.Logger;
|
15 |
import org.apache.logging.log4j.Logger;
|
| 15 |
import org.springframework.beans.factory.annotation.Autowired;
|
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 16 |
import org.springframework.mail.javamail.JavaMailSender;
|
17 |
import org.springframework.mail.javamail.JavaMailSender;
|
| Line 42... |
Line 43... |
| 42 |
PromoterRepository promoterRepository;
|
43 |
PromoterRepository promoterRepository;
|
| 43 |
|
44 |
|
| 44 |
@Autowired
|
45 |
@Autowired
|
| 45 |
UserRepository userRepository;
|
46 |
UserRepository userRepository;
|
| 46 |
|
47 |
|
| - |
|
48 |
@Autowired
|
| - |
|
49 |
UserService userService;
|
| - |
|
50 |
|
| 47 |
private String getHash256(String originalString) {
|
51 |
private String getHash256(String originalString) {
|
| 48 |
return Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
|
52 |
return Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
|
| 49 |
}
|
53 |
}
|
| 50 |
|
54 |
|
| 51 |
@Override
|
55 |
@Override
|
| Line 94... |
Line 98... |
| 94 |
String.format(RESET_PASSWORD_BODY, authUser.getFirstName(), password), null);
|
98 |
String.format(RESET_PASSWORD_BODY, authUser.getFirstName(), password), null);
|
| 95 |
} catch (Exception e) {
|
99 |
} catch (Exception e) {
|
| 96 |
throw new ProfitMandiBusinessException("Password Reset Email", emailOrMobile,
|
100 |
throw new ProfitMandiBusinessException("Password Reset Email", emailOrMobile,
|
| 97 |
"Could not send password reset mail. Password Could not be reset");
|
101 |
"Could not send password reset mail. Password Could not be reset");
|
| 98 |
}
|
102 |
}
|
| - |
|
103 |
userService.resetPassword(emailOrMobile, password);
|
| - |
|
104 |
authUser.setPassword(getHash256(password));
|
| - |
|
105 |
}
|
| - |
|
106 |
|
| - |
|
107 |
@Override
|
| - |
|
108 |
public void resetPassword(String emailOrMobile, String password) throws ProfitMandiBusinessException {
|
| - |
|
109 |
AuthUser authUser = authRepository.selectByEmailOrMobile(emailOrMobile);
|
| - |
|
110 |
userService.resetPassword(emailOrMobile, password);
|
| 99 |
authUser.setPassword(getHash256(password));
|
111 |
authUser.setPassword(getHash256(password));
|
| 100 |
}
|
112 |
}
|
| 101 |
|
113 |
|
| 102 |
@Override
|
114 |
@Override
|
| 103 |
public void changePassword(String emailOrMobile, String oldPassword, String newPassword)
|
115 |
public void changePassword(String emailOrMobile, String oldPassword, String newPassword) throws ProfitMandiBusinessException {
|
| 104 |
throws ProfitMandiBusinessException {
|
- |
|
| 105 |
if (authRepository.authenticate(emailOrMobile, getHash256(oldPassword))) {
|
116 |
if (authRepository.authenticate(emailOrMobile, getHash256(oldPassword))) {
|
| 106 |
AuthUser authUser = authRepository.selectByEmailOrMobile(emailOrMobile);
|
117 |
AuthUser authUser = authRepository.selectByEmailOrMobile(emailOrMobile);
|
| 107 |
authUser.setPassword(getHash256(newPassword));
|
118 |
authUser.setPassword(getHash256(newPassword));
|
| - |
|
119 |
userService.resetPassword(authUser.getEmailId(), newPassword);
|
| 108 |
} else {
|
120 |
} else {
|
| 109 |
throw new ProfitMandiBusinessException("Authentication", "Credentials", "Invalid email/mobile or password");
|
121 |
throw new ProfitMandiBusinessException("Authentication", "Credentials", "Invalid email/mobile or password");
|
| 110 |
}
|
122 |
}
|
| 111 |
}
|
123 |
}
|
| 112 |
|
124 |
|