Beispiel #1
0
        public async Task <IActionResult> Login([FromBody] LoginInput input)
        {
            if (string.IsNullOrWhiteSpace(input.UserName) ||
                string.IsNullOrWhiteSpace(input.Password))
            {
                return(Ok(ResponseBody.Bad("用户名或密码不能为空")));
            }
            var user = await _userService.LonginAsync(input);

            if (user != null)
            {
                return(Ok(ResponseBody.From(AuthenticateResult.Get(user, _requirement, _cache))));
            }
            return(Ok(ResponseBody.Bad("用户名或密码错误")));
        }
Beispiel #2
0
        public async Task <object> RefreshToken(string token)
        {
            if (string.IsNullOrEmpty(token))
            {
                return(Ok(ResponseBody.Bad("令牌无效,请重新登陆")));
            }
            var uid = JwtToken.ReadJwtToken <int>(token);

            var user = await _userService.GetLoginUserAsync(uid);

            if (user != null)
            {
                return(Ok(ResponseBody.From(AuthenticateResult.Get(user, _requirement, _cache))));
            }
            return(Ok(ResponseBody.Bad("认证失败")));
        }