Ejemplo n.º 1
0
        public virtual IActionResult Login([FromBody] LoginModel user)
        {
            if (user == null)
            {
                return(BadRequest("Invalid client request"));
            }

            if (_signInManager.SignIn(user.UserName, user.Password))
            {
                var secretKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_jwtStrings.Value.IssuerSigningKey));
                var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256);
                var tokenOptions      = new JwtSecurityToken(
                    issuer: _jwtStrings.Value.ValidIssuer,
                    audience: _jwtStrings.Value.ValidAudience,
                    claims: new List <Claim>(),
                    expires: DateTime.Now.AddMinutes(_jwtStrings.Value.Expires),
                    signingCredentials: signinCredentials
                    );
                var tokenString = new JwtSecurityTokenHandler().WriteToken(tokenOptions);
                return(Ok(new TokenModel
                {
                    access_token = tokenString,
                    token_type = "bearer",
                    expires_in = _jwtStrings.Value.Expires
                }));
            }

            return(Unauthorized());
        }
Ejemplo n.º 2
0
        public ActionResult LogIn(LoginViewModel model)
        {
            if (model.ValidateCode != "8888")
            {
                throw new Exception("验证码错误!");
            }
            var user = _userService.Login(model.UserNameOrEmail, model.Password);

            if (user == null)
            {
                throw new Exception("用户名或密码错误!");
            }
            _signInManager.SignIn(user.Id.ToString(), model.RememberMe);
            return(AjaxOkResponse("登陆成功!"));
        }
Ejemplo n.º 3
0
        public void user_sign_in()
        {
            var user = new User
            {
                FirstName    = "fn test",
                LastName     = "ln test",
                UserName     = "******",
                Email        = "*****@*****.**",
                Active       = true,
                CreatedOnUtc = DateTime.UtcNow
            };

            _signInManager.CreatePassword(user, "123");
            _repositoryUser.Setup(x => x.Table).Returns(new List <User> {
                user
            }.AsQueryable());
            _signInManager = new SignInManager(_repositoryUser.Object);

            Assert.True(_signInManager.SignIn("user_test", "123"));
        }
Ejemplo n.º 4
0
        /*=================================================================*/



        //
        //[ActAuthorize(ACT.UserEdit, ACT.UserView)]
        public ActionResult Test()
        {
            var user = new OrionUserIdentity
            {
                UserId   = 1,
                UserName = "******",
                Account  = "jax.hu",
                Name     = "jax.hu",
            };

            _signInManager.SignIn(user, new string[] {
                ACT.UserView.ToString(),
                "ProgramView",
                "ProgramInsert",
                "ProgramUpdate",
                "PeoplePicsView",
                "PeoplePicsInsert",
                "SystemMng",
            });


            return(Content("OK " + User.AnyAct(ACT.UserView)));
        }