Ejemplo n.º 1
0
        private User CheckUser(UserCredentials credentials)
        {
            var found = this.GetUserFromDatabase(credentials?.username, credentials?.password.EncryptPassword());

            if (found != null)
            {
                return(found);
            }
            return(new User()
            {
                id = 0
            });
        }
Ejemplo n.º 2
0
        public dynamic Get(UserCredentials credentials)
        {
            if (string.IsNullOrEmpty(credentials?.username) || string.IsNullOrEmpty(credentials?.password))
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            var user = this.CheckUser(credentials);

            if (user.id != 0)
            {
                return(JwtManager.GenerateToken(user));
            }

            throw new HttpResponseException(HttpStatusCode.Unauthorized);
        }