예제 #1
0
        public JObject SendForgetpassOTP()
        {
            Logger.Debug("Calling SendForgetpassOTP");
            JObject request = HttpProxy.GetRequestBody <JObject>();

            if (request == null)
            {
                return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
            }

            Logger.Debug("Request body SendForgetpassOTP", request);
            UserModel requestUser       = GetUserDataFromRequest(request);
            var       recaptchaResponse = request[ModuleAppConsts.Field.GOOGLE_RECAPTCHA_RESPONSE_KEY].ToString();
            var       capchaChecked     = SessionProvider.GetValue <bool>(USER_REGISTRATION_CAPCHA_VALIDATION_SESSION_KEY);

            if (capchaChecked && !GoogleCaptchaHelper.ValidateResponse(Logger, recaptchaResponse, AppSettingService.GetAppSettingData(ModuleAppConsts.Field.GOOGLE_RECAPTCHA_SECRECT_SETTING_KEY), AppSettingService.GetAppSettingData(ModuleAppConsts.Field.GOOGLE_RECAPTCHA_VALIDATE_URL_SETTING_KEY)))
            {
                Logger.Info("Captcha validate fail SendForgetpassOTP");
                return(ResponseBuilder.CreateReponse(AppResponseCode._CAPTCHA_VALIDATION_FAIL));
            }
            else
            {
                SessionProvider.SetValue <bool>(USER_REGISTRATION_CAPCHA_VALIDATION_SESSION_KEY, true);
            }
            if (IsUserExists(requestUser.user_id))
            {
                string securityToken = CommonUtility.RandomString(10);
                if (requestUser.user_type == UserIDType.PhoneNumber.ToString() && OTPService.Send(requestUser.user_id, ModuleAppConsts.Field.FORGET_PASS_OTP_SMS_TEMPLATE, OTPType.Forgetpassword, securityToken))
                {
                    JObject dataResponse = new JObject();
                    dataResponse[CommonConst.CommonField.SECURITY_TOKEN] = securityToken;
                    SessionProvider.SetValue <UserModel>(CommonConst.CommonValue.SIGN_UP_SESSION_USER_KEY, requestUser);

                    return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, null, dataResponse));
                }
                else if (requestUser.user_type == UserIDType.Email.ToString() && OTPService.SendEmail(requestUser.user_id, ModuleAppConsts.Field.FORGET_PASS_OTP_EMAIL_TEMPLATE, AppSettingService.GetAppSettingData(ModuleAppConsts.Field.FORGET_PASS_OTP_EMAIL_SUBJECT), OTPType.Forgetpassword, securityToken))
                {
                    JObject dataResponse = new JObject();
                    dataResponse[CommonConst.CommonField.SECURITY_TOKEN] = securityToken;

                    SessionProvider.SetValue <UserModel>(CommonConst.CommonValue.SIGN_UP_SESSION_USER_KEY, requestUser);
                    return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, null, dataResponse));
                }
                else
                {
                    return(ResponseBuilder.CreateReponse(AppResponseCode._OTP_SEND_ERROR));
                }
            }
            else
            {
                return(ResponseBuilder.CreateReponse(AppResponseCode._USER_NOT_FOUND));
            }
        }