diff --git a/GitCandy.Web/Controllers/CandyControllerBase.cs b/GitCandy.Web/Controllers/CandyControllerBase.cs
index 6a3cd75..390961b 100644
--- a/GitCandy.Web/Controllers/CandyControllerBase.cs
+++ b/GitCandy.Web/Controllers/CandyControllerBase.cs
@@ -8,6 +8,7 @@ using NewLife.Log;
using NewLife.Model;
using NewLife.Reflection;
using XCode.Membership;
+using UserY = NewLife.GitCandy.Entity.User;
namespace GitCandy.Controllers
{
@@ -23,7 +24,13 @@ namespace GitCandy.Controllers
protected override void OnAuthorization(AuthorizationContext filterContext)
{
var prv = ManageProvider.Provider;
- if (prv.TryLogin() != null) prv.SetPrincipal();
+ if (prv.TryLogin() != null)
+ {
+ prv.SetPrincipal();
+
+ // 同步用户数据到Git用户表
+ if (UserY.Current == null) UserY.Current = UserY.GetOrAdd(prv.Current);
+ }
base.OnAuthorization(filterContext);
}
diff --git a/GitCandy.Web/Views/Shared/_FrontLayout.cshtml b/GitCandy.Web/Views/Shared/_FrontLayout.cshtml
index 9755e96..9d574ed 100644
--- a/GitCandy.Web/Views/Shared/_FrontLayout.cshtml
+++ b/GitCandy.Web/Views/Shared/_FrontLayout.cshtml
@@ -42,6 +42,7 @@
<li class="">@Html.ActionLink(SR.Shared_Users, "Index", "Account")</li>
<li class="">@Html.ActionLink(SR.Shared_Teams, "Index", "Team")</li>
<li class="">@Html.ActionLink(SR.Shared_Settings, "Index", "GitCandy/Git")</li>
+ <li class="">@Html.ActionLink("控制台", "Index", "Admin/Index")</li>
}
<li class="">@Html.ActionLink("创建项目", "Create", "Repository")</li>
}
diff --git a/GitCandy.Web/Views/Shared/_FrontLayout.generated.cs b/GitCandy.Web/Views/Shared/_FrontLayout.generated.cs
index 38d6c20..e03f315 100644
--- a/GitCandy.Web/Views/Shared/_FrontLayout.generated.cs
+++ b/GitCandy.Web/Views/Shared/_FrontLayout.generated.cs
@@ -289,8 +289,23 @@ WriteLiteral(">");
#line hidden
WriteLiteral("</li>\r\n");
+WriteLiteral(" <li");
+
+WriteLiteral(" class=\"\"");
+
+WriteLiteral(">");
+
#line 45 "..\..\Views\Shared\_FrontLayout.cshtml"
+ Write(Html.ActionLink("控制台", "Index", "Admin/Index"));
+
+
+ #line default
+ #line hidden
+WriteLiteral("</li>\r\n");
+
+
+ #line 46 "..\..\Views\Shared\_FrontLayout.cshtml"
}
@@ -303,7 +318,7 @@ WriteLiteral(" class=\"\"");
WriteLiteral(">");
- #line 46 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 47 "..\..\Views\Shared\_FrontLayout.cshtml"
Write(Html.ActionLink("创建项目", "Create", "Repository"));
@@ -312,7 +327,7 @@ WriteLiteral(">");
WriteLiteral("</li>\r\n");
- #line 47 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 48 "..\..\Views\Shared\_FrontLayout.cshtml"
}
@@ -321,7 +336,7 @@ WriteLiteral("</li>\r\n");
WriteLiteral(" <li>");
- #line 48 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 49 "..\..\Views\Shared\_FrontLayout.cshtml"
Write(Html.ActionLink(SR.Shared_About, "About", "Home"));
@@ -334,13 +349,13 @@ WriteLiteral(" class=\"nav navbar-nav navbar-right\"");
WriteLiteral(">\r\n");
- #line 51 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 52 "..\..\Views\Shared\_FrontLayout.cshtml"
#line default
#line hidden
- #line 51 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 52 "..\..\Views\Shared\_FrontLayout.cshtml"
if (token == null)
{
@@ -354,7 +369,7 @@ WriteLiteral(" class=\"\"");
WriteLiteral(">");
- #line 53 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 54 "..\..\Views\Shared\_FrontLayout.cshtml"
Write(Html.ActionLink(SR.Shared_Register, "Login", "Admin/User"));
@@ -369,7 +384,7 @@ WriteLiteral(" class=\"\"");
WriteLiteral(">");
- #line 54 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 55 "..\..\Views\Shared\_FrontLayout.cshtml"
Write(Html.ActionLink(SR.Shared_Login, "Login", "Admin/User", new { r = ViewContext.HttpContext.Request.Url.PathAndQuery }, null));
@@ -378,7 +393,7 @@ WriteLiteral(">");
WriteLiteral("</li>\r\n");
- #line 55 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 56 "..\..\Views\Shared\_FrontLayout.cshtml"
}
else
{
@@ -393,7 +408,7 @@ WriteLiteral(" class=\"\"");
WriteLiteral(">");
- #line 58 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 59 "..\..\Views\Shared\_FrontLayout.cshtml"
Write(Html.ActionLink(token + "", "Detail", "Account", new { name = token.Name }, null));
@@ -408,7 +423,7 @@ WriteLiteral(" class=\"\"");
WriteLiteral(">");
- #line 59 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 60 "..\..\Views\Shared\_FrontLayout.cshtml"
Write(Html.ActionLink(SR.Shared_Logout, "Logout", "Admin/User", new { r = ViewContext.HttpContext.Request.Url.PathAndQuery }, null));
@@ -417,7 +432,7 @@ WriteLiteral(">");
WriteLiteral("</li>\r\n");
- #line 60 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 61 "..\..\Views\Shared\_FrontLayout.cshtml"
}
@@ -433,7 +448,7 @@ WriteLiteral(">\r\n");
WriteLiteral(" ");
- #line 67 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 68 "..\..\Views\Shared\_FrontLayout.cshtml"
Write(RenderBody());
@@ -466,7 +481,7 @@ WriteLiteral(" href=\"#\"");
WriteLiteral(">");
- #line 74 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 75 "..\..\Views\Shared\_FrontLayout.cshtml"
Write(ViewBag.Language);
@@ -483,7 +498,7 @@ WriteLiteral(" class=\"dropdown-menu\"");
WriteLiteral(">\r\n <li>");
- #line 76 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 77 "..\..\Views\Shared\_FrontLayout.cshtml"
Write(Html.CultureActionLink("zh-cn"));
@@ -492,7 +507,7 @@ WriteLiteral(">\r\n <li>");
WriteLiteral("</li>\r\n <li>");
- #line 77 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 78 "..\..\Views\Shared\_FrontLayout.cshtml"
Write(Html.CultureActionLink("en-us"));
@@ -501,7 +516,7 @@ WriteLiteral("</li>\r\n <li>");
WriteLiteral("</li>\r\n <li>");
- #line 78 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 79 "..\..\Views\Shared\_FrontLayout.cshtml"
Write(Html.CultureActionLink("fr-fr"));
@@ -515,20 +530,20 @@ WriteLiteral("><p");
WriteLiteral(" class=\"muted\"");
-WriteAttribute("title", Tuple.Create(" title=\"", 3929), Tuple.Create("\"", 3962)
+WriteAttribute("title", Tuple.Create(" title=\"", 4024), Tuple.Create("\"", 4057)
- #line 81 "..\..\Views\Shared\_FrontLayout.cshtml"
-, Tuple.Create(Tuple.Create("", 3937), Tuple.Create<System.Object, System.Int32>(Profiler.Current.Elapsed
+ #line 82 "..\..\Views\Shared\_FrontLayout.cshtml"
+, Tuple.Create(Tuple.Create("", 4032), Tuple.Create<System.Object, System.Int32>(Profiler.Current.Elapsed
#line default
#line hidden
-, 3937), false)
+, 4032), false)
);
WriteLiteral(">© 2002-");
- #line 81 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 82 "..\..\Views\Shared\_FrontLayout.cshtml"
Write(DateTime.Now.Year);
@@ -537,7 +552,7 @@ WriteLiteral(">© 2002-");
WriteLiteral(" ");
- #line 81 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 82 "..\..\Views\Shared\_FrontLayout.cshtml"
Write(cfg.Company);
@@ -545,51 +560,51 @@ WriteLiteral(" ");
#line hidden
WriteLiteral("</p></div>\r\n </div>\r\n </div>\r\n\r\n <script");
-WriteAttribute("src", Tuple.Create(" src=\"", 4060), Tuple.Create("\"", 4091)
-, Tuple.Create(Tuple.Create("", 4066), Tuple.Create<System.Object, System.Int32>(Href("~/Scripts/jquery-2.0.3.js")
-, 4066), false)
+WriteAttribute("src", Tuple.Create(" src=\"", 4155), Tuple.Create("\"", 4186)
+, Tuple.Create(Tuple.Create("", 4161), Tuple.Create<System.Object, System.Int32>(Href("~/Scripts/jquery-2.0.3.js")
+, 4161), false)
);
WriteLiteral("></script>\r\n <script");
-WriteAttribute("src", Tuple.Create(" src=\"", 4115), Tuple.Create("\"", 4143)
-, Tuple.Create(Tuple.Create("", 4121), Tuple.Create<System.Object, System.Int32>(Href("~/Scripts/bootstrap.js")
-, 4121), false)
+WriteAttribute("src", Tuple.Create(" src=\"", 4210), Tuple.Create("\"", 4238)
+, Tuple.Create(Tuple.Create("", 4216), Tuple.Create<System.Object, System.Int32>(Href("~/Scripts/bootstrap.js")
+, 4216), false)
);
WriteLiteral("></script>\r\n <script");
-WriteAttribute("src", Tuple.Create(" src=\"", 4167), Tuple.Create("\"", 4202)
-, Tuple.Create(Tuple.Create("", 4173), Tuple.Create<System.Object, System.Int32>(Href("~/Scripts/bootstrap-switch.js")
-, 4173), false)
+WriteAttribute("src", Tuple.Create(" src=\"", 4262), Tuple.Create("\"", 4297)
+, Tuple.Create(Tuple.Create("", 4268), Tuple.Create<System.Object, System.Int32>(Href("~/Scripts/bootstrap-switch.js")
+, 4268), false)
);
WriteLiteral("></script>\r\n <script");
-WriteAttribute("src", Tuple.Create(" src=\"", 4226), Tuple.Create("\"", 4265)
-, Tuple.Create(Tuple.Create("", 4232), Tuple.Create<System.Object, System.Int32>(Href("~/Scripts/bootstrap3-typeahead.js")
-, 4232), false)
+WriteAttribute("src", Tuple.Create(" src=\"", 4321), Tuple.Create("\"", 4360)
+, Tuple.Create(Tuple.Create("", 4327), Tuple.Create<System.Object, System.Int32>(Href("~/Scripts/bootstrap3-typeahead.js")
+, 4327), false)
);
WriteLiteral("></script>\r\n <script");
-WriteAttribute("src", Tuple.Create(" src=\"", 4289), Tuple.Create("\"", 4322)
-, Tuple.Create(Tuple.Create("", 4295), Tuple.Create<System.Object, System.Int32>(Href("~/Scripts/highlight.pack.js")
-, 4295), false)
+WriteAttribute("src", Tuple.Create(" src=\"", 4384), Tuple.Create("\"", 4417)
+, Tuple.Create(Tuple.Create("", 4390), Tuple.Create<System.Object, System.Int32>(Href("~/Scripts/highlight.pack.js")
+, 4390), false)
);
WriteLiteral("></script>\r\n <script");
-WriteAttribute("src", Tuple.Create(" src=\"", 4346), Tuple.Create("\"", 4371)
-, Tuple.Create(Tuple.Create("", 4352), Tuple.Create<System.Object, System.Int32>(Href("~/Scripts/marked.js")
-, 4352), false)
+WriteAttribute("src", Tuple.Create(" src=\"", 4441), Tuple.Create("\"", 4466)
+, Tuple.Create(Tuple.Create("", 4447), Tuple.Create<System.Object, System.Int32>(Href("~/Scripts/marked.js")
+, 4447), false)
);
WriteLiteral("></script>\r\n <script");
-WriteAttribute("src", Tuple.Create(" src=\"", 4395), Tuple.Create("\"", 4420)
-, Tuple.Create(Tuple.Create("", 4401), Tuple.Create<System.Object, System.Int32>(Href("~/Scripts/common.js")
-, 4401), false)
+WriteAttribute("src", Tuple.Create(" src=\"", 4490), Tuple.Create("\"", 4515)
+, Tuple.Create(Tuple.Create("", 4496), Tuple.Create<System.Object, System.Int32>(Href("~/Scripts/common.js")
+, 4496), false)
);
WriteLiteral("></script>\r\n");
@@ -597,7 +612,7 @@ WriteLiteral("></script>\r\n");
WriteLiteral(" ");
- #line 92 "..\..\Views\Shared\_FrontLayout.cshtml"
+ #line 93 "..\..\Views\Shared\_FrontLayout.cshtml"
Write(RenderSection("scripts", required: false));
diff --git "a/GitCandy/Entity/Entity/\347\224\250\346\210\267.Biz.cs" "b/GitCandy/Entity/Entity/\347\224\250\346\210\267.Biz.cs"
index 96f1e64..1adbec8 100644
--- "a/GitCandy/Entity/Entity/\347\224\250\346\210\267.Biz.cs"
+++ "b/GitCandy/Entity/Entity/\347\224\250\346\210\267.Biz.cs"
@@ -8,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
+using System.Web;
using NewLife.Data;
using NewLife.Model;
using NewLife.Web;
@@ -111,24 +112,24 @@ namespace NewLife.GitCandy.Entity
public String[] RepositoryNames => Repositories?.Select(e => e.RepositoryName).ToArray();
- ///// <summary>当前登录用户</summary>
- //public static User Current
- //{
- // get
- // {
- // var ss = HttpContext.Current?.Session;
- // if (ss == null) return null;
+ /// <summary>当前登录用户</summary>
+ public static User Current
+ {
+ get
+ {
+ var ss = HttpContext.Current?.Session;
+ if (ss == null) return null;
- // return ss["CandyUser"] as User;
- // }
- // set
- // {
- // var ss = HttpContext.Current?.Session;
- // if (ss == null) return;
+ return ss["CandyUser"] as User;
+ }
+ set
+ {
+ var ss = HttpContext.Current?.Session;
+ if (ss == null) return;
- // ss["CandyUser"] = value;
- // }
- //}
+ ss["CandyUser"] = value;
+ }
+ }
//String IIdentity.AuthenticationType => "GitCandy";
@@ -268,6 +269,43 @@ namespace NewLife.GitCandy.Entity
// return user;
//}
+
+ public static User GetOrAdd(Int32 linkid, String name)
+ {
+ var user = Find(_.LinkID == linkid);
+ if (user == null) user = FindByName(name);
+ if (user != null)
+ {
+ if (user.LinkID > 0 && user.LinkID != linkid) throw new InvalidOperationException($"账号[{name}]被[{user.LinkID}]和[{linkid}]共用,请联系管理员");
+
+ user.LinkID = linkid;
+ user.SaveAsync();
+ }
+ else
+ {
+ user = new User { LinkID = linkid, Name = name };
+ user.Insert();
+ }
+
+ //if (user.Name.IsNullOrEmpty()) user.Name = name;
+
+ return user;
+ }
+
+ public static User GetOrAdd(IManageUser user)
+ {
+ if (user == null) return null;
+
+ var u = GetOrAdd(user.ID, user.Name);
+ if (u != null)
+ {
+ u.NickName = user.NickName;
+ if (user is XCode.Membership.IUser au) u.Email = au.Mail;
+ u.SaveAsync();
+ }
+
+ return u;
+ }
#endregion
}
}
\ No newline at end of file
diff --git "a/GitCandy/Entity/Entity/\347\224\250\346\210\267.cs" "b/GitCandy/Entity/Entity/\347\224\250\346\210\267.cs"
index b99cad8..a51cc1c 100644
--- "a/GitCandy/Entity/Entity/\347\224\250\346\210\267.cs"
+++ "b/GitCandy/Entity/Entity/\347\224\250\346\210\267.cs"
@@ -12,6 +12,7 @@ namespace NewLife.GitCandy.Entity
[DataObject]
[Description("用户")]
[BindIndex("IU_User_Name", true, "Name")]
+ [BindIndex("IX_User_LinkID", false, "LinkID")]
[BindTable("User", Description = "用户", ConnName = "GitCandy", DbType = DatabaseType.SqlServer)]
public partial class User : IUser
{
@@ -72,6 +73,14 @@ namespace NewLife.GitCandy.Entity
[BindColumn("Description", "描述", "nvarchar(500)")]
public String Description { get { return _Description; } set { if (OnPropertyChanging(__.Description, value)) { _Description = value; OnPropertyChanged(__.Description); } } }
+ private Int32 _LinkID;
+ /// <summary>链接。连接到基础用户</summary>
+ [DisplayName("链接")]
+ [Description("链接。连接到基础用户")]
+ [DataObjectField(false, false, false, 0)]
+ [BindColumn("LinkID", "链接。连接到基础用户", "int")]
+ public Int32 LinkID { get { return _LinkID; } set { if (OnPropertyChanging(__.LinkID, value)) { _LinkID = value; OnPropertyChanged(__.LinkID); } } }
+
private Int32 _CreateUserID;
/// <summary>创建者</summary>
[DisplayName("创建者")]
@@ -138,6 +147,7 @@ namespace NewLife.GitCandy.Entity
case __.Enable : return _Enable;
case __.IsTeam : return _IsTeam;
case __.Description : return _Description;
+ case __.LinkID : return _LinkID;
case __.CreateUserID : return _CreateUserID;
case __.CreateTime : return _CreateTime;
case __.CreateIP : return _CreateIP;
@@ -158,6 +168,7 @@ namespace NewLife.GitCandy.Entity
case __.Enable : _Enable = Convert.ToBoolean(value); break;
case __.IsTeam : _IsTeam = Convert.ToBoolean(value); break;
case __.Description : _Description = Convert.ToString(value); break;
+ case __.LinkID : _LinkID = Convert.ToInt32(value); break;
case __.CreateUserID : _CreateUserID = Convert.ToInt32(value); break;
case __.CreateTime : _CreateTime = Convert.ToDateTime(value); break;
case __.CreateIP : _CreateIP = Convert.ToString(value); break;
@@ -195,6 +206,9 @@ namespace NewLife.GitCandy.Entity
/// <summary>描述</summary>
public static readonly Field Description = FindByName(__.Description);
+ /// <summary>链接。连接到基础用户</summary>
+ public static readonly Field LinkID = FindByName(__.LinkID);
+
/// <summary>创建者</summary>
public static readonly Field CreateUserID = FindByName(__.CreateUserID);
@@ -240,6 +254,9 @@ namespace NewLife.GitCandy.Entity
/// <summary>描述</summary>
public const String Description = "Description";
+ /// <summary>链接。连接到基础用户</summary>
+ public const String LinkID = "LinkID";
+
/// <summary>创建者</summary>
public const String CreateUserID = "CreateUserID";
@@ -286,6 +303,9 @@ namespace NewLife.GitCandy.Entity
/// <summary>描述</summary>
String Description { get; set; }
+ /// <summary>链接。连接到基础用户</summary>
+ Int32 LinkID { get; set; }
+
/// <summary>创建者</summary>
Int32 CreateUserID { get; set; }
diff --git a/GitCandy/Entity/NewLife.GitCandy.xml b/GitCandy/Entity/NewLife.GitCandy.xml
index 71b21b8..007d2bc 100644
--- a/GitCandy/Entity/NewLife.GitCandy.xml
+++ b/GitCandy/Entity/NewLife.GitCandy.xml
@@ -9,6 +9,7 @@
<Column Name="Enable" DataType="Boolean" Description="启用" />
<Column Name="IsTeam" DataType="Boolean" Description="团队" />
<Column Name="Description" DataType="String" Length="500" Description="描述" />
+ <Column Name="LinkID" DataType="Int32" Description="链接。连接到基础用户" />
<Column Name="CreateUserID" DataType="Int32" Description="创建者" />
<Column Name="CreateTime" DataType="DateTime" Description="创建时间" />
<Column Name="CreateIP" DataType="String" Description="创建地址" />
@@ -18,6 +19,7 @@
</Columns>
<Indexes>
<Index Columns="Name" Unique="True" />
+ <Index Columns="LinkID" />
</Indexes>
</Table>
<Table Name="Repository" Description="仓库" DbType="SqlServer">