Пример #1
0
 public static SettingRegRespObj ChangePassword(ChangePasswordObj regObj)
 {
     return(new StaffRepository().ChangePassword(regObj));
 }
Пример #2
0
        public JsonResult ProcessPasswordChangeRequest(string myOldPassword, string myNewPassword, string myConfirmPassword)
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }
                if (string.IsNullOrEmpty(myOldPassword) || myOldPassword.Length < 3)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Old Password must be at least 3 characters" }));
                }

                if (string.IsNullOrEmpty(myNewPassword) || myNewPassword.Length < 3)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "New Password must be at least 3 characters" }));
                }

                if (string.IsNullOrEmpty(myConfirmPassword) || myConfirmPassword.Length < 3)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Confirm Password must be at least 3 characters" }));
                }

                if (string.Compare(myOldPassword, myNewPassword, StringComparison.CurrentCultureIgnoreCase) == 0)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "New Password must be different from the Old Password" }));
                }
                if (string.Compare(myConfirmPassword, myNewPassword, StringComparison.CurrentCultureIgnoreCase) != 0)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "New Password and Confirm Password must match" }));
                }

                var passObj = new ChangePasswordObj
                {
                    NewPassword = myNewPassword,
                    OldPassword = myOldPassword,
                    ChangeType  = (int)PasswordChangeType.Regular,
                    UserId      = userData.UserId,
                };


                var changePassword = new PortalUserManager().ChangePassword(passObj, userData.Username);
                if (changePassword == null || changePassword.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!changePassword.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(changePassword.Status.Message.FriendlyMessage) ? "Process Failed! Unable to change your password" : changePassword.Status.Message.FriendlyMessage }));
                }

                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
Пример #3
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            filterContext.Controller.ViewBag.IsSuccessful = false;
            filterContext.Controller.ViewBag.Error        = "";

            var modelList = filterContext.ActionParameters.Where(ap => ap.Key == "model").ToList();

            if (modelList.IsNullOrEmpty())
            {
                filterContext.Controller.ViewBag.Error = "Invalid Password Information";
                return;
            }
            if (!modelList.Any() || modelList.Count != 1)
            {
                filterContext.Controller.ViewBag.Error = "Invalid Password Information";
                return;
            }

            if (!(modelList[0].Value is ChangePasswordContract model))
            {
                filterContext.Controller.ViewBag.Error = "Invalid Password Information";
                return;
            }

            if (!GenericVal.Validate(model, out var msg))
            {
                filterContext.Controller.ViewBag.Error = msg;
                return;
            }

            if (
                string.Compare(model.OldPassword.Trim(), model.NewPassword.Trim(),
                               StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                model.ConfirmPassword = "";
                model.NewPassword     = "";
                model.OldPassword     = "";
                filterContext.Controller.ViewBag.Error = "Current Password and New Password cannot be same";
                return;
            }

            if (
                string.Compare(model.ConfirmPassword.Trim(), model.NewPassword.Trim(),
                               StringComparison.InvariantCultureIgnoreCase) != 0)
            {
                model.ConfirmPassword = "";
                model.NewPassword     = "";
                model.OldPassword     = "";
                filterContext.Controller.ViewBag.Error = "New Password and Confirm New Password must match";
                return;
            }

            var passObj = new ChangePasswordObj
            {
                NewPassword = model.NewPassword,
                OldPassword = model.OldPassword,
                UserId      = model.UserId,
                ChangeType  = (int)PasswordChangeType.Regular
            };

            var changePassword = new PortalUserManager().ChangePassword(passObj, model.Username);

            if (changePassword == null)
            {
                filterContext.Controller.ViewBag.Error = "Process Failed! Unable to change password";
                return;
            }
            if (!changePassword.Status.IsSuccessful)
            {
                filterContext.Controller.ViewBag.Error = string.IsNullOrEmpty(changePassword.Status.Message.FriendlyMessage) ? "Process Failed! Unable to change your password" : changePassword.Status.Message.FriendlyMessage;
                return;
            }


            filterContext.Controller.ViewBag.IsSuccessful = true;
            base.OnActionExecuting(filterContext);
        }