public async Task <CommandResponse <User> > Handle(Command cmd, CancellationToken cancellationToken) { var r = await _storage.GetUserAssociation(cmd.Id); if (r == null) { return(CommandResponse <User> .Failed( "Invalid confirmation identifier.")); } if (r.IsOlderThan(60 * 24 * 30)) // 30 day expiration? { return(CommandResponse <User> .Failed( "Account confirmation link is expired. Please request a new one.")); } var u = await _storage.GetUser(r.UserId); if (u == null) { return(CommandResponse <User> .Failed( "User account is no longer valid")); } u.Confirm(); await _storage.Save(u); return(CommandResponse <User> .Success(u)); }
public async Task <CommandResponse <User> > Handle(Command cmd, CancellationToken cancellationToken) { var r = await _storage.GetUserAssociation(cmd.Id.Value); if (r == null) { return(CommandResponse <User> .Failed( "Invalid password reset token. Check the link in the email or request a new password reset")); } if (r.IsOlderThan(15)) { return(CommandResponse <User> .Failed( "Password reset link has expired. Please request a new password reset")); } var u = await _storage.GetUser(r.UserId); if (u == null) { return(CommandResponse <User> .Failed( "User account is no longer valid")); } var hash = _hash.Generate(cmd.Password, 32); u.SetPassword(hash.Hash, hash.Salt); await _storage.Save(u); return(CommandResponse <User> .Success(u)); }
public async Task <CommandResponse <User> > Handle(Command request, CancellationToken cancellationToken) { var user = await _storage.GetUserByEmail(request.Email); if (user == null) { return(CommandResponse <User> .Failed(GENERIC_MSG)); } // oauth path where password was not set.... if (!user.State.IsPasswordAvailable) { return(CommandResponse <User> .Failed(GENERIC_MSG)); } var computed = _hash.Generate(request.Password, user.State.GetSalt()); var matches = user.PasswordHashMatches(computed); if (matches) { user.LoggedIn(request.IPAddress, DateTimeOffset.UtcNow); await _storage.Save(user); return(CommandResponse <User> .Success(user)); } return(CommandResponse <User> .Failed(GENERIC_MSG)); }
public async Task <Unit> Handle(Command cmd, CancellationToken cancellationToken) { var user = await _storage.GetUser(cmd.UserId); if (user == null) { return(new Unit()); } user.Delete(cmd.Feedback); await _storage.Save(user); await _emails.Send( EmailSettings.Admin, Sender.NoReply, EmailTemplate.AdminUserDeleted, new { feedback = cmd.Feedback, email = user.State.Email }); await _storage.Delete(user); await _portfolio.Delete(user.Id); return(new Unit()); }
public async Task <Guid> Handle(Command request, CancellationToken cancellationToken) { var user = await _storage.GetUserByEmail(request.Email); if (user == null) { user = new User(request.Email, request.Firstname, request.Lastname); await _storage.Save(user); } return(user.State.Id); }
public async Task <string> Handle(Command request, CancellationToken cancellationToken) { var user = await _storage.GetUser(request.UserId); if (user == null) { return($"Unable to load user {request.UserId}"); } user.LoggedIn(request.IPAddress, request.Timestamp); await _storage.Save(user); return(""); }
public async Task <CommandResponse> Handle(Request request, CancellationToken cancellationToken) { var user = await _storage.GetUserByEmail(request.Email); if (user == null) { // not really success, but we are not going to disclose // if user account exists for a given email return(CommandResponse.Success()); } user.RequestPasswordReset(DateTimeOffset.UtcNow); await _storage.Save(user); return(CommandResponse.Success()); }
public async Task <CommandResponse <User> > Handle(Command cmd, CancellationToken cancellationToken) { var exists = await _storage.GetUserByEmail(cmd.UserInfo.Email); if (exists != null) { return(CommandResponse <User> .Failed($"Account with {cmd.UserInfo} already exists")); } var u = new User(cmd.UserInfo.Email, cmd.UserInfo.Firstname, cmd.UserInfo.Lastname); var(hash, salt) = _hash.Generate(cmd.UserInfo.Password, 32); u.SetPassword(hash, salt); if (cmd.PaymentInfo != null) { var result = _subscriptions.Create( u, planId: cmd.PaymentInfo.PlanId, paymentToken: cmd.PaymentInfo.Token.Id, email: cmd.PaymentInfo.Token.Email); if (result.CustomerId != null) { u.SubscribeToPlan(cmd.PaymentInfo.PlanId, result.CustomerId, result.SubscriptionId); } else { return(CommandResponse <User> .Failed( $"Failed to process the payment, please try again or use a different payment form" )); } } await _storage.Save(u); return(CommandResponse <User> .Success(u)); }
/// <summary> /// Saves the accounts to the storage. /// </summary> public void Save() => _storage.Save();