Пример #1
0
        public JsonResult CheckReset(string NewPassword, string ConfirmPassword, string SMSCode, string Phone)
        {
            if (string.IsNullOrEmpty(NewPassword) || string.IsNullOrEmpty(ConfirmPassword))
            {
                return(Json(new { Status = "false", Result = "密码项不能为空!请仔细检查!" }));
            }
            if (string.IsNullOrEmpty(SMSCode))
            {
                return(Json(new { Status = false, Result = "短信验证码不为空!" }));
            }
            if (string.IsNullOrEmpty(Phone))
            {
                return(Json(new { Status = false, Result = "手机号不为空!" }));
            }
            if (!CheckerHelper.IsMobile(Phone.Trim()))
            {
                return(Json(new { Status = false, Result = "您发送的不是手机号!" }));
            }
            if (!UserBackendService.IsExist(Phone.Trim()))
            {
                return(Json(new { Status = false, Result = "系统不存在此用户!" }));
            }
            if (NewPassword != ConfirmPassword)
            {
                return(Json(new { Status = "false", Result = "新输入的密码不一致!" }));
            }
            var isdetectionon = PasswordStrengthDetectionService.IsDetectionOn();

            if (isdetectionon)
            {
                var isstonger = CheckPasswordStronger(ConfirmPassword.Trim());
                if (!isstonger)
                {
                    return(Json(new { Status = "false", Result = "密码不按规则" }));
                }
            }
            var smsresult = SystemService.CheckVerificationCode(Phone.Trim(), SMSCode);

            if (smsresult == null)
            {
                SystemService.SendVerificationCode(Phone.Trim(), 120);
                return(Json(new { Status = "false", Result = smsresult.FailReson }));
            }
            if (!smsresult.IsSuccess)
            {
                return(Json(new { Status = "false", Result = "发短信失败,重新发送!" }));
            }
            var result = UserManager.ResetPassword(Phone.Trim(), ApplicationUserManager.Admintoken, ConfirmPassword.Trim());

            if (!result.Succeeded)
            {
                return(Json(new { Status = false, Result = "更改密码失败,请重新确认修改!" }));
            }
            return(Json(new { Status = true, Result = "ResetSuccess" }));
        }
Пример #2
0
        public async Task <JsonResult> ChangeNewPassword(ChangePasswordViewModel model)
        {
            //非空验证
            if (string.IsNullOrEmpty(model.OldPassword) || string.IsNullOrEmpty(model.NewPassword) || string.IsNullOrEmpty(model.ConfirmPassword))
            {
                return(Json(new HandleResult()
                {
                    Status = "false", Result = "密码项不能为空!请仔细检查!"
                }));
            }
            if (model.NewPassword != model.ConfirmPassword)
            {
                return(Json(new HandleResult()
                {
                    Status = "false", Result = "新输入的密码不一致!"
                }));
            }
            var user = await UserManager.FindByNameAsync(User.Identity.Name);

            if (user == null)
            {
                return(Json(new HandleResult()
                {
                    Result = "请检测账号是否正常登录!", Status = "false"
                }));
            }
            var IsPasswordTrue = await UserManager.CheckPasswordAsync(user, model.OldPassword);

            if (!IsPasswordTrue)
            {
                return(Json(new HandleResult()
                {
                    Result = "输入的旧密码不对,请认真检查!", Status = "false"
                }));
            }
            var isdetectionon = PasswordStrengthDetectionService.IsDetectionOn();

            if (isdetectionon)
            {
                var isstonger = CheckPasswordStronger(model.ConfirmPassword);
                if (!isstonger)
                {
                    return(Json(new HandleResult()
                    {
                        Status = "false", Result = "密码不按规则"
                    }));
                }
            }
            var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

            if (result.Succeeded)
            {
                var newuser = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (newuser != null)
                {
                    await SignInAsync(newuser, isPersistent : false);
                }
                Session["IsPasswordStronger"] = true;
                return(Json(new { Status = true, Result = "Index" }));
            }
            return(Json(new { Status = false, Result = "更改失败" }));
        }
Пример #3
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {            //通过微信登录
            var Isweixinlogin = model.IsWeiXinLogin == "1" && !string.IsNullOrEmpty(model.WeixinUser);

            ViewBag.IsWeiXinAuth = !string.IsNullOrEmpty(model.WeixinUser);
            returnUrl            = !string.IsNullOrWhiteSpace(returnUrl) ? returnUrl : (string.IsNullOrEmpty(model.Stateurl) ? "~/Manage/index" : model.Stateurl);
            if (Isweixinlogin)
            {
                ViewBag.WeiXinUser = model.WeixinUser;
                ViewBag.WeiXinUrl  = returnUrl;
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            #region 密码安全监测
            var isDetectionOn = PasswordStrengthDetectionService.IsDetectionOn();
            if (isDetectionOn)
            {
                var ismatch = PasswordStrengthDetectionService.IsMatch(model.Password.Trim());
                if (ismatch)
                {
                    Session["IsPasswordStronger"] = true;
                }
                else
                {
                    Session["IsPasswordStronger"] = false;
                }
            }
            #endregion
            var result = await SignInHelper.PasswordSignIn(model.UserName, model.Password, model.RememberMe, shouldLockout : false);


            //var user = await UserManager.FindByNameAsync(model.UserName);
            //var roles = await UserManager.GetRolesAsync(user.Id);
            log4net.LogManager.GetLogger("RollingLog").Info(model.UserName + " Log in: " + result.ToString());
            switch (result)
            {
            case MvcBackend.App_Start.SignInStatus.Success:
                Session["MyMenu"] = null;
                if (Isweixinlogin)
                {
                    var user = ReadOnlyRepository.GetForUpdate(e => e.UserName == model.UserName.Trim());
                    //if (user == null) return Redirect(WeiXinAuthHtml.Replace("[url]", returnUrl));

                    if (string.IsNullOrEmpty(user.WeiXinAuthId))
                    {
                        user.WeiXinAuthId = model.WeixinUser;
                        Repository.Update(user);
                    }
                    else
                    {
                        var weixinuser = ReadOnlyRepository.Get(e => e.WeiXinAuthId == model.WeixinUser);
                        if (weixinuser != null && weixinuser.UserName != model.UserName)
                        {
                            ModelState.AddModelError("", "微信企业号已经认证过。");
                            return(View(model));
                        }
                    }
                }
                return(RedirectToLocal(returnUrl));

            case MvcBackend.App_Start.SignInStatus.LockedOut:
                return(View("Lockout"));

            case MvcBackend.App_Start.SignInStatus.RequiresTwoFactorAuthentication:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl }));

            case MvcBackend.App_Start.SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "登陆名或密码错误。");
                return(View(model));
            }
        }