Esempio n. 1
0
        public UserViewModel Authenticate(string email, string password, out string token)
        {
            var user = _userRepository.GetByEmail(email);

            if (user == null)
            {
                throw new ArgumentException($"No user with email: {email}");
            }

            var hasPassword = Hashing.sha256(password);

            if (user.Password != hasPassword)
            {
                token = null;
                return(null);
            }

            token = _jwtGenerator.Generator(user);
            var viewUser = _mapper.Map <UserViewModel>(user);

            return(viewUser);
        }