コード例 #1
0
 private boolean validateReq(SendOtpReq sendOtpReq) {
   if (sendOtpReq != null
       && CommonUtils.checkNullOrBlank(sendOtpReq.getOtpFor())
       && CommonUtils.checkNullOrBlank(sendOtpReq.getEmailId())) {
     return true;
   }
   return false;
 }
コード例 #2
0
 private boolean sendOtp(
     Long trxNumber,
     String loginId,
     Long customerId,
     Boolean guestLoginFlag,
     SendOtpReq sendOtpReq,
     SendOtpResp sendOtpResp) {
   // TODO Auto-generated method stub
   Boolean flag = false;
   Integer opt = CommonUtils.generate6dig();
   String operation = null;
   OtpOperationEntity operationEntity = new OtpOperationEntity();
   operationEntity.setTrxNumber(trxNumber);
   operationEntity.setGuestFlag(guestLoginFlag);
   if (guestLoginFlag) {
     operationEntity.setGuestLoginId(loginId);
   } else {
     operationEntity.setCustomerId(customerId);
   }
   operationEntity.setOtp(opt.toString());
   operationEntity.setUseFlag(false);
   operationEntity.setOtpOperation(sendOtpReq.getOtpFor());
   operationEntity.setCreatedBy(Constants.DEFAULT_CREATED_BY);
   operationEntity.setCreatedDate(new Date());
   otpDao.saveOtp(operationEntity);
   if (Constants.OTP_VERIFY_EMAIL.equalsIgnoreCase(sendOtpReq.getOtpFor())) {
     operation = Constants.OTP_VERIFY_EMAIL_MSG;
   } else if (Constants.OTP_CHANGE_PASSWORD.equalsIgnoreCase(sendOtpReq.getOtpFor())) {
     operation = Constants.OTP_CHANGE_PASSWORD_MSG;
   } else if (Constants.OTP_FORGOT_PASSWORD.equalsIgnoreCase(sendOtpReq.getOtpFor())) {
     operation = Constants.OTP_FORGOT_PASSWORD_MSG;
   }
   // TODO email
   CustomMailSender.initialize();
   try {
     String subject = MessageFormat.format(this.subject, operation);
     String emailText = MessageFormat.format(this.emailText, opt.toString());
     SMTPTransport smtpTransport =
         customMailSender.connectToSmtp(
             sendOtpReq.getEmailId(), subject, emailText, null, this.fromEmail);
     System.out.println(subject + emailText);
     sendOtpResp.setOtpFor(sendOtpReq.getOtpFor());
     sendOtpResp.setTransactionCode(trxNumber.toString());
     flag = true;
   } catch (Exception e) {
     logger.error("Exception while sending OTP " + trxNumber, e);
   }
   if (!flag) {
     List<Error_> error_s = sendOtpResp.getError();
     Error_ error_ = new Error_();
     error_.setErrorCode(Constants.ERR_SOMETHING_WENT_WRONG.toString());
     ErrorMsgEntity errorMsg = baseDao.getErrorMsg(Constants.ERR_SOMETHING_WENT_WRONG);
     error_.setErrorMessage(errorMsg.getDesc());
     error_s.add(error_);
   }
   return flag;
 }
