Esempio n. 1
0
        public JsonResult GetJWTStr(TokenModel model)
        {
            TimeSpan date1 = new TimeSpan(4, 20, 33);

            TimeSpan date2 = new TimeSpan(4, 20, 33);

            return(Json(RayPIToken.IssueJWT(model, date1, date2)));
        }
Esempio n. 2
0
        public ActionResult <string> GetToken(TokenModel model)
        {
            var time  = DateTime.Now;
            var token = RayPIToken.IssueJWT(new TokenModel()
            {
                Uid = model.Uid,
                Sub = model.Sub
            }, new TimeSpan(time.Day, time.Hour, time.Minute + model.expireMinutes), new TimeSpan(time.Day, time.Hour, time.Minute + model.expireMinutes));

            return(token);
        }
Esempio n. 3
0
        public JsonResult GetJWTStr(long id, string sub, int expiresSliding = 30, int expiresAbsoulute = 30)
        {
            Token.Model.TokenModel tokenModel = new Token.Model.TokenModel();
            tokenModel.Uid = id;
            tokenModel.Sub = sub;

            DateTime d1        = DateTime.Now;
            DateTime d2        = d1.AddMinutes(expiresSliding);
            DateTime d3        = d1.AddDays(expiresAbsoulute);
            TimeSpan sliding   = d2 - d1;
            TimeSpan absoulute = d3 - d1;

            string jwtStr = RayPIToken.IssueJWT(tokenModel, sliding, absoulute);

            return(Json(jwtStr));
        }
Esempio n. 4
0
        public void Getjsonp(string callBack, long id = 1, string sub = "Admin", int expiresSliding = 30, int expiresAbsoulute = 30)
        {
            TokenModel model = new TokenModel()
            {
                Uid       = 1,
                Uname     = "TT",
                Phone     = "666",
                Icon      = "23123",
                UNickname = "糖糖",
                Sub       = "Admin"
            };
            TimeSpan time1    = (DateTime.Now.AddDays(1) - DateTime.Now);
            TimeSpan time2    = (DateTime.Now.AddMonths(1) - DateTime.Now);
            string   response = RayPIToken.IssueJWT(model, time1, time2);
            string   call     = callBack + "({" + response + "})";

            Response.WriteAsync(call);
        }
Esempio n. 5
0
        public IActionResult Token(string name, string pass)
        {
            string jwtStr = string.Empty;
            bool   suc    = false;

            // 获取用户的角色名,请暂时忽略其内部是如何获取的,可以直接用 var userRole="Admin"; 来代替更好理解。
            string userRole = ""; // await _sysUserInfoServices.GetUserRoleNameStr(name, pass);

            if (name.ToLower() == "admin")
            {
                userRole = "Admin";
            }
            else if (name.ToLower() == "System")
            {
                userRole = "System";
            }
            else if (name.ToLower() != "")
            {
                userRole = "User";
            }

            if (userRole != "")
            {
                // 将用户id和角色名,作为单独的自定义变量封装进 token 字符串中。
                TokenModel tokenModel = new TokenModel {
                    Uid = 1, Role = userRole
                };
                //jwtStr = JwtHelper.IssueJwt(tokenModel);//登录,获取到一定规则的 Token 令牌
                jwtStr = RayPIToken.IssueJWT(tokenModel);//登录,获取到一定规则的 Token 令牌
                suc    = true;
            }
            else
            {
                jwtStr = "login fail!!!";
            }

            return(Ok(new
            {
                success = suc,
                token = jwtStr
            }));
        }
Esempio n. 6
0
        public string Get(int id)
        {
            TokenModel model = new TokenModel()
            {
                Uid       = 1,
                Uname     = "TT",
                Phone     = "666",
                Icon      = "23123",
                UNickname = "糖糖",
                Sub       = "Admin"
            };
            TimeSpan time1 = (DateTime.Now.AddDays(1) - DateTime.Now);
            TimeSpan time2 = (DateTime.Now.AddMonths(1) - DateTime.Now);

            RayPIToken.IssueJWT(model, time1, time2);



            var result = UserInfoServices.Userstr();

            return(result);
        }