Exemple #1
0
        public ClaimsIdentity SignUp(string email, string password)
        {
            try
            {
                var existingUser = _context.Users.GetAll().FirstOrDefault(x => x.Email == email);
                if (existingUser != null)
                {
                    return(null);
                }

                var newUser = new User
                {
                    Email    = email,
                    Password = HashPassword(password),
                };

                var newBankAccount = new BankAccount
                {
                    AccountNumber = _helperService.GenerateAccountNumber(),
                    UserId        = newUser.Id
                };

                _context.Users.Add(newUser);
                _context.BankAccounts.Add(newBankAccount);
                _context.Save();

                return(new ClaimsIdentity(CreateClaims(email, newUser.Id),
                                          JwtBearerDefaults.AuthenticationScheme));
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                throw;
            }
        }