Esempio n. 1
0
        public async Task <UserDtoModel> Authenticate(LoginDtoModel loginModel)
        {
            var existingUser = await _entitySet
                               .AsNoTracking()
                               .SingleOrDefaultAsync(e => e.Email == loginModel.Email);

            if (existingUser != null && PasswordHasher.VerifyPassword(existingUser.PasswordHash, loginModel.Password))
            {
                existingUser.PasswordHash = null;
                existingUser.AuthToken    = GenerateAuthToken(loginModel.Email);
                return(_mapper.Map <UserDtoModel>(existingUser));
            }

            return(null);
        }
Esempio n. 2
0
        public async Task <ActionResult <UserModel> > Authenticate(LoginDtoModel loginModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await(_repository as UsersRepository).Authenticate(loginModel);

            if (user == null)
            {
                return(Unauthorized());
            }

            return(Ok(user));
        }