2015-11-30 17:44:42 +08:00
|
|
|
|
using OpenAuth.Domain.Interface;
|
2015-09-22 23:10:00 +08:00
|
|
|
|
using System;
|
2015-12-01 17:30:24 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Infrastructure;
|
2015-11-30 17:44:42 +08:00
|
|
|
|
using Infrastructure.Helper;
|
2015-12-01 17:30:24 +08:00
|
|
|
|
using OpenAuth.App.ViewModel;
|
2015-09-23 00:10:11 +08:00
|
|
|
|
using OpenAuth.Domain;
|
2015-09-22 23:10:00 +08:00
|
|
|
|
|
|
|
|
|
namespace OpenAuth.App
|
|
|
|
|
{
|
|
|
|
|
public class LoginApp
|
|
|
|
|
{
|
|
|
|
|
private IUserRepository _repository;
|
2015-12-01 17:30:24 +08:00
|
|
|
|
private IModuleRepository _moduleRepository;
|
|
|
|
|
private IRelevanceRepository _relevanceRepository;
|
2015-12-03 23:39:27 +08:00
|
|
|
|
private IRepository<ModuleElement> _moduleElementRepository;
|
2015-09-22 23:10:00 +08:00
|
|
|
|
|
2015-12-01 17:30:24 +08:00
|
|
|
|
public LoginApp(IUserRepository repository,
|
|
|
|
|
IModuleRepository moduleRepository,
|
2015-12-03 23:39:27 +08:00
|
|
|
|
IRelevanceRepository relevanceRepository,
|
|
|
|
|
IRepository<ModuleElement> moduleElementRepository )
|
2015-09-22 23:10:00 +08:00
|
|
|
|
{
|
|
|
|
|
_repository = repository;
|
2015-12-01 17:30:24 +08:00
|
|
|
|
_moduleRepository = moduleRepository;
|
|
|
|
|
_relevanceRepository = relevanceRepository;
|
2015-12-03 23:39:27 +08:00
|
|
|
|
_moduleElementRepository = moduleElementRepository;
|
2015-09-22 23:10:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-01 17:30:24 +08:00
|
|
|
|
public LoginUserVM Login(string userName, string password)
|
2015-09-22 23:10:00 +08:00
|
|
|
|
{
|
2015-11-30 17:44:42 +08:00
|
|
|
|
var user = _repository.FindSingle(u => u.Account == userName);
|
2015-09-22 23:10:00 +08:00
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22>û<EFBFBD><C3BB>ʺŲ<CABA><C5B2><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
2015-11-30 17:44:42 +08:00
|
|
|
|
user.CheckPassword(password);
|
2015-12-01 17:30:24 +08:00
|
|
|
|
|
|
|
|
|
var loginVM = new LoginUserVM
|
|
|
|
|
{
|
|
|
|
|
User = user
|
|
|
|
|
};
|
|
|
|
|
//<2F>û<EFBFBD><C3BB><EFBFBD>ɫ
|
|
|
|
|
var userRoleIds =
|
|
|
|
|
_relevanceRepository.Find(u => u.FirstId == user.Id && u.Key == "UserRole").Select(u => u.SecondId).ToList();
|
|
|
|
|
|
|
|
|
|
//<2F>û<EFBFBD><C3BB><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>䵽<EFBFBD><E4B5BD>ģ<EFBFBD><C4A3>ID
|
|
|
|
|
var moduleIds =
|
|
|
|
|
_relevanceRepository.Find(
|
|
|
|
|
u =>
|
|
|
|
|
(u.FirstId == user.Id && u.Key == "UserModule") ||
|
|
|
|
|
(u.Key == "RoleModule" && userRoleIds.Contains(u.FirstId))).Select(u =>u.SecondId).ToList();
|
|
|
|
|
//<2F>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ӵ<EFBFBD>е<EFBFBD>ģ<EFBFBD><C4A3>
|
2015-12-03 23:39:27 +08:00
|
|
|
|
loginVM.Modules = _moduleRepository.Find(u => moduleIds.Contains(u.Id)).MapToList<ModuleView>();
|
2015-12-01 17:30:24 +08:00
|
|
|
|
|
|
|
|
|
return loginVM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>½
|
|
|
|
|
/// </summary>
|
|
|
|
|
public LoginUserVM LoginByDev()
|
|
|
|
|
{
|
|
|
|
|
var loginUser = new LoginUserVM
|
|
|
|
|
{
|
|
|
|
|
User = new User
|
|
|
|
|
{
|
|
|
|
|
Name = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD>"
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-12-03 23:39:27 +08:00
|
|
|
|
loginUser.Modules = _moduleRepository.Find(null).MapToList<ModuleView>();
|
2015-12-01 17:30:24 +08:00
|
|
|
|
return loginUser;
|
2015-09-22 23:10:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-25 12:31:01 +08:00
|
|
|
|
}
|