예제 #1
0
        public async Task <TokenModel> LoginAsync(string email, string password)
        {
            var user = await _dbContext.Users.FirstOrDefaultAsync(x => x.Email == email);

            if (user == null)
            {
                throw new CinemaException(ErrorCodes.InvalidCredentials);
            }
            var generatedHash = _encrypter.Compute(password, user.Salt);

            if (!_encrypter.Compare(generatedHash, user.Password))
            {
                throw new CinemaException(ErrorCodes.InvalidCredentials);
            }
            if (user.IsConfirmed == false)
            {
                throw new CinemaException(ErrorCodes.NotActivated);
            }
            var token = _tokenProvider.CreateToken(user.Id, user.Role);

            return(token);
        }