siteserver / cms

SS CMS 基于 .NET Core,能够以最低的成本、最少的人力投入在最短的时间内架设一个功能齐全、性能优异、规模庞大并易于维护的网站平台。
https://sscms.com
GNU Affero General Public License v3.0
3.7k stars 1.22k forks source link

需要登录2次才能登录进去 #3138

Closed CharlesLueng closed 2 years ago

CharlesLueng commented 3 years ago

系统登录的时候,需要登录2次才能正常登录进来。看了代码是因为登录的时候取出来的用户信息缓存里面不存在验证密码所需要的字段,导致如果用户缓存已存在的情况下需要登录失败一次,移除了用户缓存后,再登录,就会去数据库里取用户信息来校验

YoChen commented 3 years ago

存在此问题,同上:)

YoChen commented 3 years ago

临时解决方案: 1、修改SSCMS/Repoistories/IAdministratorRepository.Cache.cs的第8行,第12行为:

Task<Administrator> GetByAccountAsync(string account, bool useCache = true);
Task<Administrator> GetByUserNameAsync(string userName, bool useCache = true);

2、修改SSCMS.Core/Repoistories/AdministratorRepository.Cache.cs的第57行

public async Task<Administrator> GetByAccountAsync(string account, bool useCache = true)
        {
            var admin = await GetByUserNameAsync(account, useCache);
            if (admin != null) return admin;
            if (StringUtils.IsMobile(account)) return await GetByMobileAsync(account);
            if (StringUtils.IsEmail(account)) return await GetByEmailAsync(account);

            return null;
        }

3、修改SSCMS.Core/Repoistories/AdministratorRepository.Cache.cs的第89行

public async Task<Administrator> GetByUserNameAsync(string userName, bool useCache = true)
        {
            if (string.IsNullOrWhiteSpace(userName)) return null;

            if (useCache)
            {
                return await GetAsync(Q
                    .Where(nameof(Administrator.UserName), userName)
                    .CachingGet(GetCacheKeyByUserName(userName))
                );
            }

            return await GetAsync(Q
                .Where(nameof(Administrator.UserName), userName)
                .CachingRemove(GetCacheKeyByUserName(userName))
                .CachingGet(GetCacheKeyByUserName(userName)));
        }

4、修改SSCMS.Core/Repoistories/AdministratorRepository.cs的第533行 var administrator = await GetByAccountAsync(account, false);

完成修改。原理,登录检测不从缓存中获取(缓存会存在null)的情况,

ifeihong commented 2 years ago

似乎到目前为止7.1还是有这个问题,请官方注意。