Esempio n. 1
0
        public IActionResult renewToken()
        {
            var i  = Request.HttpContext.User;
            var id = i.Claims.Where(c => c.Type == "Usuario").FirstOrDefault().Value;


            var sr = this._UsuarioService.GetUsuario(id);

            var gr = new APIResponse <LoginModel>();

            if (sr.HasError)
            {
                gr.code              = -1;
                gr.ErrorMessage      = sr.Exception.Message;
                gr.data.token_access = "";

                return(Ok(gr));
            }
            else
            {
                gr.code = 0;
                gr.data = new LoginModel();

                gr.data.Id      = sr.Result.Id;
                gr.data.EsAdmin = sr.Result.EsAdmin;

                var JWTdata = new JWT.JWTHelper().GenerateToken(gr.data.Id, gr.data.EsAdmin);

                gr.data.token_access = JWTdata;


                return(Ok(gr));
            }
        }
Esempio n. 2
0
        public IActionResult login([FromBody] LoginModel model)
        {
            var sr = _UsuarioService.Login(model.Id, model.Contrasena);

            var gr = new APIResponse <LoginModel>();

            gr.data = new LoginModel();

            if (sr.HasError)
            {
                gr.code              = -1;
                gr.ErrorMessage      = sr.Exception.Message + " - Source: " + sr.Exception.Source + " -  St: " + sr.Exception.StackTrace;
                gr.data.token_access = "";

                return(Ok(gr));
            }
            else
            {
                gr.code         = 0;
                gr.data.Id      = sr.Result.Id;
                gr.data.EsAdmin = sr.Result.EsAdmin;

                var JWTdata = new JWT.JWTHelper().GenerateToken(gr.data.Id, gr.data.EsAdmin);

                gr.data.token_access = JWTdata;


                return(Ok(gr));
            }
        }
Esempio n. 3
0
        public IActionResult gettoken()
        {
            var    x = new JWT.JWTHelper();
            string r = x.GenerateToken("jorge", true);

            return(Ok(r));
        }