Subversion Repositories SmartDukaan

Rev

Rev 26785 | Rev 26834 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
26785 amit.gupta 1
package com.spice.profitmandi.service;
2
 
3
import java.nio.charset.StandardCharsets;
4
 
5
import org.apache.commons.lang3.RandomStringUtils;
6
import org.apache.logging.log4j.LogManager;
7
import org.apache.logging.log4j.Logger;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.mail.javamail.JavaMailSender;
10
import org.springframework.stereotype.Component;
11
 
12
import com.google.common.hash.Hashing;
13
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
14
import com.spice.profitmandi.dao.entity.fofo.Customer;
15
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
16
 
17
@Component
18
public class CustomerServiceImpl implements CustomerService {
19
	// 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
21
	// password.\n\nRegards\nSmartdukaan";
22
	private static final String RESET_PASSWORD_BODY = "Dear %s, your password has been reset to %s. Regards\nSmartdukaan";
23
	private static final String RESET_PASSWORD_SUBJECT = "Password Reset request";
24
 
25
	private static final Logger LOGGER = LogManager.getLogger(AuthServiceImpl.class);
26
 
27
	@Autowired
28
	CustomerRepository customerRepository;
29
	@Autowired
30
	JavaMailSender mailSender;
31
 
32
	private String getHash256(String originalString) {
33
		return Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
34
	}
35
 
36
	@Override
37
	public boolean authenticate(String mobile, String password) {
38
		return customerRepository.authenticate(mobile, getHash256(password));
39
	}
40
 
41
	@Override
26817 amit.gupta 42
	public Customer addCustomer(Customer customer) {
26785 amit.gupta 43
		try {
26817 amit.gupta 44
			customer = customerRepository.selectByMobileNumber(customer.getMobileNumber());
26785 amit.gupta 45
		} catch (ProfitMandiBusinessException pbse) {
26817 amit.gupta 46
			customer.setPassword(getHash256(getRandomString()));
47
			try {
48
				customerRepository.persist(customer);
49
			} catch(Exception e) {
50
				e.printStackTrace();
51
			}
26785 amit.gupta 52
		}
26817 amit.gupta 53
		return customer;
26785 amit.gupta 54
 
55
	}
56
 
57
	private String getRandomString() {
58
		int length = 10;
59
		boolean useLetters = true;
60
		boolean useNumbers = false;
61
		String generatedString = RandomStringUtils.random(length, useLetters, useNumbers);
62
		return generatedString;
63
	}
64
 
65
	@Override
66
	public void resetPassword(String mobile) throws ProfitMandiBusinessException {
67
		// TODO Auto-generated method stub
68
 
69
	}
70
 
71
	@Override
72
	public void changePassword(String emailOrMobile, String oldHashedPassword, String hashedPassword)
73
			throws ProfitMandiBusinessException {
74
		// TODO Auto-generated method stub
75
 
76
	}
77
 
78
}