mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 23:13:40 +08:00
check js bugs
This commit is contained in:
parent
e5a3f4e4f6
commit
0c8399cbc4
@ -107,17 +107,25 @@ namespace OpenAuth.App
|
|||||||
public void AddOrUpdate(UserView view)
|
public void AddOrUpdate(UserView view)
|
||||||
{
|
{
|
||||||
User user = view;
|
User user = view;
|
||||||
user.CreateTime = DateTime.Now;
|
|
||||||
if (user.Id == 0)
|
if (user.Id == 0)
|
||||||
{
|
{
|
||||||
|
user.CreateTime = DateTime.Now;
|
||||||
user.Password = user.Account; //初始密码与账号相同
|
user.Password = user.Account; //初始密码与账号相同
|
||||||
_repository.Add(user);
|
_repository.Add(user);
|
||||||
view.Id = user.Id; //要把保存后的ID存入view
|
view.Id = user.Id; //要把保存后的ID存入view
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_repository.Update(u=>u.Id, user);
|
_repository.Update(u => u.Id == view.Id, u => new User
|
||||||
|
{
|
||||||
|
Account = user.Account,
|
||||||
|
BizCode = user.BizCode,
|
||||||
|
CreateId = user.CreateId,
|
||||||
|
Name = user.Name,
|
||||||
|
Sex = user.Sex,
|
||||||
|
Status = user.Status,
|
||||||
|
Type = user.Type
|
||||||
|
});
|
||||||
}
|
}
|
||||||
int[] orgIds = view.OrganizationIds.Split(',').Select(id => int.Parse(id)).ToArray();
|
int[] orgIds = view.OrganizationIds.Split(',').Select(id => int.Parse(id)).ToArray();
|
||||||
|
|
||||||
|
@ -22,12 +22,7 @@ namespace OpenAuth.Domain.Service
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class AuthoriseService
|
public class AuthoriseService
|
||||||
{
|
{
|
||||||
private IUserRepository _repository;
|
private IUnitWork _unitWork;
|
||||||
private IModuleRepository _moduleRepository;
|
|
||||||
private IRelevanceRepository _relevanceRepository;
|
|
||||||
private IRepository<ModuleElement> _moduleElementRepository;
|
|
||||||
private IResourceRepository _resourceRepository;
|
|
||||||
private IOrgRepository _orgRepository;
|
|
||||||
|
|
||||||
private User _user;
|
private User _user;
|
||||||
private List<Module> _modules; //用户可访问的模块
|
private List<Module> _modules; //用户可访问的模块
|
||||||
@ -35,19 +30,9 @@ namespace OpenAuth.Domain.Service
|
|||||||
private List<Resource> _resources; //用户可访问的资源
|
private List<Resource> _resources; //用户可访问的资源
|
||||||
private List<Org> _orgs; //用户可访问的机构
|
private List<Org> _orgs; //用户可访问的机构
|
||||||
|
|
||||||
public AuthoriseService(IUserRepository repository,
|
public AuthoriseService(IUnitWork unitWork)
|
||||||
IModuleRepository moduleRepository,
|
|
||||||
IRelevanceRepository relevanceRepository,
|
|
||||||
IRepository<ModuleElement> moduleElementRepository,
|
|
||||||
IResourceRepository resourceRepository,
|
|
||||||
IOrgRepository orgRepository)
|
|
||||||
{
|
{
|
||||||
_repository = repository;
|
_unitWork = unitWork;
|
||||||
_moduleRepository = moduleRepository;
|
|
||||||
_relevanceRepository = relevanceRepository;
|
|
||||||
_moduleElementRepository = moduleElementRepository;
|
|
||||||
_resourceRepository = resourceRepository;
|
|
||||||
_orgRepository = orgRepository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Module> Modules
|
public List<Module> Modules
|
||||||
@ -77,7 +62,7 @@ namespace OpenAuth.Domain.Service
|
|||||||
|
|
||||||
public void Check(string userName, string password)
|
public void Check(string userName, string password)
|
||||||
{
|
{
|
||||||
var _user = _repository.FindSingle(u => u.Account == userName);
|
var _user = _unitWork.FindSingle<User>(u => u.Account == userName);
|
||||||
if (_user == null)
|
if (_user == null)
|
||||||
{
|
{
|
||||||
throw new Exception("用户帐号不存在");
|
throw new Exception("用户帐号不存在");
|
||||||
@ -100,48 +85,48 @@ namespace OpenAuth.Domain.Service
|
|||||||
{
|
{
|
||||||
if (name == "System")
|
if (name == "System")
|
||||||
{
|
{
|
||||||
_modules = _moduleRepository.Find(null).ToList();
|
_modules = _unitWork.Find<Module>(null).ToList();
|
||||||
_moduleElements = _moduleElementRepository.Find(null).ToList();
|
_moduleElements = _unitWork.Find<ModuleElement>(null).ToList();
|
||||||
|
|
||||||
_resources = _resourceRepository.Find(null).OrderBy(u => u.SortNo).ToList();
|
_resources = _unitWork.Find<Resource>(null).OrderBy(u => u.SortNo).ToList();
|
||||||
|
|
||||||
_orgs = _orgRepository.Find(null).OrderBy(u => u.SortNo).ToList();
|
_orgs = _unitWork.Find<Org>(null).OrderBy(u => u.SortNo).ToList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_user = _repository.FindSingle(u => u.Account == name);
|
_user = _unitWork.FindSingle<User>(u => u.Account == name);
|
||||||
//用户角色
|
//用户角色
|
||||||
var userRoleIds = _relevanceRepository.Find(u => u.FirstId == _user.Id && u.Key == "UserRole").Select(u => u.SecondId).ToList();
|
var userRoleIds = _unitWork.Find<Relevance>(u => u.FirstId == _user.Id && u.Key == "UserRole").Select(u => u.SecondId).ToList();
|
||||||
|
|
||||||
//用户角色与自己分配到的模块ID
|
//用户角色与自己分配到的模块ID
|
||||||
var moduleIds = _relevanceRepository.Find(
|
var moduleIds = _unitWork.Find<Relevance>(
|
||||||
u =>
|
u =>
|
||||||
(u.FirstId == _user.Id && u.Key == "UserModule") ||
|
(u.FirstId == _user.Id && u.Key == "UserModule") ||
|
||||||
(u.Key == "RoleModule" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList();
|
(u.Key == "RoleModule" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||||
|
//得出最终用户拥有的模块
|
||||||
|
_modules = _unitWork.Find<Module>(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo).ToList();
|
||||||
|
|
||||||
//用户角色与自己分配到的菜单ID
|
//用户角色与自己分配到的菜单ID
|
||||||
var elementIds = _relevanceRepository.Find(
|
var elementIds = _unitWork.Find<Relevance>(
|
||||||
u =>
|
u =>
|
||||||
(u.FirstId == _user.Id && u.Key == "UserElement") ||
|
(u.FirstId == _user.Id && u.Key == "UserElement") ||
|
||||||
(u.Key == "RoleElement" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList();
|
(u.Key == "RoleElement" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||||
//得出最终用户拥有的模块
|
|
||||||
_modules = _moduleRepository.Find(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo).ToList();
|
|
||||||
|
|
||||||
//模块菜单权限
|
//模块菜单权限
|
||||||
_moduleElements = _moduleElementRepository.Find(u => elementIds.Contains(u.Id)).ToList();
|
_moduleElements = _unitWork.Find<ModuleElement>(u => elementIds.Contains(u.Id)).ToList();
|
||||||
|
|
||||||
//用户角色与自己分配到的资源ID
|
//用户角色与自己分配到的资源ID
|
||||||
var resourceIds = _relevanceRepository.Find(
|
var resourceIds = _unitWork.Find<Relevance>(
|
||||||
u =>
|
u =>
|
||||||
(u.FirstId == _user.Id && u.Key == "UserResource") ||
|
(u.FirstId == _user.Id && u.Key == "UserResource") ||
|
||||||
(u.Key == "RoleResource" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList();
|
(u.Key == "RoleResource" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||||
_resources = _resourceRepository.Find(u => resourceIds.Contains(u.Id)).ToList();
|
_resources = _unitWork.Find<Resource>(u => resourceIds.Contains(u.Id)).ToList();
|
||||||
|
|
||||||
//用户角色与自己分配到的机构ID
|
//用户角色与自己分配到的机构ID
|
||||||
var orgids = _relevanceRepository.Find(
|
var orgids = _unitWork.Find<Relevance>(
|
||||||
u =>
|
u =>
|
||||||
(u.FirstId == _user.Id && u.Key == "UserAccessedOrg") ||
|
(u.FirstId == _user.Id && u.Key == "UserAccessedOrg") ||
|
||||||
(u.Key == "RoleAccessedOrg" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList();
|
(u.Key == "RoleAccessedOrg" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||||
_orgs = _orgRepository.Find(u => orgids.Contains(u.Id)).ToList();
|
_orgs = _unitWork.Find<Org>(u => orgids.Contains(u.Id)).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ $(document).ready(function () {
|
|||||||
firstId: $('#firstId').val(),
|
firstId: $('#firstId').val(),
|
||||||
secIds: ids
|
secIds: ids
|
||||||
}, function (json) {
|
}, function (json) {
|
||||||
|
json = $.parseJSON(json);
|
||||||
if (json.statusCode != "200") {
|
if (json.statusCode != "200") {
|
||||||
json = $.parseJSON(json);
|
json = $.parseJSON(json);
|
||||||
$(this).alertmsg('warn', json.message);
|
$(this).alertmsg('warn', json.message);
|
||||||
@ -40,6 +41,7 @@ $(document).ready(function () {
|
|||||||
firstId: $('#firstId').val(),
|
firstId: $('#firstId').val(),
|
||||||
secIds: ids
|
secIds: ids
|
||||||
}, function (json) {
|
}, function (json) {
|
||||||
|
json = $.parseJSON(json);
|
||||||
if (json.statusCode != "200") {
|
if (json.statusCode != "200") {
|
||||||
json = $.parseJSON(json);
|
json = $.parseJSON(json);
|
||||||
$(this).alertmsg('warn', json.message);
|
$(this).alertmsg('warn', json.message);
|
||||||
|
@ -23,6 +23,7 @@ $(document).ready(function () {
|
|||||||
firstId: $('#firstId').val(),
|
firstId: $('#firstId').val(),
|
||||||
secIds: ids
|
secIds: ids
|
||||||
}, function (json) {
|
}, function (json) {
|
||||||
|
json = $.parseJSON(json);
|
||||||
if (json.statusCode != "200") {
|
if (json.statusCode != "200") {
|
||||||
json = $.parseJSON(json);
|
json = $.parseJSON(json);
|
||||||
$(this).alertmsg('warn', json.message);
|
$(this).alertmsg('warn', json.message);
|
||||||
@ -40,6 +41,7 @@ $(document).ready(function () {
|
|||||||
firstId: $('#firstId').val(),
|
firstId: $('#firstId').val(),
|
||||||
secIds: ids
|
secIds: ids
|
||||||
}, function (json) {
|
}, function (json) {
|
||||||
|
json = $.parseJSON(json);
|
||||||
if (json.statusCode != "200") {
|
if (json.statusCode != "200") {
|
||||||
json = $.parseJSON(json);
|
json = $.parseJSON(json);
|
||||||
$(this).alertmsg('warn', json.message);
|
$(this).alertmsg('warn', json.message);
|
||||||
|
@ -23,6 +23,7 @@ $(document).ready(function () {
|
|||||||
firstId: $('#firstId').val(),
|
firstId: $('#firstId').val(),
|
||||||
secIds: ids
|
secIds: ids
|
||||||
}, function (json) {
|
}, function (json) {
|
||||||
|
json = $.parseJSON(json);
|
||||||
if (json.statusCode != "200") {
|
if (json.statusCode != "200") {
|
||||||
json = $.parseJSON(json);
|
json = $.parseJSON(json);
|
||||||
$(this).alertmsg('warn', json.message);
|
$(this).alertmsg('warn', json.message);
|
||||||
@ -40,6 +41,7 @@ $(document).ready(function () {
|
|||||||
firstId: $('#firstId').val(),
|
firstId: $('#firstId').val(),
|
||||||
secIds: ids
|
secIds: ids
|
||||||
}, function (json) {
|
}, function (json) {
|
||||||
|
json = $.parseJSON(json);
|
||||||
if (json.statusCode != "200") {
|
if (json.statusCode != "200") {
|
||||||
json = $.parseJSON(json);
|
json = $.parseJSON(json);
|
||||||
$(this).alertmsg('warn', json.message);
|
$(this).alertmsg('warn', json.message);
|
||||||
|
@ -189,7 +189,6 @@ var editDlg = function () {
|
|||||||
show();
|
show();
|
||||||
$('#Id').val(ret.Id);
|
$('#Id').val(ret.Id);
|
||||||
$('#Account').val(ret.Account);
|
$('#Account').val(ret.Account);
|
||||||
$('#Password').val(ret.Password);
|
|
||||||
$('#Name').val(ret.Name);
|
$('#Name').val(ret.Name);
|
||||||
$('#Sex').selectpicker('val', ret.Sex);
|
$('#Sex').selectpicker('val', ret.Sex);
|
||||||
$('#Status').selectpicker('val', ret.Status);
|
$('#Status').selectpicker('val', ret.Status);
|
||||||
@ -208,7 +207,6 @@ var editDlg = function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
list.reload();
|
list.reload();
|
||||||
ztree.reload();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -234,7 +234,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="bottom">
|
<div class="bottom">
|
||||||
可以用admin(密码:admin) /test(密码:test) 查看不同账号登陆情况<br>
|
可以用admin(密码:admin) /test(密码:test) 查看不同账号登陆情况<br>
|
||||||
Copyright © 2015 <a href="/Login/LoginByDev">基于精典DDD的权限管理 - 点击以开发者账号登录</a>
|
Copyright © 2015 <a href="/Login/LoginByDev">基于经典DDD的权限管理 - 点击以开发者账号登录</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<!--已经选中的列表-->
|
<!--已经选中的列表-->
|
||||||
<fieldset style="height: auto;margin-left: 310px; width: 280px">
|
<fieldset style="height: auto;margin-left: 300px; width: 280px">
|
||||||
<legend>已分配的模块</legend>
|
<legend>已分配的模块</legend>
|
||||||
<ul id="selected" class="ztree"></ul>
|
<ul id="selected" class="ztree"></ul>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<!--已经选中的列表-->
|
<!--已经选中的列表-->
|
||||||
<fieldset style="height: auto;margin-left: 310px; width: 280px">
|
<fieldset style="height: auto;margin-left: 300px; width: 280px">
|
||||||
<legend>已分配的机构</legend>
|
<legend>已分配的机构</legend>
|
||||||
<ul id="selected" class="ztree"></ul>
|
<ul id="selected" class="ztree"></ul>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
<table class="table table-condensed table-hover">
|
<table class="table table-condensed table-hover">
|
||||||
<tbody>
|
<tbody>
|
||||||
<input type="text" id="Id" name="Id" value="" class="hidden"/>
|
<input type="text" id="Id" name="Id" value="" class="hidden"/>
|
||||||
<input type="text" id="Password" name="Password" class="hidden" />
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<label for="Account" class="control-label x120">账号:</label>
|
<label for="Account" class="control-label x120">账号:</label>
|
||||||
|
@ -78,6 +78,7 @@
|
|||||||
<Compile Include="TestUnitWork.cs" />
|
<Compile Include="TestUnitWork.cs" />
|
||||||
<Compile Include="TestUserApp.cs" />
|
<Compile Include="TestUserApp.cs" />
|
||||||
<Compile Include="TestOrgApp.cs" />
|
<Compile Include="TestOrgApp.cs" />
|
||||||
|
<Compile Include="TestAuthen.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config">
|
<None Include="App.config">
|
||||||
|
23
OpenAuth.UnitTest/TestAuthen.cs
Normal file
23
OpenAuth.UnitTest/TestAuthen.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using OpenAuth.Domain.Service;
|
||||||
|
using OpenAuth.Repository;
|
||||||
|
|
||||||
|
namespace OpenAuth.UnitTest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 测试用户授权服务
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class TestAuthen
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void TestMethod1()
|
||||||
|
{
|
||||||
|
AuthoriseService _service = new AuthoriseService(new UnitWork() );
|
||||||
|
_service.GetUserAccessed("test");
|
||||||
|
|
||||||
|
var orgs = _service.Orgs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -99,5 +99,11 @@ namespace OpenAuth.UnitTest
|
|||||||
};
|
};
|
||||||
_app.AddOrUpdate(org1);
|
_app.AddOrUpdate(org1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestLoadByUser()
|
||||||
|
{
|
||||||
|
var user = _app.LoadForUser(5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user