public JsonResult ProcessPasswordResetRequest(string myUsername)
        {
            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 }));
                }

                //var bearerAuth = MvcApplication.GetSessionBearerData(userData.Username);
                //var authToken = MvcApplication.GetSessionAuthData(userData.Username);

                //if (string.IsNullOrEmpty(bearerAuth) || bearerAuth.Length < 5)
                //{
                //    return Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid User Session! Please Re-Login" });
                //}

                //if (string.IsNullOrEmpty(authToken) || authToken.Length < 5)
                //{
                //    return Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid User Session! Please Re-Login" });
                //}

                if (string.IsNullOrEmpty(myUsername) || myUsername.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Username" }));
                }


                var passObj = new ResetPasswordObj
                {
                    Email       = myUsername,
                    AdminUserId = userData.UserId,
                };


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

                //MvcApplication.SetSessionBearerData(changePassword.Status.CustomSetting, userData.Username);
                //MvcApplication.SetSessionAuthData(changePassword.Status.CustomToken, userData.Username);

                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 = changePassword.NewPassword }));
            }
            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" }));
            }
        }
Example #2
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 update information";
                return;
            }
            if (!modelList.Any() || modelList.Count != 1)
            {
                filterContext.Controller.ViewBag.Error = "Invalid update information";
                return;
            }

            if (!(modelList[0].Value is ResetPasswordContract model))
            {
                filterContext.Controller.ViewBag.Error = "Invalid update information";
                return;
            }
            if (!GenericVal.Validate(model, out var msg))
            {
                filterContext.Controller.ViewBag.Error = msg;
                return;
            }

            var contract = new ResetPasswordObj
            {
                AdminUserId = 1,
                Email       = model.Username,
            };

            var passReset = new PortalUserManager().ResetPassword(contract, model.Username);

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

            filterContext.Controller.ViewBag.IsSuccessful    = true;
            filterContext.Controller.ViewBag.ThisNewPassword = passReset.NewPassword;
            base.OnActionExecuting(filterContext);
        }
Example #3
0
        public string ConfirmResetPassword(ResetPasswordObj id)
        {
            if (id.pass1.Length < 8)
            {
                return("נא להזין לפחות 8 תווים");
            }
            if (id.pass2.Length < 8)
            {
                return("נא להזין לפחות 8 תווים");
            }
            if (id.pass1 != id.pass2)
            {
                return("סיסמה לא זהה");
            }
            UserManager userManager = new UserManager();

            return(userManager.ResetPasswordPhase2(id.guid, id.pass1, id.pass2));
        }