Subversion Repositories SmartDukaan

Rev

Rev 21472 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21472 Rev 21499
Line 1... Line 1...
1
package com.spice.profitmandi.web.processor;
1
package com.spice.profitmandi.web.processor;
2
 
2
 
3
 
3
 
-
 
4
import java.io.IOException;
-
 
5
import java.net.URISyntaxException;
4
import java.time.LocalDateTime;
6
import java.time.LocalDateTime;
5
import java.util.List;
7
import java.util.List;
6
import java.util.Random;
8
import java.util.Random;
7
 
9
 
8
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.stereotype.Component;
11
import org.springframework.stereotype.Component;
10
import org.springframework.transaction.annotation.Transactional;
-
 
11
 
12
 
12
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
13
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
14
import com.spice.profitmandi.common.util.Utils;
13
import com.spice.profitmandi.dao.entity.Otp;
15
import com.spice.profitmandi.dao.entity.Otp;
14
import com.spice.profitmandi.dao.enumuration.OtpType;
16
import com.spice.profitmandi.dao.enumuration.OtpType;
15
import com.spice.profitmandi.dao.repository.OtpRepository;
17
import com.spice.profitmandi.dao.repository.OtpRepository;
16
import com.spice.profitmandi.web.res.OTPResponse;
18
import com.spice.profitmandi.web.res.OTPResponse;
17
 
19
 
18
@Component
20
@Component
19
public class OtpProcessor{
21
public class OtpProcessor{
20
 
22
 
21
	private static final int len = 5;
23
	private static final int len = 5;
22
	private static final String numbers ="0123456789";
24
	private static final String numbers ="0123456789";
-
 
25
	private static final String text = "Dear Customer, {0} is the OTP that you have requested to login into Profitmandi. Don't share your OTP with anyone.";
23
 
26
 
24
	@Autowired
27
	@Autowired
25
	OtpRepository otpRepository;
28
	OtpRepository otpRepository;
26
 
29
 
27
	private String getOtp(){
30
	private String getOtp(){
Line 61... Line 64...
61
			}
64
			}
62
		}
65
		}
63
		if (otp == null || otp.isEmpty()){
66
		if (otp == null || otp.isEmpty()){
64
			otp = getOtp();
67
			otp = getOtp();
65
		}
68
		}
-
 
69
		sendOtp(otp, phone);
66
		Otp otp_d = otpRepository.generateOtp(email, phone, otpType, otp);
70
		Otp otp_d = otpRepository.generateOtp(email, phone, otpType, otp);
67
		otpResponse.setReference_id(otp_d.getId());
71
		otpResponse.setReference_id(otp_d.getId());
68
		otpResponse.setMessage("OTP generated successfully");
72
		otpResponse.setMessage("OTP generated successfully");
69
		otpResponse.setResult(true);
73
		otpResponse.setResult(true);
70
		otpResponse.setOtp(otp_d.getOtp());
74
		otpResponse.setOtp(otp_d.getOtp());
Line 97... Line 101...
97
		otpRepository.updateById(otp);
101
		otpRepository.updateById(otp);
98
		otpResponse.setMessage("OTP validated successfully");
102
		otpResponse.setMessage("OTP validated successfully");
99
		otpResponse.setResult(true);
103
		otpResponse.setResult(true);
100
		return otpResponse;
104
		return otpResponse;
101
	}
105
	}
-
 
106
	
-
 
107
	private void sendOtp(String otp_text, String phone){
-
 
108
		String msg = java.text.MessageFormat.format(text, otp_text);
-
 
109
		try {
-
 
110
			Utils.sendSms(msg, phone);
-
 
111
		} catch (URISyntaxException e) {
-
 
112
			// TODO Auto-generated catch block
-
 
113
			e.printStackTrace();
-
 
114
		} catch (IOException e) {
-
 
115
			// TODO Auto-generated catch block
-
 
116
			e.printStackTrace();
-
 
117
		}
-
 
118
		
-
 
119
	}
102
 
120
 
103
}
121
}
104
122