Subversion Repositories SmartDukaan

Rev

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

Rev 24330 Rev 24389
Line 5... Line 5...
5
import org.apache.commons.lang.RandomStringUtils;
5
import org.apache.commons.lang.RandomStringUtils;
6
import org.apache.logging.log4j.LogManager;
6
import org.apache.logging.log4j.LogManager;
7
import org.apache.logging.log4j.Logger;
7
import org.apache.logging.log4j.Logger;
8
import org.springframework.beans.factory.annotation.Autowired;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.mail.javamail.JavaMailSender;
9
import org.springframework.mail.javamail.JavaMailSender;
-
 
10
import org.springframework.stereotype.Component;
10
 
11
 
11
import com.google.common.hash.Hashing;
12
import com.google.common.hash.Hashing;
12
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
13
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
13
import com.spice.profitmandi.common.util.Utils;
14
import com.spice.profitmandi.common.util.Utils;
14
import com.spice.profitmandi.dao.entity.auth.AuthUser;
15
import com.spice.profitmandi.dao.entity.auth.AuthUser;
15
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
16
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
16
 
17
 
-
 
18
@Component
17
public class AuthServiceImpl implements AuthService {
19
public class AuthServiceImpl implements AuthService {
18
 
20
 
19
	// private static final String RESET_PASSWORD_BODY = "Dear %s, your password has
21
	// private static final String RESET_PASSWORD_BODY = "Dear %s, your password has
20
	// been reset. Please click this <a href=\"%s\">link</a> to reset your
22
	// been reset. Please click this <a href=\"%s\">link</a> to reset your
21
	// password.\n\nRegards\nSmartdukaan";
23
	// password.\n\nRegards\nSmartdukaan";
Line 42... Line 44...
42
	@Override
44
	@Override
43
	public void resetPassword(String emailOrMobile) throws ProfitMandiBusinessException {
45
	public void resetPassword(String emailOrMobile) throws ProfitMandiBusinessException {
44
		AuthUser authUser = authRepository.selectByEmailOrMobile(emailOrMobile);
46
		AuthUser authUser = authRepository.selectByEmailOrMobile(emailOrMobile);
45
		String password = getRandomString();
47
		String password = getRandomString();
46
		try {
48
		try {
47
			Utils.sendMailWithAttachments(mailSender, authUser.getEmailId(), null, RESET_PASSWORD_SUBJECT, String.format(RESET_PASSWORD_BODY, authUser.getFirstName(), password), null);
49
			Utils.sendMailWithAttachments(mailSender, authUser.getEmailId(), null, RESET_PASSWORD_SUBJECT,
-
 
50
					String.format(RESET_PASSWORD_BODY, authUser.getFirstName(), password), null);
48
		} catch(Exception e) {
51
		} catch (Exception e) {
49
			throw new ProfitMandiBusinessException("Password Reset Email", emailOrMobile, "Could not send password reset mail. Password Could not be reset");
52
			throw new ProfitMandiBusinessException("Password Reset Email", emailOrMobile,
-
 
53
					"Could not send password reset mail. Password Could not be reset");
50
		}
54
		}
51
		authUser.setPassword(getHash256(password));
55
		authUser.setPassword(getHash256(password));
52
		authRepository.persist(authUser);
56
		authRepository.persist(authUser);
53
	}
57
	}
54
 
58
 
Line 64... Line 68...
64
		}
68
		}
65
	}
69
	}
66
 
70
 
67
	@Override
71
	@Override
68
	public void addAuthUser(AuthUser authUser) throws ProfitMandiBusinessException {
72
	public void addAuthUser(AuthUser authUser) throws ProfitMandiBusinessException {
-
 
73
		try {
-
 
74
			authRepository.selectByEmailOrMobile(authUser.getEmailId());
-
 
75
		} catch(ProfitMandiBusinessException pbse) {
-
 
76
			try {
-
 
77
				authRepository.selectByEmailOrMobile(authUser.getMobileNumber());
-
 
78
			} catch(ProfitMandiBusinessException e) {
69
		authRepository.persist(authUser);
79
				authRepository.persist(authUser);
70
		this.resetPassword(authUser.getEmailId());
80
				this.resetPassword(authUser.getEmailId());
-
 
81
				return;
-
 
82
			}
-
 
83
			throw new ProfitMandiBusinessException("Mobile", authUser.getMobileNumber(), "Mobile number already exist");
-
 
84
		}	
-
 
85
		throw new ProfitMandiBusinessException("Email", authUser.getEmailId(), "Email Id already exist");
-
 
86
 
71
	}
87
	}
72
 
88
 
73
	private String getRandomString() {
89
	private String getRandomString() {
74
		int length = 10;
90
		int length = 10;
75
		boolean useLetters = true;
91
		boolean useLetters = true;