public async Task ForgotPasswordAsync(ForgotPasswordRequest request) { Account account = _accountsRepository.FindBy(a => a.Email == request.Email).FirstOrDefault(); if (account == null) { throw new Exception("Account with that email does not exist!"); } account.GenerateForgotPasswordToken(); await _unitOfWork.SaveChangesAsync(); string callbackUrl = UrlHelper.AddUrlParameters( url: request.RedirectUrl, parameters: new Dictionary <string, string> { { "token", account.ForgotPasswordToken } }); await PublishEmailEvent("Change password", account.Email, callbackUrl); }
public async Task <Account> CreateUserAsync(CreateAccountRequest request) { bool isAccountExist = _accountsRepository.Any(a => a.Email == request.Email); if (isAccountExist) { throw new Exception("Account with that email already exists!"); } Account newAccount = new Account(request.Email, request.Password, request.UserName, request.BirthDay, SystemRoles.User); await _accountsRepository.AddAsync(newAccount); await _unitOfWork.SaveChangesAsync(); string callbackUrl = UrlHelper.AddUrlParameters( url: $"{_accessor.HttpContext.Request.Scheme}://{_accessor.HttpContext.Request.Host}/api/auth/verify-email", parameters: new Dictionary <string, string> { { "token", newAccount.VerifyEmailToken }, { "redirectUrl", request.RedirectUrl } }); await PublishEmailEvent("Verify account", newAccount.Email, callbackUrl); await _serviceBus.PublishAsync ( new UserCreatedEvent { Email = newAccount.Email, UserId = newAccount.Id, UserName = newAccount.UserName } ); return(newAccount); }