Exemple #1
0
        public IHttpActionResult Authenticate(LoginRequest login)
        {
            if (login == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            Usuario usuario = ValidarUsuario(login);

            if (!string.IsNullOrEmpty(usuario.USU_IDENTIFICACION))
            {
                var token = TokenGenerator.GenerateTokenJwt(login.Username);
                return(Ok(token));
            }
            else
            {
                return(Unauthorized());
            }
        }
Exemple #2
0
        public IHttpActionResult Authenticate(LoginRequest login)
        {
            if (login == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            //TODO: Validate credentials Correctly, this code is only for demo !!
            bool isCredentialValid = (login.Password == "123456");

            if (isCredentialValid)
            {
                var token = TokenGenerator.GenerateTokenJwt(login.Username);
                return(Ok(token));
            }
            else
            {
                return(Unauthorized());
            }
        }
Exemple #3
0
        public IHttpActionResult Authenticate(LoginRequest login)
        {
            var user         = db.UserAdmins.FirstOrDefault(x => x.Email == login.Email && x.Password == login.Password && x.State == true);
            var userEmail    = db.UserAdmins.FirstOrDefault(x => x.Email == login.Email && x.State == true);
            var userPassword = db.UserAdmins.FirstOrDefault(x => x.Password == login.Password && x.State == true);

            if (userEmail == null || userPassword == null)
            {
                return(BadRequest("Usuario o contrasena incorrectos."));
            }

            if (user == null)
            {
                return(BadRequest("El usuario no existe."));
            }
            else
            {
                var token = TokenGenerator.GenerateTokenJwt(login.Email);
                return(Ok(token));
            }
        }
Exemple #4
0
        public IHttpActionResult Authenticate(LoginRequest login)
        {
            if (login == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            //TODO: This code is only for demo - extract method in new class & validate correctly in your application !!
            var isUserValid = (login.Username == "user" && login.Password == "123456");

            if (isUserValid)
            {
                var rolename = "Developer";
                var token    = TokenGenerator.GenerateTokenJwt(login.Username, rolename);
                return(Ok(token));
            }

            //TODO: This code is only for demo - extract method in new class & validate correctly in your application !!
            var isTesterValid = (login.Username == "test" && login.Password == "123456");

            if (isTesterValid)
            {
                var rolename = "Tester";
                var token    = TokenGenerator.GenerateTokenJwt(login.Username, rolename);
                return(Ok(token));
            }

            //TODO: This code is only for demo - extract method in new class & validate correctly in your application !!
            var isAdminValid = (login.Username == "admin" && login.Password == "123456");

            if (isAdminValid)
            {
                var rolename = "Administrator";
                var token    = TokenGenerator.GenerateTokenJwt(login.Username, rolename);
                return(Ok(token));
            }

            // Unauthorized access
            return(Unauthorized());
        }