mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 23:13:40 +08:00
complete login
This commit is contained in:
parent
ae2d70a028
commit
8e4472b86a
@ -8,6 +8,7 @@ namespace OpenAuth.Domain.Model
|
||||
public Button()
|
||||
{
|
||||
this.RoleMenuButtons = new List<RoleMenuButton>();
|
||||
this.Menus = new List<Menu>();
|
||||
}
|
||||
|
||||
public string ButtonId { get; set; }
|
||||
@ -20,5 +21,6 @@ namespace OpenAuth.Domain.Model
|
||||
public bool Enabled { get; set; }
|
||||
public Nullable<int> SortCode { 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()
|
||||
{
|
||||
this.Buttons = new List<Button>();
|
||||
this.Roles = new List<Role>();
|
||||
this.RoleMenuButtons = new List<RoleMenuButton>();
|
||||
}
|
||||
|
||||
@ -24,6 +25,7 @@ namespace OpenAuth.Domain.Model
|
||||
public bool Enabled { get; set; }
|
||||
public Nullable<int> SortCode { get; set; }
|
||||
public virtual ICollection<Button> Buttons { get; set; }
|
||||
public virtual ICollection<Role> Roles { get; set; }
|
||||
public virtual ICollection<RoleMenuButton> RoleMenuButtons { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +44,9 @@
|
||||
<Compile Include="Model\DataPermission.cs" />
|
||||
<Compile Include="Model\Department.cs" />
|
||||
<Compile Include="Model\Menu.cs" />
|
||||
<Compile Include="Model\RoleMenuButton.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Model\Role.cs" />
|
||||
<Compile Include="Model\RoleMenuButton.cs" />
|
||||
<Compile Include="Model\User.cs" />
|
||||
<Compile Include="Service\LoginService.cs" />
|
||||
</ItemGroup>
|
||||
|
@ -37,6 +37,25 @@ namespace OpenAuth.Infrastructure.Mapping
|
||||
this.Property(t => t.Target)
|
||||
.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
|
||||
this.ToTable("Menu");
|
||||
this.Property(t => t.MenuId).HasColumnName("MenuId");
|
||||
|
@ -31,6 +31,7 @@ namespace OpenAuth.Infrastructure.Mapping
|
||||
this.Property(t => t.DepartmentId)
|
||||
.HasMaxLength(50);
|
||||
|
||||
//角色包含的用户;
|
||||
this.HasMany(d => d.Users)
|
||||
.WithMany(u => u.Roles)
|
||||
.Map(
|
||||
@ -41,6 +42,16 @@ namespace OpenAuth.Infrastructure.Mapping
|
||||
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
|
||||
this.ToTable("Role");
|
||||
|
@ -37,8 +37,10 @@
|
||||
<HintPath>..\packages\EntityFramework.6.1.3\lib\net40\EntityFramework.SqlServer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Activities" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Transactions" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
@ -22,7 +22,7 @@ namespace OpenAuth.Infrastructure
|
||||
public DbSet<Department> Departments { get; set; }
|
||||
public DbSet<Menu> Menus { 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; }
|
||||
|
||||
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
||||
@ -32,7 +32,7 @@ namespace OpenAuth.Infrastructure
|
||||
modelBuilder.Configurations.Add(new DepartmentMap());
|
||||
modelBuilder.Configurations.Add(new MenuMap());
|
||||
modelBuilder.Configurations.Add(new RoleMap());
|
||||
modelBuilder.Configurations.Add(new RoleMenuButtonMap());
|
||||
// modelBuilder.Configurations.Add(new RoleMenuButtonMap());
|
||||
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>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="DbContextTest.cs" />
|
||||
<Compile Include="DepartmentTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="LoginTest.cs" />
|
||||
|
@ -26,14 +26,12 @@ namespace OpenAuth.Web.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ContentResult Login(string username, string password)
|
||||
public ActionResult Login(string username, string password)
|
||||
{
|
||||
var request = new LoginRequest {UserName = username, Password = password};
|
||||
var loginApp = new LoginApp(new UserRepository());
|
||||
var response = loginApp.Login(request);
|
||||
if(response.Success)
|
||||
Response.Redirect("Home/Index");
|
||||
return Content(response.Message);
|
||||
return Json(new{Success= response.Success,Message=response.Message});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,24 +3,19 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<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 -->
|
||||
<link href="@Url.Content("~/Content/css/bootstrap.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")" />
|
||||
>
|
||||
<!--[if IE 7]>
|
||||
<link rel="stylesheet" href="css/font-awesome-ie7.min.css" />
|
||||
<![endif]-->
|
||||
<!-- page specific plugin styles -->
|
||||
<!-- ace styles -->
|
||||
<link rel="stylesheet" href="@Url.Content("~/Content/css/ace.min.css")" />
|
||||
>
|
||||
<link rel="stylesheet" href="@Url.Content("~/Content/css/ace-responsive.min.css")" />
|
||||
>
|
||||
<!--[if lt IE 9]>
|
||||
<link rel="stylesheet" href="css/ace-ie.min.css" />
|
||||
<![endif]-->
|
||||
@ -52,13 +47,13 @@
|
||||
<fieldset>
|
||||
<label>
|
||||
<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>
|
||||
</span>
|
||||
</label>
|
||||
<label>
|
||||
<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>
|
||||
</span>
|
||||
</label>
|
||||
@ -67,8 +62,9 @@
|
||||
<label class="span8">
|
||||
<input type="checkbox"><span class="lbl"> Remember Me</span>
|
||||
</label>
|
||||
<button onclick="Login()" class="span4 btn btn-small btn-primary"><i class="icon-key"></i> Login</button>
|
||||
</div>
|
||||
@*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>
|
||||
|
||||
</fieldset>
|
||||
</form>
|
||||
@ -84,7 +80,7 @@
|
||||
</div>
|
||||
</div><!--/.fluid-container-->
|
||||
<!-- basic scripts -->
|
||||
<script type="text/javascript" src="@Url.Content("~/Content/1.9.1/jquery.min.js")"></script>
|
||||
|
||||
<!-- page specific plugin scripts -->
|
||||
<!-- inline scripts related to this page -->
|
||||
|
||||
@ -92,14 +88,23 @@
|
||||
function Login() {
|
||||
var username = $("#username").val();
|
||||
var password = $("#password").val();
|
||||
$.post("/Home/Login",
|
||||
{
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
function (data) {
|
||||
alert("登陆失败:" + data);
|
||||
});
|
||||
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/Home/Login",
|
||||
data: {
|
||||
username: username,
|
||||
password: password
|
||||
},
|
||||
success: function(rel) {
|
||||
if (rel.Success)
|
||||
window.location = "/Home/Index";
|
||||
else
|
||||
alert("登陆失败:" + rel.Message);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
@ -12,7 +12,10 @@
|
||||
<add key="ClientValidationEnabled" value="true" />
|
||||
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
|
||||
</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>
|
||||
|
Loading…
Reference in New Issue
Block a user