/// <summary> /// 注册; /// </summary> /// <param name="user">用户</param> /// <returns>是否注册成功</returns> public User SignUp(string userNo, string userPassword) { this.HasSignedUp = false; User user = new User() { No = userNo, Password = CrytoHelper.Md5(userPassword), IsActivated = true }; try { this.UserDal.Insert(user); this.HasSignedUp = true; this.Message = "注册成功。"; } catch (ApplicationException ex) { this.Message = $"{ex.Message}\n注册失败!"; } catch (Exception) { this.Message = "注册失败!"; } return(user); }
/// <summary> /// 注册; /// </summary> /// <param name="user">用户</param> /// <returns>是否注册成功</returns> public UserDto SignUp(string userNo, string userPassword) { this.HasSignedUp = false; User user = new User() { No = userNo, Password = CrytoHelper.Md5(userPassword), IsActivated = true, RoleNo = this.GetRole(userNo).No }; try { this.UserDal.Insert(user); this.HasSignedUp = true; this.Message = "注册成功。"; } catch (ApplicationException ex) { this.Message = $"{ex.Message}\n注册失败!"; } catch (Exception) { this.Message = "注册失败!"; } UserDto userDto = AutoMapperHelper.Get <User, UserDto>(user); userDto.HasSignedUp = this.HasSignedUp; userDto.Message = this.Message; return(userDto); }
public Boolean TriggerEmail(String toAddress, String userPassword, string username) { var emailSubject = "Updated password !!!"; var bodyContent = "The updated password for the Varavuselavu app is <br/> <b>Username:</b>" + username + "<br/>" + "<b>Password:</b>" + userPassword + "<br/>" + $"Application URL: <a href = \"http:www.varavuselavu.xyz\">VaravuselavuApp</a>"; return(Email.Send( CrytoHelper.DecryptString(_appConfiguration.EmailConfigurations.FromAddress, Constants.KEY), toAddress, CrytoHelper.DecryptString(_appConfiguration.EmailConfigurations.FromAddress, Constants.KEY), CrytoHelper.DecryptString(_appConfiguration.EmailConfigurations.Password, Constants.KEY), userPassword, username, emailSubject, bodyContent)); }
/// <summary> /// 处理用户密码错误; /// </summary> /// <param name="user">用户</param> /// <param name="password">密码</param> private void HandleUserPasswordNotMatch(User user, string password) { bool isPasswordMatch = CrytoHelper.Md5Equal(user.Password, password); if (!isPasswordMatch) { this.HandleUserLoginFail(user); this.HandleUserLoginFailTooManyTimes(user); string errorMessage = user.IsActivated ? $"密码错误,请重新输入!\n您还有{this.LogInFailCountMax - user.LoginFailCount}次机会!" : $"密码错误已达{this.LogInFailCountMax}次上限!"; throw new ApplicationException(errorMessage); } }