コード例 #1
0
        public ActionResult GenerateSignature()
        {
            if (!Authentication.IsSigned())
            {
                return(Json(new { Error = "Need to login" }));
            }
            Customer user = Authentication.GetUser();

            return(Json(new { token = SJWT.GenerateToken(user.Account.Id, user.Account.Email, user.Account.Password) }));
        }
コード例 #2
0
 public static void SignIn(uint id, string email, string password)
 {
     if (!IsSigned())
     {
         HttpCookie cookie = new HttpCookie("sjwt", SJWT.GenerateToken(id, email, password))
         {
             Expires = DateTime.MaxValue
         };
         cookie.HttpOnly = true;
         HttpContext.Current.Response.AppendCookie(cookie);
     }
 }
コード例 #3
0
        /*public static void RememberMe() {
         *  if (HttpContext.Current.Request.Cookies["remember_me"] == null) {
         *      HttpCookie cookie = new HttpCookie("remember_me", "true") {
         *          Expires = DateTime.MaxValue
         *      };
         *      HttpContext.Current.Response.Cookies.Add(cookie);
         *  }
         * }*/


        public static Customer GetUser()
        {
            HttpCookie token = GetToken();

            if (token == null)
            {
                return(null);
            }
            dynamic data    = SJWT.GetTokenData(token.Value);
            dynamic payload = data.Payload;
            object  id      = payload.id;

            return(CustomerDAO.GetById(Convert.ToUInt32(id)));
        }
コード例 #4
0
        public static bool VerifyTokenMobile()
        {
            var headerToken = HttpContext.Current.Request.Headers["Authorization"];

            if (headerToken == null || headerToken == "null")
            {
                return(false);
            }
            string   token    = headerToken.Split(' ')[1];
            dynamic  data     = SJWT.GetTokenData(token);
            Customer c        = CustomerDAO.GetById(Convert.ToUInt32(data.Payload.id));
            string   newToken = SJWT.GenerateToken(c.Account.Id, c.Account.Email, c.Account.Password);

            return(token == newToken);
        }