Exemple #1
0
        public void Check(JwtAuthorizationContext context)
        {
            Console.WriteLine("open database");

            //// 1.using database
            //using (var cnn = _dbFactory.Create())
            //{
            //    var auth = cnn.QuerySingleOrDefault<User>(@"Select id, name, email From users Where email = @email and pwd = @pwd", new { email = context.UserName, pwd = context.Password });
            //    if (auth != null)
            //    {
            //        context.AddClaim("email", auth.Email);
            //    }
            //}


            // 2.hardcode
            if (context.UserName == "admin" && context.Password == "admin")
            {
                context.AddClaim("username", "admin");
                //context.AddClaim("userid", "");
            }
            else
            {
                context.Rejected("username or password error", "please check your username and password!");
            }
        }
Exemple #2
0
        public void Check(JwtAuthorizationContext context)
        {
            Console.WriteLine("open database");

            /*
             *       // using database
             *       _cnn.Open();
             *         var auth = _cnn.QuerySingleOrDefault<User>(@"Select id, name, email From users Where email = @email and pwd = @pwd", new { email = context.UserName, pwd = context.Password });
             *         if (auth != null)
             *         {
             *             context.AddClaim("email", auth.Email);
             *         }
             */

            // hardcode
            if (context.UserName == "admin" && context.Password == "admin")
            {
                context.AddClaim("username", "admin");
                //context.AddClaim("userid", "");
            }
            else
            {
                context.Rejected("username or password error", "please check your username and password!");
            }
        }
Exemple #3
0
        public void Check(JwtAuthorizationContext context)
        {
            Console.WriteLine("open database");
            _cnn.Open();
            var auth = _cnn.QuerySingleOrDefault <User>(@"Select id, name, email From users Where email = @email and pwd = @pwd", new { email = context.UserName, pwd = context.Password });

            if (auth != null)
            {
                context.AddClaim("email", auth.Email);
            }
        }
Exemple #4
0
 public void CheckUser(JwtAuthorizationContext context)
 {
     if (context.UserName == "admin" && context.Password == "admin")
     {
         context.AddClaim("username", "admin");
         context.AddClaim("roles", "admin");
     }
     else
     {
         context.Rejected("401", "acount or password incorrect");
     }
 }