mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-11-09 02:44:44 +08:00
add login service
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Data.Entity.ModelConfiguration;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Model;
|
||||
|
||||
namespace OpenAuth.Infrastructure.Mapping
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Data.Entity.ModelConfiguration;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Model;
|
||||
|
||||
namespace OpenAuth.Infrastructure.Mapping
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Data.Entity.ModelConfiguration;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Model;
|
||||
|
||||
namespace OpenAuth.Infrastructure.Mapping
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Data.Entity.ModelConfiguration;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Model;
|
||||
|
||||
namespace OpenAuth.Infrastructure.Mapping
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Data.Entity.ModelConfiguration;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Model;
|
||||
|
||||
namespace OpenAuth.Infrastructure.Mapping
|
||||
{
|
||||
@@ -30,6 +31,16 @@ namespace OpenAuth.Infrastructure.Mapping
|
||||
this.Property(t => t.DepartmentId)
|
||||
.HasMaxLength(50);
|
||||
|
||||
this.HasMany(d => d.Users)
|
||||
.WithMany(u => u.Roles)
|
||||
.Map(
|
||||
m =>
|
||||
{
|
||||
m.MapLeftKey("RoleId");
|
||||
m.MapRightKey("UserId");
|
||||
m.ToTable("UserRole");
|
||||
});
|
||||
|
||||
|
||||
// Table & Column Mappings
|
||||
this.ToTable("Role");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Data.Entity.ModelConfiguration;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Model;
|
||||
|
||||
namespace OpenAuth.Infrastructure.Mapping
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Data.Entity.ModelConfiguration;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Model;
|
||||
|
||||
namespace OpenAuth.Infrastructure.Mapping
|
||||
{
|
||||
@@ -36,6 +37,15 @@ namespace OpenAuth.Infrastructure.Mapping
|
||||
m.ToTable("UserDepartment");
|
||||
});
|
||||
|
||||
this.HasMany(u => u.Roles)
|
||||
.WithMany(r => r.Users)
|
||||
.Map(m =>
|
||||
{
|
||||
m.MapLeftKey("UserId");
|
||||
m.MapRightKey("RoleId");
|
||||
m.ToTable("UserRole");
|
||||
});
|
||||
|
||||
// Table & Column Mappings
|
||||
this.ToTable("User");
|
||||
this.Property(t => t.UserId).HasColumnName("UserId");
|
||||
|
||||
@@ -55,6 +55,8 @@
|
||||
<Compile Include="Mapping\UserMap.cs" />
|
||||
<Compile Include="OpenAuthDBContext.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Repository\BaseRepository.cs" />
|
||||
<Compile Include="Repository\UserRepository.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenAuth.App\OpenAuth.App.csproj">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Data.Entity;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Model;
|
||||
using OpenAuth.Infrastructure.Mapping;
|
||||
|
||||
namespace OpenAuth.Infrastructure
|
||||
|
||||
12
OpenAuth.Infrastructure/Repository/BaseRepository.cs
Normal file
12
OpenAuth.Infrastructure/Repository/BaseRepository.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenAuth.Infrastructure.Repository
|
||||
{
|
||||
public class BaseRepository
|
||||
{
|
||||
protected OpenAuthDBContext _Context = new OpenAuthDBContext();
|
||||
}
|
||||
}
|
||||
25
OpenAuth.Infrastructure/Repository/UserRepository.cs
Normal file
25
OpenAuth.Infrastructure/Repository/UserRepository.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenAuth.Domain.Interface;
|
||||
using OpenAuth.Domain.Model;
|
||||
|
||||
namespace OpenAuth.Infrastructure.Repository
|
||||
{
|
||||
public class UserRepository :BaseRepository, IUserRepository
|
||||
{
|
||||
public User FindBy(string username)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _Context.Users.First(e => e.Account == username);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user