Example #1
0
        private BaseState GetPassWordByEmail(string baseurl, GetPwdModel model)
        {
            if (!Dev.Comm.Validate.Validate.IsEmail(model.UserName))
            {
                return new BaseState(-1, "用户名非邮箱!");
            }


            var nick = this.GetNickNameByUserName(model.UserName);
            var token = WebSecurity.GeneratePasswordResetToken(model.UserName);
            var mail = SystemMessagerManager.GetContentForGetPass(baseurl, nick, token);
            var isok = SystemMessagerManager.SendValidateMail(baseurl, model.UserName, nick, "找回密码", mail);

            if (isok)
            {
                return new BaseState();
            }

            return new BaseState { ErrorCode = -1, ErrorMessage = "发送邮件失败" };
        }
Example #2
0
        public ActionResult GetPwd(GetPwdModel model)
        {
            var code = (this.SessionGet<string>(SessionName.验证码) ?? "").ToLower();
            this.SessionRemove(SessionName.验证码);

            if (model.Validcode.ToLower() != code)
            {
                this.ModelState.AddModelError("Validcode", "验证码不正确");
                return View(model);
            }

            // 用户没有本地密码,因此将删除由于缺少
            // OldPassword 字段而导致的所有验证错误
            var state = this.ModelState["GetPwdType"];
            if (state != null)
            {
                state.Errors.Clear();
            }

            if (this.ModelState.IsValid)
            {
                var bs = this._userService.GetPassWord(Dev.Comm.Web.HttpServerInfo.BaseUrl, model);

                if (bs.ErrorCode == 0)
                {
                    if (model.GetPwdType == 0)
                        return this.View("_GetPwdMailSucess", model: model.UserName);
                    else
                        return this.View("_GetPwdNext", model: bs.ErrorMessage);
                }
                else
                {
                    if (bs.ErrorCode == -3)
                        return this.Message("此用户还未激活,激活后继续",
                                            this.Url.Action("EmailActivation", new { email = model.UserName }));

                    this.ModelState.AddModelError("", "" + bs.ErrorMessage);
                }
            }


            return this.View();
        }
Example #3
0
        private BaseState GetPassWordByPhone(GetPwdModel model)
        {
            var userid = WebSecurity.GetUserId(model.UserName);
            var uid = this.GetUidByUserId(userid);
            var profile = this._userProfileRepository.FindOne(x => x.UserId == userid);
            if (profile == null)
                return new BaseState(-1, "用户不存在");
            var phone = profile.Phone;
            if (string.IsNullOrEmpty(phone))
            {
                return new BaseState(-1, "用户还未设置手机号");
            }

            if (profile.LastPhonePasswordResetTokenTime.HasValue &&
                profile.LastPhonePasswordResetTokenTime.Value.AddMinutes(1) > System.DateTime.Now
                ||
                profile.PhonePasswordResendCount.HasValue && profile.PhonePasswordResendCount >= 5 &&
                profile.LastPhonePasswordResetTokenTime.HasValue &&
                profile.LastPhonePasswordResetTokenTime.Value.AddHours(1) > System.DateTime.Now)
            {
                return new BaseState(-1, "短信发送过于频繁,请稍后再试");
            }


            var code = this.GeneratePhonePasswordResetToken(model.UserName);

            var message = "尊敬的" + phone + ",您好!XXXXX发送给您的认证码是" + code + ",请在网站上输入,找回XXXXX密码。如非本人操作,请忽略。";
            var issend = SystemMessagerManager.SendSMS(phone, message, uid);

            if (!issend)
                return new BaseState(-1, "发送失败");

            return new BaseState(0, phone + "," + model.UserName);
        }
Example #4
0
        public BaseState GetPassWord(string baseurl, GetPwdModel model)
        {
            var exist = this._userProfileRepository.FindOne(x => x.Email == model.UserName);
            // .UserExists(model.UserName);
            if (exist == null)
            {
                return new BaseState(-2, "邮箱不正确");
            }

            if (!WebSecurity.IsConfirmed(model.UserName))
            {
                return new BaseState(-3, "此帐户还未激活");
            }


            if (model.GetPwdType == 0)
            {
                return this.GetPassWordByEmail(baseurl, model);
            }
            else if (model.GetPwdType == 1)
            {
                return this.GetPassWordByPhone(model);
            }
            throw new ArgumentException("类型只能为0,1", "model.GetPwdType");
        }