Ejemplo n.º 1
0
        private string GetToken(User user, bool remember = true)
        {
            // TODO: use remember me when creating a token.
            var token = _tokenManager.Create(user);

            return(token.Id);
        }
Ejemplo n.º 2
0
        public Token SignIn(string _UserName, string _UserPwd)
        {
            var a = from users in db.User select users;

            foreach (var i in a)
            {
                if (i.UserName == _UserName && i.UserPwd == _UserPwd)
                {
                    var token = _tokenManager.Create(i);
                    i.token      = token.Access_token;
                    i.Expires_in = token.expires_in;
                    refreshTokens.Add(token.Refresh_token, i);
                    return(token);
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        public static HttpStatusCode Login(string login, string password)
        {
            var request = new RestRequest(_loginUrl, Method.POST);

            request.AddJsonBody(new { username = login, userpassword = password });
            var response = _client.Execute <Dictionary <string, string> >(request);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                TokenManager.Create(response.Data["accessToken"], response.Data["refreshToken"]);
                UserId = Convert.ToInt64(response.Data["userId"]);
            }
            return(response.StatusCode);
        }
Ejemplo n.º 4
0
        public Token SignIn(User user)
        {
            //模擬從資料庫取得資料
            //if (!(model.UserId == "abc" && model.Password == "123"))
            //{
            //    throw new Exception("登入失敗,帳號或密碼錯誤");
            //}
            //var user = new User
            //{
            //    Id = 1,
            //    UserId = "abc",
            //    UserName = "******"
            //};
            //產生 Token
            var token = _tokenManager.Create(user);

            //需存入資料庫
            refreshTokens.Add(token.refresh_token, user);
            return(token);
        }
Ejemplo n.º 5
0
        private string GetToken(User user)
        {
            var token = _tokenManager.Create(user);

            return(token.Id);
        }
Ejemplo n.º 6
0
        public string Get()
        {
            var result = TokenManager.Create(5, new AdminRole());

            return(result);
        }