public async Task <User> CreateAsync(string tenantId, UserCreator userCreator) { if (string.IsNullOrWhiteSpace(userCreator.Password)) { throw new IllegalArgumentException(code: "USER_PASSWORD_INVALID", message: _sl[UserResource.PASSWORD_MUST_BE_SET] !); } if (string.IsNullOrWhiteSpace(userCreator.Login)) { throw new IllegalArgumentException(code: "USER_LOGIN_INVALID", message: _sl[UserResource.LOGIN_MUST_BE_SET] !); } if (string.IsNullOrWhiteSpace(userCreator.Email) || !EmailValidator.EmailValid(userCreator.Email)) { throw new IllegalArgumentException(code: "USER_EMAIL_INVALID", message: _sl[UserResource.EMAIL_FORMAT_INVALID] !); } if ((await _userRepository.FindAllAsync(new(Login: userCreator.Login))).Count != 0 || (await _userRepository.FindAllAsync(new(Email: userCreator.Email))).Count != 0) { throw new IllegalArgumentException(code: "USER_EXISTS", message: string.Format(_sl[UserResource.USER_P0_ALREADY_EXISTS] !, userCreator.Login)); } var secretValues = await _daprClient.GetSecretAsync(ConfigConstant.CodexKey, ConfigConstant.PasswordSalt); var salt = secretValues[ConfigConstant.PasswordSalt]; var user = userCreator.ToUser(passwordHash: _passwordHasher.GenerateHash(userCreator.Password !, salt)); // generate activation code for 30 days user = user with { ActivationCode = StringUtils.RandomString(50), ActivationValidity = DateTime.Now.AddDays(30) }; var userRow = await _userRepository.InsertAsync(_mapper.Map <UserRow>(user)); user = _mapper.Map <User>(userRow); await SendActivationUserEmailAsync(user, tenantId); return(user); }
public async Task <User> CreateAsync(string tenantId, UserCreator userCreator) { if (string.IsNullOrWhiteSpace(userCreator.Password)) { throw new IllegalArgumentException(code: "USER_PASSWORD_INVALID", message: "Password must be not null or whitespace"); } if (string.IsNullOrWhiteSpace(userCreator.Login)) { throw new IllegalArgumentException(code: "USER_LOGIN_INVALID", message: "Login must be not null or whitespace"); } if (string.IsNullOrWhiteSpace(userCreator.Email) || !EmailValidator.EmailValid(userCreator.Email)) { throw new IllegalArgumentException(code: "USER_EMAIL_INVALID", message: "Email format is invalid"); } if ((await _userRepository.FindAllAsync(new (Login: userCreator.Login))).Count != 0 || (await _userRepository.FindAllAsync(new(Email: userCreator.Email))).Count != 0) { throw new IllegalArgumentException(code: "USER_EXISTS", message: $"User '{userCreator.Login}' already exists"); } var secretValues = await _daprClient.GetSecretAsync(ConfigConstant.CodexKey, ConfigConstant.PasswordSalt); var salt = secretValues[ConfigConstant.PasswordSalt]; var user = userCreator.ToUser(passwordHash: _passwordHasher.GenerateHash(userCreator.Password !, salt)); // generate activation code for 30 days user = user with { ActivationCode = StringUtils.RandomString(50), ActivationValidity = DateTime.Now.AddDays(30) }; user = await _userRepository.InsertAsync(user); await SendActivationUserEmailAsync(user, tenantId); return(user); }
public void EmailValid_Empty_Email() { bool result = EmailValidator.EmailValid(""); Assert.False(result); }
public void EmailValid_Invalid_Email_3() { bool result = EmailValidator.EmailValid("[email protected]"); Assert.False(result); }
public void EmailValid_Invalid_Email_1() { bool result = EmailValidator.EmailValid("@gmail.com"); Assert.False(result); }
public void EmailValid_valid_1() { bool result = EmailValidator.EmailValid("test@gmailcom"); Assert.True(result); }