fix: 用户为空时直接返回空角色集合
This commit is contained in:
parent
33235323a2
commit
045ffc8ce2
|
@ -78,10 +78,12 @@ namespace Bootstrap.DataAccess.MongoDB
|
||||||
{
|
{
|
||||||
var roles = new List<string>();
|
var roles = new List<string>();
|
||||||
var user = UserHelper.Retrieves().Cast<User>().FirstOrDefault(u => u.UserName.ToLowerInvariant() == userName.ToLowerInvariant());
|
var user = UserHelper.Retrieves().Cast<User>().FirstOrDefault(u => u.UserName.ToLowerInvariant() == userName.ToLowerInvariant());
|
||||||
var role = RoleHelper.Retrieves();
|
if (user != null)
|
||||||
|
{
|
||||||
roles.AddRange(role.Where(r => user.Roles.Any(rl => rl == r.Id)).Select(r => r.RoleName));
|
var role = RoleHelper.Retrieves();
|
||||||
if (roles.Count == 0) roles.Add("Default");
|
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;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue