public void PasswordHasOnlySpecialChars() { AccountValidate pass = new AccountValidate(); var r = pass.IsValidPassword("!@#$&*!@#$&*"); Assert.IsFalse(r); }
public void PasswordHasOnlyNumber_Chars() { AccountValidate pass = new AccountValidate(); var r = pass.IsValidPassword("Moneylover1"); Assert.IsFalse(r); }
public void PasswordCorrectFormat() { AccountValidate pass = new AccountValidate(); var r = pass.IsValidPassword("!Moneylover1"); Assert.IsTrue(r); }
public void PasswordHasOnlyNumber() { AccountValidate pass = new AccountValidate(); var r = pass.IsValidPassword("123456789"); Assert.IsFalse(r); }
public void EmailCorrectFormat() { AccountValidate addr = new AccountValidate(); var r = addr.IsValidEmail("*****@*****.**"); Assert.IsTrue(r); }
public void PasswordLessThan8() { AccountValidate pass = new AccountValidate(); var r = pass.IsValidPassword("!Money1"); Assert.IsFalse(r); }
public void EmailNull() { AccountValidate addr = new AccountValidate(); var r = addr.IsValidEmail(null); Assert.IsFalse(r); }
public void EmailWrongFormat() { AccountValidate addr = new AccountValidate(); var r = addr.IsValidEmail("user1.com"); Assert.IsFalse(r); }
public void EmailBlank() { AccountValidate addr = new AccountValidate(); var r = addr.IsValidEmail(""); Assert.IsFalse(r); }
public async Task <string> UpdateClientInfo([FromBody] Client clientDto) { var client = await _unitOfWork.Repository <User>().GetByIdAsync(clientDto.Id); client = Mapper.Map(clientDto, client); await _accountHelper.UpdateUserInfoAsync(client); return(AccountValidate.ValidationMessage(RequestState.Success, "Update Client success")); }
public async Task <string> UpdateMemberInfo([FromBody] Member memberDto) { var member = await _unitOfWork.Repository <User>().GetByIdAsync(memberDto.Id); member = Mapper.Map(memberDto, member); await _accountHelper.UpdateUserInfoAsync(member); return(AccountValidate.ValidationMessage(RequestState.Success, "Update Member success")); }
public async Task <string> DeleteAccount(string id) { if (id == null) { throw new ArgumentNullException(nameof(id)); } var clientToDelete = await _unitOfWork.Repository <User>().GetByIdAsync(id); await _unitOfWork.Repository <User>().DeleteAsync(clientToDelete); return(AccountValidate.ValidationMessage(RequestState.Success, "Delete account success")); }
public async Task <string> NewMember([FromBody] Member memberDto) { var account = await _accountHelper.CreateNewAccount(memberDto); await _userManager.AddToRoleAsync(account.User, memberDto.Role); var signUpInfo = new SignUpInfo { UserName = account.User.UserName, SignupUrl = account.CallbackUrl, RandomPassword = account.RandomPassword }; string bodyContent = await _emailTemplateService.RenderTemplateAsync("Account/AccountConfirm.cshtml", signUpInfo); await _emailSender.SendEmail(EmailType.MemberAccount, memberDto.Email, bodyContent); return(AccountValidate.ValidationMessage(RequestState.Success, "Create new member success")); }
public async Task <string> GetAuthToken([FromBody] LoginViewModel userDto) { var user = await _userManager.FindByNameAsync(userDto.Username); if (user == null) { return(AccountValidate.ValidationMessage(RequestState.Failed, "User account not exists")); } if (!await _userManager.IsEmailConfirmedAsync(user)) { return(AccountValidate.ValidationMessage(RequestState.Failed, "You must have a confirmed email to log in.")); } var result = await _signInManager.PasswordSignInAsync(userDto.Username, userDto.Password, false, true); if (result.IsLockedOut) { return(AccountValidate.ValidationMessage(RequestState.Failed, "User account locked out.")); } if (!result.Succeeded) { return(AccountValidate.ValidationMessage(RequestState.Failed, "Account credentails is not valid")); } var requesAt = DateTime.Now; var expiresIn = requesAt + TokenAuthOption.ExpiresSpan; //need to pass user id for generate token var token = TokenHelper.GenerateToken(user, expiresIn); return(JsonConvert.SerializeObject(new RequestResult { State = RequestState.Success, Data = new { requesAt, expiresIn = TokenAuthOption.ExpiresSpan.TotalSeconds, tokenType = TokenAuthOption.TokenType, accessToken = token } })); }
/// <summary> /// 登录 /// </summary> /// <param name="loginInfo">登录信息</param> /// <returns>登录结果</returns> public static LoginResult Login(LoginInfo loginInfo) { LoginResult result = new LoginResult(); try { // 验证登录基本信息 AccountValidate.ValdateLoginInfo(loginInfo); // 加载用户信息 var mAccount = Domain.AccountDomain.AccountService.QueryMAccountByAccountNo(loginInfo.AccountNo); // 验证用户信息 AccountValidate.ValdateLoginMAccount(mAccount); // 加载用户领域对象 var account = mAccount.ToAccount(); // 验证公司信息 CompanyValidate.ValdateCompany(account.Company.Value); // 登录 result = account.Login(loginInfo.LoginPassword, loginInfo.SysType); } catch (CustomException ex) { result.Result.IsSucceed = false; result.Result.Message = ex.Message; } catch (Exception ex) { result.Result.IsSucceed = false; result.Result.Message = Const.LoginFail; // 记录异常日志 LogService.WriteLog(ex, Const.Login); } return(result); }