|
@@ -1,7 +1,6 @@
|
|
using System;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
-using System.Security.Claims;
|
|
|
|
using Admin.Core.Model.Admin;
|
|
using Admin.Core.Model.Admin;
|
|
using Admin.Core.Model.Output;
|
|
using Admin.Core.Model.Output;
|
|
using Admin.Core.Repository.Admin;
|
|
using Admin.Core.Repository.Admin;
|
|
@@ -19,24 +18,24 @@ namespace Admin.Core.Service.Admin.Auth
|
|
private readonly IUser _user;
|
|
private readonly IUser _user;
|
|
private readonly ICache _cache;
|
|
private readonly ICache _cache;
|
|
private readonly IMapper _mapper;
|
|
private readonly IMapper _mapper;
|
|
- private readonly IUserToken _userToken;
|
|
|
|
private readonly IUserRepository _userRepository;
|
|
private readonly IUserRepository _userRepository;
|
|
|
|
+ private readonly IPermissionRepository _permissionRepository;
|
|
private readonly IRolePermissionRepository _rolePermissionRepository;
|
|
private readonly IRolePermissionRepository _rolePermissionRepository;
|
|
|
|
|
|
public AuthService(
|
|
public AuthService(
|
|
IUser user,
|
|
IUser user,
|
|
ICache cache,
|
|
ICache cache,
|
|
IMapper mapper,
|
|
IMapper mapper,
|
|
- IUserToken userToken,
|
|
|
|
IUserRepository userRepository,
|
|
IUserRepository userRepository,
|
|
|
|
+ IPermissionRepository permissionRepository,
|
|
IRolePermissionRepository rolePermissionRepository
|
|
IRolePermissionRepository rolePermissionRepository
|
|
)
|
|
)
|
|
{
|
|
{
|
|
_user = user;
|
|
_user = user;
|
|
_cache = cache;
|
|
_cache = cache;
|
|
_mapper = mapper;
|
|
_mapper = mapper;
|
|
- _userToken = userToken;
|
|
|
|
_userRepository = userRepository;
|
|
_userRepository = userRepository;
|
|
|
|
+ _permissionRepository = permissionRepository;
|
|
_rolePermissionRepository = rolePermissionRepository;
|
|
_rolePermissionRepository = rolePermissionRepository;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -50,11 +49,11 @@ namespace Admin.Core.Service.Admin.Auth
|
|
var verifyCode = await _cache.GetAsync(verifyCodeKey);
|
|
var verifyCode = await _cache.GetAsync(verifyCodeKey);
|
|
if (string.IsNullOrEmpty(verifyCode))
|
|
if (string.IsNullOrEmpty(verifyCode))
|
|
{
|
|
{
|
|
- return ResponseOutput.NotOk("验证码已过期!",1);
|
|
|
|
|
|
+ return ResponseOutput.NotOk("验证码已过期!", 1);
|
|
}
|
|
}
|
|
if (verifyCode.ToLower() != input.VerifyCode.ToLower())
|
|
if (verifyCode.ToLower() != input.VerifyCode.ToLower())
|
|
{
|
|
{
|
|
- return ResponseOutput.NotOk("验证码输入有误!",2);
|
|
|
|
|
|
+ return ResponseOutput.NotOk("验证码输入有误!", 2);
|
|
}
|
|
}
|
|
await _cache.DelAsync(verifyCodeKey);
|
|
await _cache.DelAsync(verifyCodeKey);
|
|
}
|
|
}
|
|
@@ -80,14 +79,14 @@ namespace Admin.Core.Service.Admin.Auth
|
|
var secretKey = await _cache.GetAsync(passwordEncryptKey);
|
|
var secretKey = await _cache.GetAsync(passwordEncryptKey);
|
|
if (passwordEncryptKey.IsNull())
|
|
if (passwordEncryptKey.IsNull())
|
|
{
|
|
{
|
|
- return ResponseOutput.NotOk("解密失败!",1);
|
|
|
|
|
|
+ return ResponseOutput.NotOk("解密失败!", 1);
|
|
}
|
|
}
|
|
input.Password = DesEncrypt.Decrypt(input.Password, secretKey);
|
|
input.Password = DesEncrypt.Decrypt(input.Password, secretKey);
|
|
await _cache.DelAsync(passwordEncryptKey);
|
|
await _cache.DelAsync(passwordEncryptKey);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- return ResponseOutput.NotOk("解密失败!",1);
|
|
|
|
|
|
+ return ResponseOutput.NotOk("解密失败!", 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
#endregion
|
|
@@ -95,7 +94,7 @@ namespace Admin.Core.Service.Admin.Auth
|
|
var password = MD5Encrypt.Encrypt32(input.Password);
|
|
var password = MD5Encrypt.Encrypt32(input.Password);
|
|
if (user.Password != password)
|
|
if (user.Password != password)
|
|
{
|
|
{
|
|
- return ResponseOutput.NotOk("密码输入有误!",4);
|
|
|
|
|
|
+ return ResponseOutput.NotOk("密码输入有误!", 4);
|
|
}
|
|
}
|
|
|
|
|
|
var authLoginOutput = _mapper.Map<AuthLoginOutput>(user);
|
|
var authLoginOutput = _mapper.Map<AuthLoginOutput>(user);
|
|
@@ -111,34 +110,36 @@ namespace Admin.Core.Service.Admin.Auth
|
|
}
|
|
}
|
|
|
|
|
|
var user = await _userRepository.Select.WhereDynamic(_user.Id)
|
|
var user = await _userRepository.Select.WhereDynamic(_user.Id)
|
|
- .ToOneAsync(m=>new {
|
|
|
|
|
|
+ .ToOneAsync(m => new {
|
|
m.NickName,
|
|
m.NickName,
|
|
m.Name,
|
|
m.Name,
|
|
m.Avatar
|
|
m.Avatar
|
|
});
|
|
});
|
|
|
|
|
|
//获取菜单
|
|
//获取菜单
|
|
- var menus = await _rolePermissionRepository.Select
|
|
|
|
- .InnerJoin<UserRoleEntity>((a, b) => a.RoleId == b.RoleId && b.UserId == _user.Id)
|
|
|
|
- .Include(a => a.Permission.View)
|
|
|
|
- .Where(a => new[] { PermissionType.Group,PermissionType.Menu }.Contains(a.Permission.Type))
|
|
|
|
- //.Distinct()
|
|
|
|
- .OrderBy(a => a.Permission.ParentId)
|
|
|
|
- .OrderBy(a => a.Permission.Sort)
|
|
|
|
|
|
+ var menus = await _permissionRepository.Select
|
|
|
|
+ .Where(a => new[] { PermissionType.Group, PermissionType.Menu }.Contains(a.Type))
|
|
|
|
+ .Where(a =>
|
|
|
|
+ _rolePermissionRepository.Select
|
|
|
|
+ .InnerJoin<UserRoleEntity>((b, c) => b.RoleId == c.RoleId && b.PermissionId == a.Id && c.UserId == _user.Id)
|
|
|
|
+ .Any()
|
|
|
|
+ )
|
|
|
|
+ .OrderBy(a => a.ParentId)
|
|
|
|
+ .OrderBy(a => a.Sort)
|
|
.ToListAsync(a => new
|
|
.ToListAsync(a => new
|
|
{
|
|
{
|
|
- a.Permission.Id,
|
|
|
|
- a.Permission.ParentId,
|
|
|
|
- a.Permission.Path,
|
|
|
|
- ViewPath = a.Permission.View.Path,
|
|
|
|
- a.Permission.Label,
|
|
|
|
-
|
|
|
|
- a.Permission.Icon,
|
|
|
|
- a.Permission.Opened,
|
|
|
|
- a.Permission.Closable,
|
|
|
|
- a.Permission.Hidden,
|
|
|
|
- a.Permission.NewWindow,
|
|
|
|
- a.Permission.External
|
|
|
|
|
|
+ a.Id,
|
|
|
|
+ a.ParentId,
|
|
|
|
+ a.Path,
|
|
|
|
+ ViewPath = a.View.Path,
|
|
|
|
+ a.Label,
|
|
|
|
+
|
|
|
|
+ a.Icon,
|
|
|
|
+ a.Opened,
|
|
|
|
+ a.Closable,
|
|
|
|
+ a.Hidden,
|
|
|
|
+ a.NewWindow,
|
|
|
|
+ a.External
|
|
});
|
|
});
|
|
|
|
|
|
return ResponseOutput.Ok(new { user, menus });
|
|
return ResponseOutput.Ok(new { user, menus });
|