| 21285 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 26783 |
amit.gupta |
3 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
4 |
import org.apache.logging.log4j.Logger;
|
| 21285 |
kshitij.so |
5 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
6 |
import org.springframework.http.MediaType;
|
|
|
7 |
import org.springframework.http.ResponseEntity;
|
|
|
8 |
import org.springframework.stereotype.Controller;
|
| 21702 |
ashik.ali |
9 |
import org.springframework.transaction.annotation.Transactional;
|
| 21285 |
kshitij.so |
10 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
11 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
12 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
13 |
|
|
|
14 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
15 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 21740 |
ashik.ali |
16 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 21735 |
ashik.ali |
17 |
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
|
|
|
18 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 26783 |
amit.gupta |
19 |
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
|
| 21285 |
kshitij.so |
20 |
import com.spice.profitmandi.web.processor.OtpProcessor;
|
|
|
21 |
import com.spice.profitmandi.web.res.OTPResponse;
|
|
|
22 |
|
|
|
23 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
24 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
25 |
import io.swagger.annotations.ApiOperation;
|
|
|
26 |
|
|
|
27 |
@Controller
|
| 26783 |
amit.gupta |
28 |
@Transactional(rollbackFor = Throwable.class)
|
| 21285 |
kshitij.so |
29 |
public class OTPController {
|
|
|
30 |
|
| 26783 |
amit.gupta |
31 |
private static final Logger logger = LogManager.getLogger(OTPController.class);
|
|
|
32 |
|
| 21285 |
kshitij.so |
33 |
@Autowired
|
| 22931 |
ashik.ali |
34 |
private ResponseSender<?> responseSender;
|
| 26783 |
amit.gupta |
35 |
|
|
|
36 |
|
| 21440 |
ashik.ali |
37 |
@Autowired
|
| 22931 |
ashik.ali |
38 |
private OtpProcessor otpProcessor;
|
| 21285 |
kshitij.so |
39 |
|
| 26783 |
amit.gupta |
40 |
@RequestMapping(value = ProfitMandiConstants.URL_GENERATE_OTP, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21285 |
kshitij.so |
41 |
@ApiImplicitParams({
|
| 26783 |
amit.gupta |
42 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 21285 |
kshitij.so |
43 |
@ApiOperation(value = "Generate OTP")
|
| 26783 |
amit.gupta |
44 |
public ResponseEntity<?> generateOtp(@RequestParam("mobile") String mobile) throws Exception {
|
| 21285 |
kshitij.so |
45 |
OTPResponse otpResponse;
|
| 26783 |
amit.gupta |
46 |
if (!StringUtils.isValidMobile(mobile)) {
|
| 21285 |
kshitij.so |
47 |
otpResponse = new OTPResponse();
|
|
|
48 |
otpResponse.setMessage("Illegal mobile number");
|
| 22931 |
ashik.ali |
49 |
return responseSender.badRequest(otpResponse);
|
| 21285 |
kshitij.so |
50 |
}
|
| 26783 |
amit.gupta |
51 |
|
|
|
52 |
otpResponse = otpProcessor.generateOtp(mobile, OtpType.REGISTRATION);
|
| 22931 |
ashik.ali |
53 |
return responseSender.ok(otpResponse);
|
| 26783 |
amit.gupta |
54 |
|
| 21285 |
kshitij.so |
55 |
}
|
|
|
56 |
|
| 26783 |
amit.gupta |
57 |
@RequestMapping(value = ProfitMandiConstants.URL_VERIFY_OTP, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21287 |
kshitij.so |
58 |
@ApiImplicitParams({
|
| 26783 |
amit.gupta |
59 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 21394 |
kshitij.so |
60 |
@ApiOperation(value = "Validate OTP")
|
| 26783 |
amit.gupta |
61 |
public ResponseEntity<?> validateOtp(String mobile, @RequestParam int referenceId, String otpCode)
|
|
|
62 |
throws Exception {
|
|
|
63 |
// TODO validate email & phone from utility method
|
| 21285 |
kshitij.so |
64 |
OTPResponse otpResponse;
|
| 26783 |
amit.gupta |
65 |
otpResponse = otpProcessor.validateOtp(referenceId, mobile, otpCode);
|
| 22931 |
ashik.ali |
66 |
return responseSender.ok(otpResponse);
|
| 21285 |
kshitij.so |
67 |
}
|
| 26783 |
amit.gupta |
68 |
|
| 21382 |
amit.gupta |
69 |
@ApiOperation(value = "Parse OTP")
|
| 21475 |
amit.gupta |
70 |
@ApiImplicitParams({
|
| 26783 |
amit.gupta |
71 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
72 |
@RequestMapping(value = ProfitMandiConstants.URL_PARSE_OTP, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
73 |
public ResponseEntity<?> parseOTP(@RequestParam(name = "message") String message) {
|
|
|
74 |
logger.info("message {}", message);
|
|
|
75 |
String numberOnly = message.replaceAll("[^0-9]", "");
|
|
|
76 |
if (numberOnly.length() != 5) {
|
| 22931 |
ashik.ali |
77 |
return responseSender.badRequest("");
|
| 21476 |
amit.gupta |
78 |
}
|
|
|
79 |
return responseSender.ok(numberOnly);
|
| 21382 |
amit.gupta |
80 |
}
|
| 21285 |
kshitij.so |
81 |
|
|
|
82 |
}
|