public async Task <string> AddAccount(DataAccountsRequest account) { if (!await GetIsEmployee()) { throw new Exception("User does not have access to this resource"); } var duplicateAccount = await GetAccountByEmail(account.Email); if (duplicateAccount.Count > 0) { throw new DuplicateNameException($"Account alread exists with email: {account.Email}"); } var accountDto = new AccountsDto() { CompanyName = account.CompanyName, Email = account.Email, Id = Guid.NewGuid().ToString(), PasswordHash = IntegraTestEncryption.ComputePasswordHash(account.Password) }; await DynamoDbContextProvider.CurrentContext.SaveAsync <AccountsDto>(accountDto); return(accountDto.Id); }
public void AddUser() { var accountClient = new DataClient("664ca358-3ae8-4d79-9554-682d21a01467").Accounts(); var user = new DataAccountsRequest() { CompanyName = "Number One", Email = "*****@*****.**", Password = "******" }; var id = accountClient.AddAccount(user).Result; var returnedUser = accountClient.GetAccountById(id); var otherReturnedUser = accountClient.GetAccountByEmail(user.Email).Result.FirstOrDefault(); var passwordHash = returnedUser.Result.PasswordHash; var correct = IntegraTestEncryption.IsCorrectPassword(user.Password, passwordHash); }
public async Task <string> Login(LoginRequest request) { var account = await _accountsService.GetFullAccountByEmail(request.Email).ConfigureAwait(false); if (account == null) { throw new Exception("Login failed"); } var valid = IntegraTestEncryption.IsCorrectPassword(request.Password, account.PasswordHash); if (!valid) { throw new Exception("Login failed"); } return(JwtHelpers.CreateJwt(new JwtRequest() { UserEmail = account.Email, UserId = account.Id })); }