fix: 用户为空时直接返回空角色集合

This commit is contained in:
Argo Zhang 2019-08-24 00:08:00 +08:00
parent 33235323a2
commit 045ffc8ce2
1 changed files with 6 additions and 4 deletions

View File

@ -78,10 +78,12 @@ namespace Bootstrap.DataAccess.MongoDB
{
var roles = new List<string>();
var user = UserHelper.Retrieves().Cast<User>().FirstOrDefault(u => u.UserName.ToLowerInvariant() == userName.ToLowerInvariant());
var role = RoleHelper.Retrieves();
roles.AddRange(role.Where(r => user.Roles.Any(rl => rl == r.Id)).Select(r => r.RoleName));
if (roles.Count == 0) roles.Add("Default");
if (user != null)
{
var role = RoleHelper.Retrieves();
roles.AddRange(role.Where(r => user.Roles.Any(rl => rl == r.Id)).Select(r => r.RoleName));
if (roles.Count == 0) roles.Add("Default");
}
return roles;
}