public void RegisterUser(RegisterUserInput registerUser) { var existingUser = _userRepository.FirstOrDefault(u => u.EmailAddress == registerUser.EmailAddress); if (existingUser != null) { if (!existingUser.IsEmailConfirmed) { SendConfirmationEmail(existingUser); throw new UserFriendlyException("You registere with this email address before (" + registerUser.EmailAddress + ")! We re-sent an activation code to your email!"); } throw new UserFriendlyException("There is already a user with this email address (" + registerUser.EmailAddress + ")! Select another email address!"); } var userEntity = registerUser.MapTo <TaskeverUser>(); userEntity.Password = new PasswordHasher().HashPassword(userEntity.Password); userEntity.GenerateEmailConfirmationCode(); _userRepository.Insert(userEntity); SendConfirmationEmail(userEntity); }
/// <summary> /// 创建用户 /// </summary> /// <param name="input">input</param> /// <returns></returns> public async Task Register(RegisterUserInput input) { await ValidateCode(input.ValidateCode); var user = input.MapTo <User>(); user.IsActive = true; user.Password = new PasswordHasher().HashPassword(input.Password); if (input.ValidateCode.ValidateType == ValidateType.手机) { user.IsPhoneNoConfirm = true; } else { user.IsEmailConfirmed = true; } var identityResult = await UserManager.CreateAsync(user); if (!identityResult.Succeeded) { throw new UserFriendlyException(identityResult.Errors.JoinAsString(" ")); } }