コード例 #1
0
        public JObject ValidateOTP()
        {
            Logger.Debug("Calling ValidateOTP");
            JObject request = HttpProxy.GetRequestBody <JObject>();

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

            var       otp           = request[CommonConst.CommonField.OTP].ToString();
            UserModel requestUser   = GetUserDataFromRequest(request);
            var       securityToken = request[CommonConst.CommonField.SECURITY_TOKEN].ToString();

            if (!IsUserExists(requestUser.user_id))
            {
                if (requestUser.user_type == UserIDType.PhoneNumber.ToString() && OTPService.Validate(requestUser.user_id, otp, OTPType.Signup, securityToken))
                {
                    UserModel tempUser = new UserModel()
                    {
                        user_id = requestUser.user_id, user_type = UserIDType.PhoneNumber.ToString()
                    };
                    SessionProvider.SetValue(CommonConst.CommonValue.SIGN_UP_SESSION_USER_KEY, tempUser);
                    return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS));
                }
                else if (requestUser.user_type == UserIDType.Email.ToString() && OTPService.ValidateEmail(requestUser.user_id, otp, OTPType.Signup, securityToken))
                {
                    UserModel tempUser = new UserModel()
                    {
                        user_id = requestUser.user_id, user_type = UserIDType.Email.ToString()
                    };
                    SessionProvider.SetValue(CommonConst.CommonValue.SIGN_UP_SESSION_USER_KEY, tempUser);
                    return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS));
                }
                else
                {
                    Logger.Error("Error OTP validation fail");
                    return(ResponseBuilder.CreateReponse(AppResponseCode._OTP_VALIDATION_FAIL));
                }
            }
            else
            {
                Logger.Info(string.Format("User Exits with this phone number {0}", requestUser.user_id));
                return(ResponseBuilder.CreateReponse(AppResponseCode._USER_EXISTS));
            }
        }
コード例 #2
0
        public JObject ResetPassword()
        {
            try
            {
                Logger.Debug("Calling ResetPassword");
                JObject request = HttpProxy.GetRequestBody <JObject>();
                Logger.Debug("ResetPassword Request data", request);

                var redirect_url = HttpProxy.GetQueryString(CommonConst.CommonField.REDIRECT_URL_KEY);
                if (request == null)
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }
                var otp                = request[CommonConst.CommonField.OTP].ToString();
                var requestUser        = GetUserDataFromRequest(request);
                var forgetpasswordUser = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SIGN_UP_SESSION_USER_KEY);
                if (forgetpasswordUser == null)
                {
                    return(ResponseBuilder.CreateReponse(AppResponseCode._SESSION_USER_NOT_FOUND));
                }
                if (forgetpasswordUser.user_id != requestUser.user_id)
                {
                    return(ResponseBuilder.CreateReponse(AppResponseCode._SESSION_USER_DATA_MISMATCH));
                }

                if (request[CommonConst.CommonField.PASSWORD].ToString() != request[CommonConst.CommonField.CONFIRM_PASSWORD].ToString())
                {
                    return(ResponseBuilder.CreateReponse(AppResponseCode._SESSION_USER_DATA_MISMATCH));
                }

                var capchaChecked = SessionProvider.GetValue <bool>(USER_REGISTRATION_CAPCHA_VALIDATION_SESSION_KEY);

                if (!capchaChecked)
                {
                    Logger.Info("Captcha validate fail");
                    return(ResponseBuilder.CreateReponse(AppResponseCode._CAPTCHA_VALIDATION_FAIL));
                }

                bool OTPValidate = false;
                if (requestUser.user_type == UserIDType.PhoneNumber.ToString() && OTPService.Validate(requestUser.user_id, otp, OTPType.Forgetpassword, string.Empty))
                {
                    OTPValidate = true;
                }
                else if (requestUser.user_type == UserIDType.Email.ToString() && OTPService.ValidateEmail(requestUser.user_id, otp, OTPType.Forgetpassword, string.Empty))
                {
                    OTPValidate = true;
                }
                else
                {
                    Logger.Error("Error OTP validation fail");
                    return(ResponseBuilder.CreateReponse(AppResponseCode._OTP_VALIDATION_FAIL));
                }

                if (ResetPass(requestUser, request[CommonConst.CommonField.PASSWORD].ToString()) && OTPValidate)
                {
                    var user = DBProxy.FirstOrDefault <UserModel>(CommonConst.Collection.USERS, CommonConst.CommonField.USER_ID, requestUser.user_id);

                    var     rurl        = AppSettingService.GetAppSettingData(ModuleAppConsts.Field.FORGET_PASS_LENDING_PAGE_SETTING_KEY);
                    JObject resonseData = new JObject();
                    if (string.IsNullOrEmpty(redirect_url))
                    {
                        resonseData[CommonConst.CommonField.REDIRECT_URL_KEY] = rurl;
                    }
                    else
                    {
                        resonseData[CommonConst.CommonField.REDIRECT_URL_KEY] = string.Format("{0}?{1}={2}", rurl, CommonConst.CommonField.REDIRECT_URL_KEY, redirect_url);
                    }
                    return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, null, resonseData));
                }
                else
                {
                    Logger.Error("Error while ResetPassword");
                    return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("Forgetpassword.ResetPassword error : {0}", ex.Message), ex);
                return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
            }
        }