mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-12-26 22:25:39 +08:00
主页加载菜单按钮
重新修改了登陆逻辑
This commit is contained in:
12
OpenAuth.Domain/Interface/IMenuRepository.cs
Normal file
12
OpenAuth.Domain/Interface/IMenuRepository.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenAuth.Domain.Model;
|
||||
|
||||
namespace OpenAuth.Domain.Interface
|
||||
{
|
||||
public interface IMenuRepository
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using OpenAuth.Domain.Model;
|
||||
|
||||
namespace OpenAuth.Domain.Interface
|
||||
{
|
||||
public interface IUserRepository
|
||||
{
|
||||
User FindBy(string username);
|
||||
User FindByAccount(string account);
|
||||
User FindById(string id);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenAuth.Domain.Utility;
|
||||
|
||||
namespace OpenAuth.Domain.Model
|
||||
{
|
||||
public partial class User
|
||||
public partial class User :EntityBase<string>
|
||||
{
|
||||
public User()
|
||||
{
|
||||
@@ -11,7 +12,6 @@ namespace OpenAuth.Domain.Model
|
||||
this.Roles = new List<Role>();
|
||||
}
|
||||
|
||||
public string UserId { get; set; }
|
||||
public string Account { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string RealName { get; set; }
|
||||
@@ -23,5 +23,10 @@ namespace OpenAuth.Domain.Model
|
||||
|
||||
public Role DefaultRole { get; set; }
|
||||
|
||||
protected override void Validate()
|
||||
{
|
||||
if(string.IsNullOrEmpty(Account))
|
||||
AddBrokenRule(new BusinessRule("Account","<22>û<EFBFBD><C3BB>ʺŲ<CABA><C5B2><EFBFBD>Ϊ<EFBFBD><CEAA>"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Interface\IMenuRepository.cs" />
|
||||
<Compile Include="Interface\IUserRepository.cs" />
|
||||
<Compile Include="Model\Button.cs" />
|
||||
<Compile Include="Model\DataPermission.cs" />
|
||||
@@ -49,6 +50,14 @@
|
||||
<Compile Include="Model\Role.cs" />
|
||||
<Compile Include="Model\User.cs" />
|
||||
<Compile Include="Service\LoginService.cs" />
|
||||
<Compile Include="Service\MenuService.cs" />
|
||||
<Compile Include="Utility\BusinessRule.cs" />
|
||||
<Compile Include="Utility\EntityBase.cs" />
|
||||
<Compile Include="Utility\IAggregateRoot.cs" />
|
||||
<Compile Include="Utility\IReadOnlyRepository.cs" />
|
||||
<Compile Include="Utility\IRepository.cs" />
|
||||
<Compile Include="Utility\ValueObjectBase.cs" />
|
||||
<Compile Include="Utility\ValueObjectIsInvalidException.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -1,26 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenAuth.Domain.Interface;
|
||||
using OpenAuth.Domain.Model;
|
||||
|
||||
namespace OpenAuth.Domain.Service
|
||||
{
|
||||
public class LoginService
|
||||
{
|
||||
private IUserRepository _userRepository;
|
||||
|
||||
public LoginService(IUserRepository repository)
|
||||
{
|
||||
_userRepository = repository;
|
||||
}
|
||||
|
||||
public User Login(string username, string password)
|
||||
{
|
||||
return _userRepository.FindBy(username);
|
||||
|
||||
var user = _userRepository.FindByAccount(username);
|
||||
if (user == null)
|
||||
{
|
||||
throw new Exception("用户名不存在");
|
||||
}
|
||||
if (!user.Password.Equals(password))
|
||||
{
|
||||
throw new Exception("密码错误");
|
||||
}
|
||||
if (!user.Enabled)
|
||||
{
|
||||
throw new Exception("该用户被禁用");
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
34
OpenAuth.Domain/Service/MenuService.cs
Normal file
34
OpenAuth.Domain/Service/MenuService.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenAuth.Domain.Interface;
|
||||
using OpenAuth.Domain.Model;
|
||||
|
||||
namespace OpenAuth.Domain.Service
|
||||
{
|
||||
public class MenuService
|
||||
{
|
||||
private IUserRepository _userRepository;
|
||||
|
||||
public MenuService(IUserRepository repository)
|
||||
{
|
||||
_userRepository = repository;
|
||||
}
|
||||
|
||||
public List<Menu> GetMenuFor(string userId)
|
||||
{
|
||||
var menus = new List<Menu>();
|
||||
var user = _userRepository.FindById(userId);
|
||||
if (user != null)
|
||||
{
|
||||
foreach (var role in user.Roles)
|
||||
{
|
||||
foreach (var menu in role.RoleMenus.Where(menu => !menus.Exists(e =>e.MenuId == menu.MenuId)))
|
||||
{
|
||||
menus.Add(menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
return menus;
|
||||
}
|
||||
}
|
||||
}
|
||||
27
OpenAuth.Domain/Utility/BusinessRule.cs
Normal file
27
OpenAuth.Domain/Utility/BusinessRule.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace OpenAuth.Domain.Utility
|
||||
{
|
||||
public class BusinessRule
|
||||
{
|
||||
private string _property;
|
||||
private string _rule;
|
||||
|
||||
public BusinessRule(string property, string rule)
|
||||
{
|
||||
this._property = property;
|
||||
this._rule = rule;
|
||||
}
|
||||
|
||||
public string Property
|
||||
{
|
||||
get { return _property; }
|
||||
set { _property = value; }
|
||||
}
|
||||
|
||||
public string Rule
|
||||
{
|
||||
get { return _rule; }
|
||||
set { _rule = value; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
65
OpenAuth.Domain/Utility/EntityBase.cs
Normal file
65
OpenAuth.Domain/Utility/EntityBase.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenAuth.Domain.Utility
|
||||
{
|
||||
public abstract class EntityBase<TId>
|
||||
{
|
||||
private List<BusinessRule> _brokenRules = new List<BusinessRule>();
|
||||
|
||||
public TId Id { get; set; }
|
||||
|
||||
protected abstract void Validate();
|
||||
|
||||
public IEnumerable<BusinessRule> GetBrokenRules()
|
||||
{
|
||||
_brokenRules.Clear();
|
||||
Validate();
|
||||
return _brokenRules;
|
||||
}
|
||||
|
||||
protected void AddBrokenRule(BusinessRule businessRule)
|
||||
{
|
||||
_brokenRules.Add(businessRule);
|
||||
}
|
||||
|
||||
public override bool Equals(object entity)
|
||||
{
|
||||
return entity != null
|
||||
&& entity is EntityBase<TId>
|
||||
&& this == (EntityBase<TId>)entity;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.Id.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(EntityBase<TId> entity1,
|
||||
EntityBase<TId> entity2)
|
||||
{
|
||||
if ((object)entity1 == null && (object)entity2 == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((object)entity1 == null || (object)entity2 == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entity1.Id.ToString() == entity2.Id.ToString())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool operator !=(EntityBase<TId> entity1,
|
||||
EntityBase<TId> entity2)
|
||||
{
|
||||
return (!(entity1 == entity2));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
7
OpenAuth.Domain/Utility/IAggregateRoot.cs
Normal file
7
OpenAuth.Domain/Utility/IAggregateRoot.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace OpenAuth.Domain.Utility
|
||||
{
|
||||
public interface IAggregateRoot
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
11
OpenAuth.Domain/Utility/IReadOnlyRepository.cs
Normal file
11
OpenAuth.Domain/Utility/IReadOnlyRepository.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenAuth.Domain.Utility
|
||||
{
|
||||
public interface IReadOnlyRepository<T, TId> where T : IAggregateRoot
|
||||
{
|
||||
T FindBy(TId id);
|
||||
IEnumerable<T> FindAll();
|
||||
|
||||
}
|
||||
}
|
||||
10
OpenAuth.Domain/Utility/IRepository.cs
Normal file
10
OpenAuth.Domain/Utility/IRepository.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace OpenAuth.Domain.Utility
|
||||
{
|
||||
public interface IRepository<T, TId> : IReadOnlyRepository<T, TId> where T : IAggregateRoot
|
||||
{
|
||||
void Save(T entity);
|
||||
void Add(T entity);
|
||||
void Remove(T entity);
|
||||
}
|
||||
}
|
||||
|
||||
36
OpenAuth.Domain/Utility/ValueObjectBase.cs
Normal file
36
OpenAuth.Domain/Utility/ValueObjectBase.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenAuth.Domain.Utility
|
||||
{
|
||||
public abstract class ValueObjectBase
|
||||
{
|
||||
private List<BusinessRule> _brokenRules = new List<BusinessRule>();
|
||||
|
||||
public ValueObjectBase()
|
||||
{
|
||||
}
|
||||
|
||||
protected abstract void Validate();
|
||||
|
||||
public void ThrowExceptionIfInvalid()
|
||||
{
|
||||
_brokenRules.Clear();
|
||||
Validate();
|
||||
if (_brokenRules.Count() > 0)
|
||||
{
|
||||
StringBuilder issues = new StringBuilder();
|
||||
foreach (BusinessRule businessRule in _brokenRules)
|
||||
issues.AppendLine(businessRule.Rule);
|
||||
|
||||
throw new ValueObjectIsInvalidException(issues.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void AddBrokenRule(BusinessRule businessRule)
|
||||
{
|
||||
_brokenRules.Add(businessRule);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
OpenAuth.Domain/Utility/ValueObjectIsInvalidException.cs
Normal file
13
OpenAuth.Domain/Utility/ValueObjectIsInvalidException.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace OpenAuth.Domain.Utility
|
||||
{
|
||||
public class ValueObjectIsInvalidException : Exception
|
||||
{
|
||||
public ValueObjectIsInvalidException(string message)
|
||||
: base(message)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user