| | |
| | | |
| | | import javax.xml.rpc.ServiceException; |
| | | import java.rmi.RemoteException; |
| | | import java.util.Arrays; |
| | | import java.util.UUID; |
| | | |
| | | @RestController |
| | |
| | | |
| | | @PostMapping("/sendOtp") |
| | | public ResponseEntity<Object> sendOtp(@RequestBody OtpLoginVM login) { |
| | | try { |
| | | if(applicationProperty.isMockLogin()) { |
| | | return new ResponseEntity<>(getMockSendOtpResponse(), HttpStatus.OK); |
| | | } |
| | | |
| | | if(login.getLoginType() == OtpLoginTypeEnum.SMS) { |
| | | return new ResponseEntity<>(otpWebService.sendByPhone(login.getAccount()), HttpStatus.OK); |
| | | } |
| | | else if(login.getLoginType() == OtpLoginTypeEnum.EMAIL) { |
| | | return new ResponseEntity<>(otpWebService.sendByEmail(login.getAccount()), HttpStatus.OK); |
| | | } |
| | | |
| | | return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("can not support this login type, loginType = " + login.getLoginType().name()); |
| | | } catch (ServiceException | RemoteException e) { |
| | | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("connecting otp web service error"); |
| | | if(applicationProperty.isMockLogin()) { |
| | | return new ResponseEntity<>(getMockSendOtpResponse(), HttpStatus.OK); |
| | | } |
| | | |
| | | if(login.getLoginType() == OtpLoginTypeEnum.SMS) { |
| | | return new ResponseEntity<>(otpWebService.sendByPhone(login.getAccount()), HttpStatus.OK); |
| | | } |
| | | else if(login.getLoginType() == OtpLoginTypeEnum.EMAIL) { |
| | | return new ResponseEntity<>(otpWebService.sendByEmail(login.getAccount()), HttpStatus.OK); |
| | | } |
| | | |
| | | return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("can not support this login type, loginType = " + login.getLoginType().name()); |
| | | } |
| | | |
| | | @PostMapping("/verify") |
| | |
| | | |
| | | private OtpResponseDTO getMockSendOtpResponse() { |
| | | String indexKey = UUID.randomUUID().toString().substring(0, 8); |
| | | return new OtpResponseDTO(new String[]{indexKey, "0", "", ""}); |
| | | return new OtpResponseDTO(Arrays.asList(indexKey, "0", "", "")); |
| | | } |
| | | } |