Subversion Repositories SmartDukaan

Rev

Rev 26817 | Rev 26840 | 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) {
26834 amit.gupta 46
			if(customer.getPassword()!=null) {
47
				customer.setPassword(getHash256(customer.getPassword()));
48
			}
26817 amit.gupta 49
			customer.setPassword(getHash256(getRandomString()));
50
			try {
51
				customerRepository.persist(customer);
52
			} catch(Exception e) {
53
				e.printStackTrace();
54
			}
26785 amit.gupta 55
		}
26817 amit.gupta 56
		return customer;
26785 amit.gupta 57
 
58
	}
59
 
60
	private String getRandomString() {
61
		int length = 10;
62
		boolean useLetters = true;
63
		boolean useNumbers = false;
64
		String generatedString = RandomStringUtils.random(length, useLetters, useNumbers);
65
		return generatedString;
66
	}
67
 
68
	@Override
69
	public void resetPassword(String mobile) throws ProfitMandiBusinessException {
70
		// TODO Auto-generated method stub
71
 
72
	}
73
 
74
	@Override
75
	public void changePassword(String emailOrMobile, String oldHashedPassword, String hashedPassword)
76
			throws ProfitMandiBusinessException {
77
		// TODO Auto-generated method stub
78
 
79
	}
80
 
81
}