public void ConfirmSignUpRequest(TodoContext context, SignUpConfirmationRequest signUpConfirmationRequest) { _signUpConfirmationRequestValidator.ValidateAndThrow(signUpConfirmationRequest); var pendingUser = context.PendingUsers .SingleOrDefault(pu => pu.Secret == signUpConfirmationRequest.Secret); if (pendingUser == null) { throw new TodoException(ServiceError.NoSuchPendingUser); } var existingUser = context.Users .SingleOrDefault(u => u.Email == pendingUser.Email); if (existingUser != null) { throw new TodoException(ServiceError.UserAlreadyRegistered); } var user = new User { Email = pendingUser.Email, Password = pendingUser.Password, IsAdmin = false, AuthenticationCount = 0, RegisteredAt = _timeProvider.GetCurrentTime() }; context.Users.Add(user); context.PendingUsers.Remove(pendingUser); context.SaveChanges(); _welcomeNotifier.Notify(user.Email); }
public ServiceResult <Object> ConfirmSignUpRequest(string secret) { var signUpConfirmationRequest = new SignUpConfirmationRequest { Secret = secret }; return(ExecuteWithExceptionHandling( context => ConfirmSignUpRequestTransactionScript.ConfirmSignUpRequest( context, signUpConfirmationRequest))); }