mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-17 19:37:45 +08:00
complete login
This commit is contained in:
parent
ae2d70a028
commit
8e4472b86a
@ -8,6 +8,7 @@ namespace OpenAuth.Domain.Model
|
|||||||
public Button()
|
public Button()
|
||||||
{
|
{
|
||||||
this.RoleMenuButtons = new List<RoleMenuButton>();
|
this.RoleMenuButtons = new List<RoleMenuButton>();
|
||||||
|
this.Menus = new List<Menu>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ButtonId { get; set; }
|
public string ButtonId { get; set; }
|
||||||
@ -20,5 +21,6 @@ namespace OpenAuth.Domain.Model
|
|||||||
public bool Enabled { get; set; }
|
public bool Enabled { get; set; }
|
||||||
public Nullable<int> SortCode { get; set; }
|
public Nullable<int> SortCode { get; set; }
|
||||||
public virtual ICollection<RoleMenuButton> RoleMenuButtons { get; set; }
|
public virtual ICollection<RoleMenuButton> RoleMenuButtons { get; set; }
|
||||||
|
public virtual ICollection<Menu> Menus { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ namespace OpenAuth.Domain.Model
|
|||||||
public Menu()
|
public Menu()
|
||||||
{
|
{
|
||||||
this.Buttons = new List<Button>();
|
this.Buttons = new List<Button>();
|
||||||
|
this.Roles = new List<Role>();
|
||||||
this.RoleMenuButtons = new List<RoleMenuButton>();
|
this.RoleMenuButtons = new List<RoleMenuButton>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ namespace OpenAuth.Domain.Model
|
|||||||
public bool Enabled { get; set; }
|
public bool Enabled { get; set; }
|
||||||
public Nullable<int> SortCode { get; set; }
|
public Nullable<int> SortCode { get; set; }
|
||||||
public virtual ICollection<Button> Buttons { get; set; }
|
public virtual ICollection<Button> Buttons { get; set; }
|
||||||
|
public virtual ICollection<Role> Roles { get; set; }
|
||||||
public virtual ICollection<RoleMenuButton> RoleMenuButtons { get; set; }
|
public virtual ICollection<RoleMenuButton> RoleMenuButtons { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,9 +44,9 @@
|
|||||||
<Compile Include="Model\DataPermission.cs" />
|
<Compile Include="Model\DataPermission.cs" />
|
||||||
<Compile Include="Model\Department.cs" />
|
<Compile Include="Model\Department.cs" />
|
||||||
<Compile Include="Model\Menu.cs" />
|
<Compile Include="Model\Menu.cs" />
|
||||||
|
<Compile Include="Model\RoleMenuButton.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Model\Role.cs" />
|
<Compile Include="Model\Role.cs" />
|
||||||
<Compile Include="Model\RoleMenuButton.cs" />
|
|
||||||
<Compile Include="Model\User.cs" />
|
<Compile Include="Model\User.cs" />
|
||||||
<Compile Include="Service\LoginService.cs" />
|
<Compile Include="Service\LoginService.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -37,6 +37,25 @@ namespace OpenAuth.Infrastructure.Mapping
|
|||||||
this.Property(t => t.Target)
|
this.Property(t => t.Target)
|
||||||
.HasMaxLength(50);
|
.HasMaxLength(50);
|
||||||
|
|
||||||
|
//菜单包含的按钮
|
||||||
|
this.HasMany(t => t.Buttons)
|
||||||
|
.WithMany(b => b.Menus)
|
||||||
|
.Map(m =>
|
||||||
|
{
|
||||||
|
m.MapLeftKey("MenuId");
|
||||||
|
m.MapRightKey("ButtonId");
|
||||||
|
m.ToTable("MenuButton");
|
||||||
|
});
|
||||||
|
//TODO:菜单包含的角色(如果不加这句,EF查询时会自动添加Role_RoleId列
|
||||||
|
this.HasMany(t => t.Roles)
|
||||||
|
.WithMany(b => b.RoleMenus)
|
||||||
|
.Map(m =>
|
||||||
|
{
|
||||||
|
m.MapLeftKey("MenuId");
|
||||||
|
m.MapRightKey("RoleId");
|
||||||
|
m.ToTable("RoleMenu");
|
||||||
|
});
|
||||||
|
|
||||||
// Table & Column Mappings
|
// Table & Column Mappings
|
||||||
this.ToTable("Menu");
|
this.ToTable("Menu");
|
||||||
this.Property(t => t.MenuId).HasColumnName("MenuId");
|
this.Property(t => t.MenuId).HasColumnName("MenuId");
|
||||||
|
@ -31,6 +31,7 @@ namespace OpenAuth.Infrastructure.Mapping
|
|||||||
this.Property(t => t.DepartmentId)
|
this.Property(t => t.DepartmentId)
|
||||||
.HasMaxLength(50);
|
.HasMaxLength(50);
|
||||||
|
|
||||||
|
//角色包含的用户;
|
||||||
this.HasMany(d => d.Users)
|
this.HasMany(d => d.Users)
|
||||||
.WithMany(u => u.Roles)
|
.WithMany(u => u.Roles)
|
||||||
.Map(
|
.Map(
|
||||||
@ -41,6 +42,16 @@ namespace OpenAuth.Infrastructure.Mapping
|
|||||||
m.ToTable("UserRole");
|
m.ToTable("UserRole");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//角色包含的菜单
|
||||||
|
this.HasMany(m => m.RoleMenus)
|
||||||
|
.WithMany(r => r.Roles)
|
||||||
|
.Map(m =>
|
||||||
|
{
|
||||||
|
m.MapLeftKey("RoleId");
|
||||||
|
m.MapRightKey("MenuId");
|
||||||
|
m.ToTable("RoleMenu");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// Table & Column Mappings
|
// Table & Column Mappings
|
||||||
this.ToTable("Role");
|
this.ToTable("Role");
|
||||||
|
@ -37,8 +37,10 @@
|
|||||||
<HintPath>..\packages\EntityFramework.6.1.3\lib\net40\EntityFramework.SqlServer.dll</HintPath>
|
<HintPath>..\packages\EntityFramework.6.1.3\lib\net40\EntityFramework.SqlServer.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Activities" />
|
||||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Transactions" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
@ -22,7 +22,7 @@ namespace OpenAuth.Infrastructure
|
|||||||
public DbSet<Department> Departments { get; set; }
|
public DbSet<Department> Departments { get; set; }
|
||||||
public DbSet<Menu> Menus { get; set; }
|
public DbSet<Menu> Menus { get; set; }
|
||||||
public DbSet<Role> Roles { get; set; }
|
public DbSet<Role> Roles { get; set; }
|
||||||
public DbSet<RoleMenuButton> RoleMenuButtons { get; set; }
|
// public DbSet<RoleMenuButton> RoleMenuButtons { get; set; }
|
||||||
public DbSet<User> Users { get; set; }
|
public DbSet<User> Users { get; set; }
|
||||||
|
|
||||||
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
||||||
@ -32,7 +32,7 @@ namespace OpenAuth.Infrastructure
|
|||||||
modelBuilder.Configurations.Add(new DepartmentMap());
|
modelBuilder.Configurations.Add(new DepartmentMap());
|
||||||
modelBuilder.Configurations.Add(new MenuMap());
|
modelBuilder.Configurations.Add(new MenuMap());
|
||||||
modelBuilder.Configurations.Add(new RoleMap());
|
modelBuilder.Configurations.Add(new RoleMap());
|
||||||
modelBuilder.Configurations.Add(new RoleMenuButtonMap());
|
// modelBuilder.Configurations.Add(new RoleMenuButtonMap());
|
||||||
modelBuilder.Configurations.Add(new UserMap());
|
modelBuilder.Configurations.Add(new UserMap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
50
OpenAuth.UnitTest/DbContextTest.cs
Normal file
50
OpenAuth.UnitTest/DbContextTest.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Data.Entity;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using OpenAuth.Infrastructure;
|
||||||
|
|
||||||
|
namespace OpenAuth.UnitTest
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class DbContextTest
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void TestMethod1()
|
||||||
|
{
|
||||||
|
Display();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Display()
|
||||||
|
{
|
||||||
|
OpenAuthDBContext context = new OpenAuthDBContext();
|
||||||
|
foreach (var user in context.Users)
|
||||||
|
{
|
||||||
|
Console.WriteLine(user.RealName);
|
||||||
|
}
|
||||||
|
foreach (var department in context.Departments)
|
||||||
|
{
|
||||||
|
Console.WriteLine(department.FullName);
|
||||||
|
}
|
||||||
|
foreach (var menu in context.Menus)
|
||||||
|
{
|
||||||
|
Console.WriteLine(menu.FullName);
|
||||||
|
}
|
||||||
|
foreach (var button in context.Buttons)
|
||||||
|
{
|
||||||
|
Console.WriteLine(button.FullName);
|
||||||
|
}
|
||||||
|
foreach (var role in context.Roles)
|
||||||
|
{
|
||||||
|
Console.WriteLine(role.FullName);
|
||||||
|
foreach (var roleMenu in role.RoleMenus)
|
||||||
|
{
|
||||||
|
Console.WriteLine(roleMenu.FullName);
|
||||||
|
foreach (var button in roleMenu.Buttons)
|
||||||
|
{
|
||||||
|
Console.WriteLine(button.FullName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -61,6 +61,7 @@
|
|||||||
</Otherwise>
|
</Otherwise>
|
||||||
</Choose>
|
</Choose>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="DbContextTest.cs" />
|
||||||
<Compile Include="DepartmentTest.cs" />
|
<Compile Include="DepartmentTest.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="LoginTest.cs" />
|
<Compile Include="LoginTest.cs" />
|
||||||
|
@ -26,14 +26,12 @@ namespace OpenAuth.Web.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ContentResult Login(string username, string password)
|
public ActionResult Login(string username, string password)
|
||||||
{
|
{
|
||||||
var request = new LoginRequest {UserName = username, Password = password};
|
var request = new LoginRequest {UserName = username, Password = password};
|
||||||
var loginApp = new LoginApp(new UserRepository());
|
var loginApp = new LoginApp(new UserRepository());
|
||||||
var response = loginApp.Login(request);
|
var response = loginApp.Login(request);
|
||||||
if(response.Success)
|
return Json(new{Success= response.Success,Message=response.Message});
|
||||||
Response.Redirect("Home/Index");
|
|
||||||
return Content(response.Message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,24 +3,19 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>Login Page - Ace Admin</title>
|
<title>Login Page - Ace Admin</title>
|
||||||
<meta name="description" content="User login page" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<script type="text/javascript" src="@Url.Content("~/Content/1.9.1/jquery.min.js")"></script>
|
||||||
<!-- basic styles -->
|
<!-- basic styles -->
|
||||||
<link href="@Url.Content("~/Content/css/bootstrap.min.css")" rel="stylesheet" />
|
<link href="@Url.Content("~/Content/css/bootstrap.min.css")" rel="stylesheet" />
|
||||||
>
|
|
||||||
<link href="@Url.Content("~/Content/css/bootstrap-responsive.min.css")" rel="stylesheet" />
|
<link href="@Url.Content("~/Content/css/bootstrap-responsive.min.css")" rel="stylesheet" />
|
||||||
>
|
|
||||||
<link rel="stylesheet" href="@Url.Content("~/Content/css/font-awesome.min.css")" />
|
<link rel="stylesheet" href="@Url.Content("~/Content/css/font-awesome.min.css")" />
|
||||||
>
|
|
||||||
<!--[if IE 7]>
|
<!--[if IE 7]>
|
||||||
<link rel="stylesheet" href="css/font-awesome-ie7.min.css" />
|
<link rel="stylesheet" href="css/font-awesome-ie7.min.css" />
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
<!-- page specific plugin styles -->
|
<!-- page specific plugin styles -->
|
||||||
<!-- ace styles -->
|
<!-- ace styles -->
|
||||||
<link rel="stylesheet" href="@Url.Content("~/Content/css/ace.min.css")" />
|
<link rel="stylesheet" href="@Url.Content("~/Content/css/ace.min.css")" />
|
||||||
>
|
|
||||||
<link rel="stylesheet" href="@Url.Content("~/Content/css/ace-responsive.min.css")" />
|
<link rel="stylesheet" href="@Url.Content("~/Content/css/ace-responsive.min.css")" />
|
||||||
>
|
|
||||||
<!--[if lt IE 9]>
|
<!--[if lt IE 9]>
|
||||||
<link rel="stylesheet" href="css/ace-ie.min.css" />
|
<link rel="stylesheet" href="css/ace-ie.min.css" />
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
@ -52,13 +47,13 @@
|
|||||||
<fieldset>
|
<fieldset>
|
||||||
<label>
|
<label>
|
||||||
<span class="block input-icon input-icon-right">
|
<span class="block input-icon input-icon-right">
|
||||||
<input type="text" class="span12" id="username" placeholder="Username" />
|
<input type="text" class="span12" id="username" value="admin" placeholder="Username" />
|
||||||
<i class="icon-user"></i>
|
<i class="icon-user"></i>
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
<span class="block input-icon input-icon-right">
|
<span class="block input-icon input-icon-right">
|
||||||
<input type="password" class="span12" id="password" placeholder="Password" />
|
<input type="password" class="span12" id="password" value="123456" placeholder="Password" />
|
||||||
<i class="icon-lock"></i>
|
<i class="icon-lock"></i>
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
@ -67,7 +62,8 @@
|
|||||||
<label class="span8">
|
<label class="span8">
|
||||||
<input type="checkbox"><span class="lbl"> Remember Me</span>
|
<input type="checkbox"><span class="lbl"> Remember Me</span>
|
||||||
</label>
|
</label>
|
||||||
<button onclick="Login()" class="span4 btn btn-small btn-primary"><i class="icon-key"></i> Login</button>
|
@*TODO:尼妹,这个第一次点击不正常?<button onclick="Login();" class="span4 btn btn-small btn-primary"><i class="icon-key"></i> Login</button>*@
|
||||||
|
<input type="button" value="登录" onclick="Login();" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
@ -84,7 +80,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div><!--/.fluid-container-->
|
</div><!--/.fluid-container-->
|
||||||
<!-- basic scripts -->
|
<!-- basic scripts -->
|
||||||
<script type="text/javascript" src="@Url.Content("~/Content/1.9.1/jquery.min.js")"></script>
|
|
||||||
<!-- page specific plugin scripts -->
|
<!-- page specific plugin scripts -->
|
||||||
<!-- inline scripts related to this page -->
|
<!-- inline scripts related to this page -->
|
||||||
|
|
||||||
@ -92,13 +88,22 @@
|
|||||||
function Login() {
|
function Login() {
|
||||||
var username = $("#username").val();
|
var username = $("#username").val();
|
||||||
var password = $("#password").val();
|
var password = $("#password").val();
|
||||||
$.post("/Home/Login",
|
|
||||||
{
|
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "/Home/Login",
|
||||||
|
data: {
|
||||||
username: username,
|
username: username,
|
||||||
password: password
|
password: password
|
||||||
},
|
},
|
||||||
function (data) {
|
success: function(rel) {
|
||||||
alert("登陆失败:" + data);
|
if (rel.Success)
|
||||||
|
window.location = "/Home/Index";
|
||||||
|
else
|
||||||
|
alert("登陆失败:" + rel.Message);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -12,7 +12,10 @@
|
|||||||
<add key="ClientValidationEnabled" value="true" />
|
<add key="ClientValidationEnabled" value="true" />
|
||||||
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
|
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
|
||||||
</appSettings>
|
</appSettings>
|
||||||
<connectionStrings configSource="DB.config"></connectionStrings>
|
<connectionStrings>
|
||||||
|
<add name="OpenAuthDBContext" connectionString="Data Source=.;Initial Catalog=OpenAuthDB;Persist Security Info=True;User ID=sa;Password=516688;MultipleActiveResultSets=True"
|
||||||
|
providerName="System.Data.SqlClient" />
|
||||||
|
</connectionStrings>
|
||||||
|
|
||||||
|
|
||||||
<system.web>
|
<system.web>
|
||||||
|
Loading…
Reference in New Issue
Block a user