diff --git a/OpenAuth.App/LoginApp.cs b/OpenAuth.App/LoginApp.cs
index 52d89597..0d742f7c 100644
--- a/OpenAuth.App/LoginApp.cs
+++ b/OpenAuth.App/LoginApp.cs
@@ -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("用户帐号不存在");
}
-
user.CheckPassword(password);
- SessionHelper.AddSessionUser(user);
+
+ var loginVM = new LoginUserVM
+ {
+ User = user
+ };
+ //用户角色
+ var userRoleIds =
+ _relevanceRepository.Find(u => u.FirstId == user.Id && u.Key == "UserRole").Select(u => u.SecondId).ToList();
+
+ //用户角色与自己分配到的模块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();
+ //得出最终用户拥有的模块
+ loginVM.Modules = _moduleRepository.Find(u => moduleIds.Contains(u.Id)).ToList();
+
+ return loginVM;
+ }
+
+ ///
+ /// 开发者登陆
+ ///
+ public LoginUserVM LoginByDev()
+ {
+ var loginUser = new LoginUserVM
+ {
+ User = new User
+ {
+ Name = "开发者账号"
+ }
+ };
+ loginUser.Modules = _moduleRepository.Find(null).ToList();
+ return loginUser;
}
}
}
\ No newline at end of file
diff --git a/OpenAuth.App/OpenAuth.App.csproj b/OpenAuth.App/OpenAuth.App.csproj
index 3499c01a..a68b7dfd 100644
--- a/OpenAuth.App/OpenAuth.App.csproj
+++ b/OpenAuth.App/OpenAuth.App.csproj
@@ -49,6 +49,7 @@
+
diff --git a/OpenAuth.App/ViewModel/LoginUserVM.cs b/OpenAuth.App/ViewModel/LoginUserVM.cs
new file mode 100644
index 00000000..424cb516
--- /dev/null
+++ b/OpenAuth.App/ViewModel/LoginUserVM.cs
@@ -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 (c) . All rights reserved.
+//
+// 鐧婚檰瑙嗗浘妯″瀷
+// ***********************************************************************
+
+using System.Collections.Generic;
+using OpenAuth.Domain;
+
+namespace OpenAuth.App.ViewModel
+{
+ ///
+ /// 鐧婚檰鐢ㄦ埛瑙嗗浘妯″瀷
+ ///
+ public class LoginUserVM
+ {
+ public User User { get; set; }
+ ///
+ /// 鐢ㄦ埛鍙互璁块棶鍒扮殑妯″潡锛堝寘鎷墍灞炶鑹蹭笌鑷繁鐨勬墍鏈夋ā鍧楋級
+ ///
+ public List Modules { get; set; }
+
+ ///
+ /// 鐢ㄦ埛鍙互璁块棶鍒扮殑妯″潡涓殑鍏冪礌
+ ///
+ public List ModuleElements { get; set; }
+ }
+
+}
diff --git a/OpenAuth.Domain/Interface/IRelevanceRepository.cs b/OpenAuth.Domain/Interface/IRelevanceRepository.cs
new file mode 100644
index 00000000..026a44b3
--- /dev/null
+++ b/OpenAuth.Domain/Interface/IRelevanceRepository.cs
@@ -0,0 +1,25 @@
+锘// ***********************************************************************
+// Assembly : OpenAuth.Domain
+// Author : Yubao Li
+// Created : 11-30-2015
+//
+// Last Modified By : Yubao Li
+// Last Modified On : 11-30-2015
+// ***********************************************************************
+//
+// Copyright (c) . All rights reserved.
+//
+// 澶氬澶氬叧绯荤粺涓澶勭悊
+// ***********************************************************************
+
+using System.Collections.Generic;
+using System.Linq;
+
+namespace OpenAuth.Domain.Interface
+{
+ public interface IRelevanceRepository : IRepository
+ {
+ void DeleteBy(string key, params int[] firstIds);
+ void AddRelevance( string key, ILookup idMaps);
+ }
+}
diff --git a/OpenAuth.Domain/Module.cs b/OpenAuth.Domain/Module.cs
index 8e38b403..e7d6888e 100644
--- a/OpenAuth.Domain/Module.cs
+++ b/OpenAuth.Domain/Module.cs
@@ -6,12 +6,12 @@ using System.Linq;
namespace OpenAuth.Domain
{
///
- /// 鐢ㄦ埛ID
+ /// 绯荤粺妯″潡
///
public partial class Module
{
///
- /// 鐢ㄦ埛ID
+ /// 妯″潡ID
///
///
public int Id { get; set; }
diff --git a/OpenAuth.Mvc/Controllers/BaseController.cs b/OpenAuth.Mvc/Controllers/BaseController.cs
index 2f906f26..db161dac 100644
--- a/OpenAuth.Mvc/Controllers/BaseController.cs
+++ b/OpenAuth.Mvc/Controllers/BaseController.cs
@@ -14,6 +14,7 @@
using System.Web.Mvc;
using Infrastructure.Helper;
+using OpenAuth.App.ViewModel;
using OpenAuth.Domain;
using OpenAuth.Mvc.Models;
@@ -29,10 +30,10 @@ namespace OpenAuth.Mvc.Controllers
base.OnActionExecuting(filterContext);
//#region 褰揝ession杩囨湡鑷姩璺冲嚭鐧诲綍鐢婚潰
- //if (SessionHelper.GetSessionUser() == null)
- //{
- // Response.Redirect("/Login/Index");
- //}
+ if (SessionHelper.GetSessionUser() == null)
+ {
+ Response.Redirect("/Login/Index");
+ }
//#endregion
}
}
diff --git a/OpenAuth.Mvc/Controllers/LoginController.cs b/OpenAuth.Mvc/Controllers/LoginController.cs
index 406dc91e..19a3177f 100644
--- a/OpenAuth.Mvc/Controllers/LoginController.cs
+++ b/OpenAuth.Mvc/Controllers/LoginController.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
+using Infrastructure.Helper;
using OpenAuth.App;
namespace OpenAuth.Mvc.Controllers
@@ -26,7 +27,7 @@ namespace OpenAuth.Mvc.Controllers
{
try
{
- _app.Login(username, password);
+ SessionHelper.AddSessionUser( _app.Login(username, password));
return RedirectToAction("Index", "Home");
}
@@ -35,5 +36,28 @@ namespace OpenAuth.Mvc.Controllers
return View(e.Message);
}
}
+
+ ///
+ /// 寮鍙戣呯櫥闄
+ ///
+ public ActionResult LoginByDev()
+ {
+ try
+ {
+ SessionHelper.AddSessionUser(_app.LoginByDev());
+ return RedirectToAction("Index", "Home");
+
+ }
+ catch (Exception e)
+ {
+ return View(e.Message);
+ }
+ }
+
+ public ActionResult Logout()
+ {
+ SessionHelper.Clear();
+ return RedirectToAction("Index", "Login");
+ }
}
}
\ No newline at end of file
diff --git a/OpenAuth.Mvc/Models/AccountViewModels.cs b/OpenAuth.Mvc/Models/AccountViewModels.cs
deleted file mode 100644
index a52c031e..00000000
--- a/OpenAuth.Mvc/Models/AccountViewModels.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-锘縰sing System.ComponentModel.DataAnnotations;
-
-namespace OpenAuth.Mvc.Models
-{
- public class LoginViewModel
- {
- [Required]
- [Display(Name = "鐢ㄦ埛鍚")]
- public string UserName { get; set; }
-
- [Required]
- [DataType(DataType.Password)]
- [Display(Name = "瀵嗙爜")]
- public string Password { get; set; }
-
- [Display(Name = "璁颁綇鎴?")]
- public bool RememberMe { get; set; }
- }
-
-}
diff --git a/OpenAuth.Mvc/OpenAuth.Mvc.csproj b/OpenAuth.Mvc/OpenAuth.Mvc.csproj
index fc76ca1d..4f41b87d 100644
--- a/OpenAuth.Mvc/OpenAuth.Mvc.csproj
+++ b/OpenAuth.Mvc/OpenAuth.Mvc.csproj
@@ -134,7 +134,6 @@
Global.asax
-
diff --git a/OpenAuth.Mvc/Views/Home/Index.cshtml b/OpenAuth.Mvc/Views/Home/Index.cshtml
index b13ea8a6..50fe46e5 100644
--- a/OpenAuth.Mvc/Views/Home/Index.cshtml
+++ b/OpenAuth.Mvc/Views/Home/Index.cshtml
@@ -174,7 +174,7 @@
淇敼瀵嗙爜
鎴戠殑璧勬枡
- 娉ㄩ攢鐧婚檰
+ 娉ㄩ攢鐧婚檰
diff --git a/OpenAuth.Mvc/Views/Login/Index.cshtml b/OpenAuth.Mvc/Views/Login/Index.cshtml
index a31fc407..75cc32f1 100644
--- a/OpenAuth.Mvc/Views/Login/Index.cshtml
+++ b/OpenAuth.Mvc/Views/Login/Index.cshtml
@@ -228,7 +228,7 @@
-
+