Beispiel #1
0
//API Request OTP
func (this *CustomerController) RequestOTP() {

	flg := true
	var apiRequest m.OTPRequest
	response := new(m.ResRequestOTP)
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &apiRequest)
	if err != nil {
		beego.Error(err.Error())
		response.Header.StatusCode = lib.ERROR_JSON_UNMARSHAL_FAILED
		flg = false
	}

	if flg {
		valid := validation.Validation{}
		valid.Mobile(apiRequest.MobileNumber, "mobile")
		if valid.HasErrors() {
			response.Header.StatusCode = lib.BIZ_WRONG_MOBILE_NUMBER
			flg = false
		}
	}

	if flg {
		response.Header.StatusCode = lib.STATUS_SUCCESS
		otp := lib.GenerateOTP()
		response.SequenceNumber = lib.GenerateSequenceNumberForOTP(otp)

		beego.Debug(response.SequenceNumber + ":" + otp)

		redisx.Put("OTP_SEQ_"+response.SequenceNumber, otp, 300)
		redisx.Put("OTP_MOBILE_"+response.SequenceNumber, apiRequest.MobileNumber, 300)
		go sendOTPSMS(apiRequest.MobileNumber, otp)
	}

	response.Header.ErrorMsg = GetErrorMsg(response.Header.StatusCode)
	this.Data["json"] = &response
	this.ServeJson()

}