mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2026-06-27 06:43:08 +08:00
完成登录处理
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
using OpenAuth.Domain.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Helper;
|
||||
using OpenAuth.App.ViewModel;
|
||||
using OpenAuth.Domain;
|
||||
|
||||
namespace OpenAuth.App
|
||||
@@ -8,22 +12,61 @@ namespace OpenAuth.App
|
||||
public class LoginApp
|
||||
{
|
||||
private IUserRepository _repository;
|
||||
private IModuleRepository _moduleRepository;
|
||||
private IRelevanceRepository _relevanceRepository;
|
||||
|
||||
public LoginApp(IUserRepository repository)
|
||||
public LoginApp(IUserRepository repository,
|
||||
IModuleRepository moduleRepository,
|
||||
IRelevanceRepository relevanceRepository)
|
||||
{
|
||||
_repository = repository;
|
||||
_moduleRepository = moduleRepository;
|
||||
_relevanceRepository = relevanceRepository;
|
||||
}
|
||||
|
||||
public void Login(string userName, string password)
|
||||
public LoginUserVM Login(string userName, string password)
|
||||
{
|
||||
var user = _repository.FindSingle(u => u.Account == userName);
|
||||
if (user == null)
|
||||
{
|
||||
throw new Exception("<22>û<EFBFBD><C3BB>ʺŲ<CABA><C5B2><EFBFBD><EFBFBD><EFBFBD>");
|
||||
}
|
||||
|
||||
user.CheckPassword(password);
|
||||
SessionHelper.AddSessionUser(user);
|
||||
|
||||
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>
|
||||
loginVM.Modules = _moduleRepository.Find(u => moduleIds.Contains(u.Id)).ToList();
|
||||
|
||||
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>"
|
||||
}
|
||||
};
|
||||
loginUser.Modules = _moduleRepository.Find(null).ToList();
|
||||
return loginUser;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@
|
||||
<Compile Include="UserManagerApp.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="OrgManagerApp.cs" />
|
||||
<Compile Include="ViewModel\LoginUserVM.cs" />
|
||||
<Compile Include="ViewModel\ModuleView.cs" />
|
||||
<Compile Include="ViewModel\RoleVM.cs" />
|
||||
<Compile Include="ViewModel\UserView.cs" />
|
||||
|
||||
37
OpenAuth.App/ViewModel/LoginUserVM.cs
Normal file
37
OpenAuth.App/ViewModel/LoginUserVM.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.App
|
||||
// Author : Yubao Li
|
||||
// Created : 12-01-2015
|
||||
//
|
||||
// Last Modified By : Yubao Li
|
||||
// Last Modified On : 12-01-2015
|
||||
// ***********************************************************************
|
||||
// <copyright file="LoginUserVM.cs" company="">
|
||||
// Copyright (c) . All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>登陆视图模型</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenAuth.Domain;
|
||||
|
||||
namespace OpenAuth.App.ViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 登陆用户视图模型
|
||||
/// </summary>
|
||||
public class LoginUserVM
|
||||
{
|
||||
public User User { get; set; }
|
||||
/// <summary>
|
||||
/// 用户可以访问到的模块(包括所属角色与自己的所有模块)
|
||||
/// </summary>
|
||||
public List<Module> Modules { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户可以访问到的模块中的元素
|
||||
/// </summary>
|
||||
public List<ModuleElement> ModuleElements { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user