예제 #1
0
        public async Task <UserBearerTokenModel> UserLogin(UserLoginModel model)
        {
            try
            {
                var user = await _context.Users.FirstOrDefaultAsync(u =>
                                                                    u.Email.Equals(model.Email, StringComparison.InvariantCultureIgnoreCase));

                if (user == null)
                {
                    throw new InvalidCredentialsException();
                }

                var hashedPassword = StringUtilities.HashPassword(model.Password, user.Nonce);
                if (!hashedPassword.Equals(user.HashedPassword))
                {
                    throw new InvalidCredentialsException();
                }

                var token          = _accountHelper.JwtGenerator(user.Id, user.FullName, 0, user.UserType);
                var userTokenModel = new UserBearerTokenModel
                {
                    Token = token
                };

                return(userTokenModel);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }