示例#1
0
        public async Task <AuthenticateOutput> IsAuthenticated()
        {
            var userid = AbpSession.UserId;

            if (!userid.HasValue)
            {
                return(null);
            }
            var result = await _userRepository.GetAsync((int)userid.Value);

            if (result.Locked)
            {
                return(null);
            }
            var token = await HttpContext.GetTokenAsync(JwtBearerDefaults.AuthenticationScheme, "access_token");

            var utc = new JwtSecurityTokenHandler().ReadJwtToken(token).ValidTo;

            if (result != null)
            {
                return(new AuthenticateOutput
                {
                    AccessToken = token,
                    ExpireInSeconds = (int)(utc.ToLocalTime() - DateTime.Now).TotalSeconds,
                    UserId = result.Id,
                    Phone = result.Phone,
                    Realname = result.Realname,
                    Username = result.Username,
                    //Role = (int)result.Role,
                    RegionCode = result.RegionCode,
                    //Department = result.Department,
                    RegionIndex = result.RegionIndex,
                    RegionName = result.RegionName
                });
            }
            return(null);
        }