コード例 #3
0
  @Transactional(readOnly = false)
  @Override
  public ResponseWrapper<SendOtpResp> sendOtp(
      RequestWrapper<SendOtpReq> requestWrapper, Long trxNumber) {
    MsgHeader msgHeader = requestWrapper.getMsgHeader();
    SendOtpReq sendOtpReq = requestWrapper.getData();
    SendOtpResp sendOtpResp = new SendOtpResp();
    ResponseWrapper<SendOtpResp> responseWrapper = new ResponseWrapper<SendOtpResp>();
    DeviceFPmsgHeader deviceFPmsgHeader = requestWrapper.getDeviceFPmsgHeader();
    Long customerId = null;
    MsgHeaderResp msgHeaderResp = null;
    Boolean guestLoginFlag = false;
    boolean validateGuestFlag = false;
    Boolean successFlag = false;
    if (validateHeader(msgHeader) && validateReq(sendOtpReq)) {
      msgHeaderResp = getMessageResponse(msgHeader, trxNumber);
      TransactionInfoEntity transactionInfoEntity =
          getTransactionEntity(msgHeader, deviceFPmsgHeader, Constants.API_SEND_OTP, trxNumber);
      String loginId = msgHeader.getLoginId();
      if (!validateConsumer(msgHeader)) {
        Error errorMsg = getErrorMsg(Constants.ERR_CODE_APPLICATION_ACCESS);
        CommonUtils.setErrorInRespose(msgHeaderResp, errorMsg);
      } else {
        sendOtpResp.setOtpFor(sendOtpReq.getOtpFor());
        AppUserDetailsEntity appUserDetailsEntity = null;
        if (Constants.GUEST_LOGIN_FLAG_Y.equalsIgnoreCase(msgHeader.getGuestLoginFlag())) {
          appUserDetailsEntity = validateGuestLogin(msgHeader);
          guestLoginFlag = true;
          if (appUserDetailsEntity == null) {
            transactionInfoEntity.setLoginId(loginId);
            msgHeaderResp.setLoginId(loginId);
            Error errorMsg = getErrorMsg(Constants.ERR_INVALID_GUEST);
            msgHeaderResp = CommonUtils.setErrorInRespose(msgHeaderResp, errorMsg);
          } else {
            transactionInfoEntity.setLoginId(loginId);
            msgHeaderResp.setLoginId(loginId);
            validateGuestFlag = true;
            // Verify Email to be done using Guest Login
            if (Constants.OTP_VERIFY_EMAIL.equalsIgnoreCase(sendOtpReq.getOtpFor())) {
              CustomerCredEntity customerCredEntity =
                  baseDao.getCustomerId(sendOtpReq.getEmailId());
              if (customerCredEntity != null) {
                List<Error_> error_s = sendOtpResp.getError();
                Error_ error_ = new Error_();
                error_.setErrorCode(Constants.ERR_BODY_USER_ID_ALREADY_EXIST.toString());
                ErrorMsgEntity errorMsg =
                    baseDao.getErrorMsg(Constants.ERR_BODY_USER_ID_ALREADY_EXIST);
                error_.setErrorMessage(errorMsg.getDesc());
                error_s.add(error_);
              } else {
                successFlag =
                    sendOtp(
                        trxNumber, loginId, customerId, guestLoginFlag, sendOtpReq, sendOtpResp);
              }
            } else {
              Error errorMsg = getErrorMsg(Constants.ERR_CODE_GUEST_LOGIN_NOT_ALLWED);
              CommonUtils.setErrorInRespose(msgHeaderResp, errorMsg);
            }
          }
        } else {
          guestLoginFlag = false;
          // Non Verify Email for Non-Guest
          if (!Constants.OTP_VERIFY_EMAIL.equalsIgnoreCase(sendOtpReq.getOtpFor())) {
            CustomerCredEntity customerCredEntity = baseDao.getCustomerId(loginId);
            if (customerCredEntity != null && loginId.equalsIgnoreCase(sendOtpReq.getEmailId())) {
              if (Constants.CUST_ACCOUNT_ACTIVE.equalsIgnoreCase(
                  customerCredEntity.getAccountStatus())) {
                successFlag =
                    sendOtp(
                        trxNumber,
                        loginId,
                        customerCredEntity.getCustomerId(),
                        guestLoginFlag,
                        sendOtpReq,
                        sendOtpResp);
              } else {
                // If account is locked then send message
                List<Error_> error_s = sendOtpResp.getError();
                Error_ error_ = new Error_();
                error_.setErrorCode(Constants.ERR_BODY_ACCNT_LOCKED.toString());
                ErrorMsgEntity errorMsg = baseDao.getErrorMsg(Constants.ERR_BODY_ACCNT_LOCKED);
                error_.setErrorMessage(errorMsg.getDesc());
                error_s.add(error_);
              }

            } else {
              // If invalid account
              List<Error_> error_s = sendOtpResp.getError();
              Error_ error_ = new Error_();
              error_.setErrorCode(Constants.ERR_INVALID_EMAIL_ID.toString());
              ErrorMsgEntity errorMsg = baseDao.getErrorMsg(Constants.ERR_INVALID_EMAIL_ID);
              error_.setErrorMessage(errorMsg.getDesc());
              error_s.add(error_);
            }

          } else {
            Error errorMsg = getErrorMsg(Constants.ERR_CODE_INTERNAL_ERROR);
            msgHeaderResp = CommonUtils.setErrorInRespose(msgHeaderResp, errorMsg);
          }
        }
        baseDao.saveTransactionInfo(transactionInfoEntity);
      }
      if (msgHeader != null && msgHeaderResp.getHostStatus() == null) {
        msgHeaderResp.setHostStatus(Constants.HOST_STATUS_SUCCESS);
      }
      sendOtpResp.setSuccessflag(successFlag);
      responseWrapper.setMessage(msgHeaderResp);
      responseWrapper.setData(sendOtpResp);
    } else {
      Error error = getErrorMsg(Constants.ERR_CODE_BAD_REQUEST);
      responseWrapper = CommonUtils.malformedResp(sendOtpResp, trxNumber, error);
    }
    return responseWrapper;
  }