Ejemplo n.º 1
0
        public async Task <AuthenticateResultModel> Authenticate([FromBody] AuthenticateModel model)
        {
            var loginResult = await GetLoginResultAsync(
                model.UserNameOrEmailAddress,
                model.Password,
                GetTenancyNameOrNull()
                );

            var accessToken = CreateAccessToken(CreateJwtClaims(loginResult.Identity));
            var user        = await _userAppService.GetEntityById(loginResult.User.Id);

            var lastReadTime = _sessionAppService.GetReadLastNoticeTime(loginResult.User.Id);

            // AbpSessions.SaveUserToCache(loginResult); // 记住登录不经过此
            // SessionAppService - GetCurrentLoginInformations

            return(new AuthenticateResultModel
            {
                AccessToken = accessToken,
                EncryptedAccessToken = GetEncrpyedAccessToken(accessToken),
                ExpireInSeconds = (int)_configuration.Expiration.TotalSeconds,
                UserId = loginResult.User.Id,
                SurName = user.Surname,
                Roles = user.RoleNames,
                RoleNames = user.Roles,
                LastReadNoticeTime = lastReadTime
            });
        }