From 032bc20e1e7d50249c63469d709ced1b89fd323b Mon Sep 17 00:00:00 2001 From: yubaolee Date: Fri, 8 Jul 2016 11:28:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0SSO=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/ControlHelper.cs | 59 - Infrastructure/CookieHelper.cs | 42 +- Infrastructure/GenerateId.cs | 49 +- Infrastructure/Infrastructure.csproj | 23 +- Infrastructure/SessionHelper.cs | 2 +- Infrastructure/packages.config | 3 + OpenAuth.App/LoginApp.cs | 9 +- OpenAuth.App/OpenAuth.App.csproj | 35 + OpenAuth.App/SSO/AuthUtil.cs | 76 + OpenAuth.App/SSO/LoginResult.cs | 10 + OpenAuth.App/SSO/SSOAuthAttribute.cs | 68 + OpenAuth.App/ViewModel/LoginUserVM.cs | 1 + .../Content/jqGrid/i18n/grid.locale-it.js | 2 +- .../Content/jqGrid/i18n/grid.locale-lt.js | 2 +- OpenAuth.Mvc/Controllers/HomeController.cs | 1 - OpenAuth.Mvc/Controllers/LoginController.cs | 1 - .../Controllers/ModuleManagerController.cs | 1 - .../Controllers/OrgManagerController.cs | 1 - OpenAuth.Mvc/Global.asax.cs | 64 +- OpenAuth.Mvc/OpenAuth.Mvc.csproj | 26 +- .../Properties/PublishProfiles/default.pubxml | 17 + OpenAuth.Mvc/Views/Home/Index.cshtml | 23 +- OpenAuth.Mvc/Views/Login/Index.cshtml | 3 + OpenAuth.Mvc/Views/ModuleManager/Index.cshtml | 2 +- OpenAuth.Mvc/Views/Shared/_BjuiLayout.cshtml | 2 +- OpenAuth.Mvc/Web.config | 33 +- OpenAuth.Mvc/packages.config | 12 +- OpenAuth.UnitTest/App.config | 37 +- OpenAuth.WebApi/App_Start/BundleConfig.cs | 28 + OpenAuth.WebApi/App_Start/FilterConfig.cs | 13 + OpenAuth.WebApi/App_Start/RouteConfig.cs | 23 + OpenAuth.WebApi/App_Start/WebApiConfig.cs | 24 + .../Areas/SSO/Controllers/LoginController.cs | 122 + .../SSO/Controllers/PassportController.cs | 18 + OpenAuth.WebApi/Areas/SSO/Models/AppInfo.cs | 37 + OpenAuth.WebApi/Areas/SSO/Models/AppUser.cs | 41 + .../Areas/SSO/Models/PassportLoginRequest.cs | 26 + .../Areas/SSO/Models/ServiceContext.cs | 64 + .../Areas/SSO/Models/StringExtensions.cs | 31 + .../Areas/SSO/SSOAreaRegistration.cs | 24 + .../Areas/SSO/Views/Login/Index.cshtml | 58 + OpenAuth.WebApi/Areas/SSO/Views/web.config | 36 + OpenAuth.WebApi/AutofacExt.cs | 74 + OpenAuth.WebApi/Content/Site.css | 17 + OpenAuth.WebApi/Content/bootstrap.css | 6816 ++++++++++++ OpenAuth.WebApi/Content/bootstrap.min.css | 20 + OpenAuth.WebApi/Global.asax | 1 + OpenAuth.WebApi/Global.asax.cs | 25 + OpenAuth.WebApi/OpenAuth.WebApi.csproj | 262 + OpenAuth.WebApi/Properties/AssemblyInfo.cs | 35 + OpenAuth.WebApi/Scripts/_references.js | Bin 0 -> 600 bytes OpenAuth.WebApi/Scripts/bootstrap.js | 2014 ++++ OpenAuth.WebApi/Scripts/bootstrap.min.js | 21 + .../Scripts/jquery-1.10.2.intellisense.js | 2657 +++++ OpenAuth.WebApi/Scripts/jquery-1.10.2.js | 9803 +++++++++++++++++ OpenAuth.WebApi/Scripts/jquery-1.10.2.min.js | 23 + OpenAuth.WebApi/Scripts/jquery-1.10.2.min.map | 1 + OpenAuth.WebApi/Scripts/modernizr-2.6.2.js | 1416 +++ OpenAuth.WebApi/Scripts/respond.js | 340 + OpenAuth.WebApi/Scripts/respond.min.js | 20 + OpenAuth.WebApi/Web.Debug.config | 30 + OpenAuth.WebApi/Web.Release.config | 31 + OpenAuth.WebApi/Web.config | 96 + OpenAuth.WebApi/favicon.ico | Bin 0 -> 32038 bytes .../fonts/glyphicons-halflings-regular.eot | Bin 0 -> 14079 bytes .../fonts/glyphicons-halflings-regular.svg | 228 + .../fonts/glyphicons-halflings-regular.ttf | Bin 0 -> 29512 bytes .../fonts/glyphicons-halflings-regular.woff | Bin 0 -> 16448 bytes OpenAuth.WebApi/packages.config | 33 + OpenAuth.WebTest/App_Start/BundleConfig.cs | 31 + OpenAuth.WebTest/App_Start/FilterConfig.cs | 13 + OpenAuth.WebTest/App_Start/RouteConfig.cs | 23 + OpenAuth.WebTest/Content/Site.css | 24 + OpenAuth.WebTest/Content/bootstrap.css | 6816 ++++++++++++ OpenAuth.WebTest/Content/bootstrap.min.css | 20 + .../Controllers/HomeController.cs | 15 + .../Controllers/LoginController.cs | 30 + OpenAuth.WebTest/Global.asax | 1 + OpenAuth.WebTest/Global.asax.cs | 21 + OpenAuth.WebTest/OpenAuth.WebTest.csproj | 218 + OpenAuth.WebTest/Properties/AssemblyInfo.cs | 35 + OpenAuth.WebTest/Scripts/_references.js | Bin 0 -> 600 bytes OpenAuth.WebTest/Scripts/bootstrap.js | 2014 ++++ OpenAuth.WebTest/Scripts/bootstrap.min.js | 21 + .../Scripts/jquery-1.10.2.intellisense.js | 2657 +++++ OpenAuth.WebTest/Scripts/jquery-1.10.2.js | 9803 +++++++++++++++++ OpenAuth.WebTest/Scripts/jquery-1.10.2.min.js | 23 + .../Scripts/jquery-1.10.2.min.map | 1 + .../Scripts/jquery.validate-vsdoc.js | 1302 +++ OpenAuth.WebTest/Scripts/jquery.validate.js | 1245 +++ .../Scripts/jquery.validate.min.js | 16 + .../Scripts/jquery.validate.unobtrusive.js | 429 + .../jquery.validate.unobtrusive.min.js | 19 + OpenAuth.WebTest/Scripts/modernizr-2.6.2.js | 1416 +++ OpenAuth.WebTest/Scripts/respond.js | 340 + OpenAuth.WebTest/Scripts/respond.min.js | 20 + OpenAuth.WebTest/Views/Home/Index.cshtml | 62 + OpenAuth.WebTest/Views/Login/Index.cshtml | 28 + OpenAuth.WebTest/Views/Shared/Error.cshtml | 14 + OpenAuth.WebTest/Views/Shared/_Layout.cshtml | 41 + OpenAuth.WebTest/Views/Web.config | 43 + OpenAuth.WebTest/Views/_ViewStart.cshtml | 3 + OpenAuth.WebTest/Web.Debug.config | 30 + OpenAuth.WebTest/Web.Release.config | 31 + OpenAuth.WebTest/Web.config | 60 + OpenAuth.WebTest/favicon.ico | Bin 0 -> 32038 bytes .../fonts/glyphicons-halflings-regular.eot | Bin 0 -> 14079 bytes .../fonts/glyphicons-halflings-regular.svg | 228 + .../fonts/glyphicons-halflings-regular.ttf | Bin 0 -> 29512 bytes .../fonts/glyphicons-halflings-regular.woff | Bin 0 -> 16448 bytes OpenAuth.WebTest/packages.config | 21 + OpenAuth.sln | 20 +- 112 files changed, 52068 insertions(+), 178 deletions(-) delete mode 100644 Infrastructure/ControlHelper.cs create mode 100644 OpenAuth.App/SSO/AuthUtil.cs create mode 100644 OpenAuth.App/SSO/LoginResult.cs create mode 100644 OpenAuth.App/SSO/SSOAuthAttribute.cs create mode 100644 OpenAuth.Mvc/Properties/PublishProfiles/default.pubxml create mode 100644 OpenAuth.WebApi/App_Start/BundleConfig.cs create mode 100644 OpenAuth.WebApi/App_Start/FilterConfig.cs create mode 100644 OpenAuth.WebApi/App_Start/RouteConfig.cs create mode 100644 OpenAuth.WebApi/App_Start/WebApiConfig.cs create mode 100644 OpenAuth.WebApi/Areas/SSO/Controllers/LoginController.cs create mode 100644 OpenAuth.WebApi/Areas/SSO/Controllers/PassportController.cs create mode 100644 OpenAuth.WebApi/Areas/SSO/Models/AppInfo.cs create mode 100644 OpenAuth.WebApi/Areas/SSO/Models/AppUser.cs create mode 100644 OpenAuth.WebApi/Areas/SSO/Models/PassportLoginRequest.cs create mode 100644 OpenAuth.WebApi/Areas/SSO/Models/ServiceContext.cs create mode 100644 OpenAuth.WebApi/Areas/SSO/Models/StringExtensions.cs create mode 100644 OpenAuth.WebApi/Areas/SSO/SSOAreaRegistration.cs create mode 100644 OpenAuth.WebApi/Areas/SSO/Views/Login/Index.cshtml create mode 100644 OpenAuth.WebApi/Areas/SSO/Views/web.config create mode 100644 OpenAuth.WebApi/AutofacExt.cs create mode 100644 OpenAuth.WebApi/Content/Site.css create mode 100644 OpenAuth.WebApi/Content/bootstrap.css create mode 100644 OpenAuth.WebApi/Content/bootstrap.min.css create mode 100644 OpenAuth.WebApi/Global.asax create mode 100644 OpenAuth.WebApi/Global.asax.cs create mode 100644 OpenAuth.WebApi/OpenAuth.WebApi.csproj create mode 100644 OpenAuth.WebApi/Properties/AssemblyInfo.cs create mode 100644 OpenAuth.WebApi/Scripts/_references.js create mode 100644 OpenAuth.WebApi/Scripts/bootstrap.js create mode 100644 OpenAuth.WebApi/Scripts/bootstrap.min.js create mode 100644 OpenAuth.WebApi/Scripts/jquery-1.10.2.intellisense.js create mode 100644 OpenAuth.WebApi/Scripts/jquery-1.10.2.js create mode 100644 OpenAuth.WebApi/Scripts/jquery-1.10.2.min.js create mode 100644 OpenAuth.WebApi/Scripts/jquery-1.10.2.min.map create mode 100644 OpenAuth.WebApi/Scripts/modernizr-2.6.2.js create mode 100644 OpenAuth.WebApi/Scripts/respond.js create mode 100644 OpenAuth.WebApi/Scripts/respond.min.js create mode 100644 OpenAuth.WebApi/Web.Debug.config create mode 100644 OpenAuth.WebApi/Web.Release.config create mode 100644 OpenAuth.WebApi/Web.config create mode 100644 OpenAuth.WebApi/favicon.ico create mode 100644 OpenAuth.WebApi/fonts/glyphicons-halflings-regular.eot create mode 100644 OpenAuth.WebApi/fonts/glyphicons-halflings-regular.svg create mode 100644 OpenAuth.WebApi/fonts/glyphicons-halflings-regular.ttf create mode 100644 OpenAuth.WebApi/fonts/glyphicons-halflings-regular.woff create mode 100644 OpenAuth.WebApi/packages.config create mode 100644 OpenAuth.WebTest/App_Start/BundleConfig.cs create mode 100644 OpenAuth.WebTest/App_Start/FilterConfig.cs create mode 100644 OpenAuth.WebTest/App_Start/RouteConfig.cs create mode 100644 OpenAuth.WebTest/Content/Site.css create mode 100644 OpenAuth.WebTest/Content/bootstrap.css create mode 100644 OpenAuth.WebTest/Content/bootstrap.min.css create mode 100644 OpenAuth.WebTest/Controllers/HomeController.cs create mode 100644 OpenAuth.WebTest/Controllers/LoginController.cs create mode 100644 OpenAuth.WebTest/Global.asax create mode 100644 OpenAuth.WebTest/Global.asax.cs create mode 100644 OpenAuth.WebTest/OpenAuth.WebTest.csproj create mode 100644 OpenAuth.WebTest/Properties/AssemblyInfo.cs create mode 100644 OpenAuth.WebTest/Scripts/_references.js create mode 100644 OpenAuth.WebTest/Scripts/bootstrap.js create mode 100644 OpenAuth.WebTest/Scripts/bootstrap.min.js create mode 100644 OpenAuth.WebTest/Scripts/jquery-1.10.2.intellisense.js create mode 100644 OpenAuth.WebTest/Scripts/jquery-1.10.2.js create mode 100644 OpenAuth.WebTest/Scripts/jquery-1.10.2.min.js create mode 100644 OpenAuth.WebTest/Scripts/jquery-1.10.2.min.map create mode 100644 OpenAuth.WebTest/Scripts/jquery.validate-vsdoc.js create mode 100644 OpenAuth.WebTest/Scripts/jquery.validate.js create mode 100644 OpenAuth.WebTest/Scripts/jquery.validate.min.js create mode 100644 OpenAuth.WebTest/Scripts/jquery.validate.unobtrusive.js create mode 100644 OpenAuth.WebTest/Scripts/jquery.validate.unobtrusive.min.js create mode 100644 OpenAuth.WebTest/Scripts/modernizr-2.6.2.js create mode 100644 OpenAuth.WebTest/Scripts/respond.js create mode 100644 OpenAuth.WebTest/Scripts/respond.min.js create mode 100644 OpenAuth.WebTest/Views/Home/Index.cshtml create mode 100644 OpenAuth.WebTest/Views/Login/Index.cshtml create mode 100644 OpenAuth.WebTest/Views/Shared/Error.cshtml create mode 100644 OpenAuth.WebTest/Views/Shared/_Layout.cshtml create mode 100644 OpenAuth.WebTest/Views/Web.config create mode 100644 OpenAuth.WebTest/Views/_ViewStart.cshtml create mode 100644 OpenAuth.WebTest/Web.Debug.config create mode 100644 OpenAuth.WebTest/Web.Release.config create mode 100644 OpenAuth.WebTest/Web.config create mode 100644 OpenAuth.WebTest/favicon.ico create mode 100644 OpenAuth.WebTest/fonts/glyphicons-halflings-regular.eot create mode 100644 OpenAuth.WebTest/fonts/glyphicons-halflings-regular.svg create mode 100644 OpenAuth.WebTest/fonts/glyphicons-halflings-regular.ttf create mode 100644 OpenAuth.WebTest/fonts/glyphicons-halflings-regular.woff create mode 100644 OpenAuth.WebTest/packages.config diff --git a/Infrastructure/ControlHelper.cs b/Infrastructure/ControlHelper.cs deleted file mode 100644 index d7d20d72..00000000 --- a/Infrastructure/ControlHelper.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Infrastructure -{ - public class ControlHelper - { - /// - /// 根据集合得到下拉框 - /// - /// 实体对象 - /// 实体集合 - /// 下拉框的id - /// 值 字段名 - /// 文本 字段名 - /// 需要选中的值 - /// 样式名称 - /// - public static string GetDropDownByList(List rList, string id, string valFiled, string nameFiled, string selected = "0", string css = "") - { - string str = " "; - return str; - } - - /// - /// 根据枚举得到下拉框 - /// - /// 枚举对象 - /// 下拉框的id - /// 需要选中的值 - /// 样式名称 - /// - public static string GetDropDownByEnum(Type type, string id, string selected = "", string css = "") - { - string str = " "; - return str; - } - } -} diff --git a/Infrastructure/CookieHelper.cs b/Infrastructure/CookieHelper.cs index d636042d..11ce0b82 100644 --- a/Infrastructure/CookieHelper.cs +++ b/Infrastructure/CookieHelper.cs @@ -13,7 +13,7 @@ using System; using System.Web; -namespace Infrastructure.Helper +namespace Infrastructure { /// /// Cookie帮助类 @@ -68,5 +68,45 @@ namespace Infrastructure.Helper } return ""; } + + /// + /// Get cookie expiry date that was set in the cookie value + /// + /// + /// + public static DateTime GetExpirationDate(HttpCookie cookie) + { + if (String.IsNullOrEmpty(cookie.Value)) + { + return DateTime.MinValue; + } + string strDateTime = cookie.Value.Substring(cookie.Value.IndexOf("|") + 1); + return Convert.ToDateTime(strDateTime); + } + + /// + /// Set cookie value using the token and the expiry date + /// + /// + /// + /// + public static string BuildCookueValue(string value, int minutes) + { + return String.Format("{0}|{1}", value, DateTime.Now.AddMinutes(minutes).ToString()); + } + + /// + /// Reads cookie value from the cookie + /// + /// + /// + public static string GetCookieValue(HttpCookie cookie) + { + if (String.IsNullOrEmpty(cookie.Value)) + { + return cookie.Value; + } + return cookie.Value.Substring(0, cookie.Value.IndexOf("|")); + } } } diff --git a/Infrastructure/GenerateId.cs b/Infrastructure/GenerateId.cs index ca73e230..c193b399 100644 --- a/Infrastructure/GenerateId.cs +++ b/Infrastructure/GenerateId.cs @@ -13,11 +13,17 @@ // *********************************************************************** using System; +using System.Security.Cryptography; namespace Infrastructure { public class GenerateId { + public static string GetGuidHash() + { + return Guid.NewGuid().ToString().GetHashCode().ToString("x"); + } + /// /// 生成一个长整型,可以转成19字节长的字符串 /// @@ -40,7 +46,16 @@ namespace Infrastructure i *= ((int)b + 1); } - return string.Format("{0:x}", i - DateTime.Now.Ticks); + return String.Format("{0:x}", i - DateTime.Now.Ticks); + } + + /// + /// 创建11位的英文与数字组合 + /// + /// System.String. + public static string ShortStr() + { + return Convert(GenerateLong()); } /// @@ -55,6 +70,8 @@ namespace Infrastructure return strDateTimeNumber + strRandomResult; } + #region private + /// /// 参考:msdn上的RNGCryptoServiceProvider例子 /// @@ -66,46 +83,44 @@ namespace Infrastructure // Create a byte array to hold the random value. byte[] randomNumber = new byte[length]; // Create a new instance of the RNGCryptoServiceProvider. - System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider(); + RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); // Fill the array with a random value. rng.GetBytes(randomNumber); // Convert the byte to an uint value to make the modulus operation easier. uint randomResult = 0x0; for (int i = 0; i < length; i++) { - randomResult |= ((uint)randomNumber[i] << ((length - 1 - i) * 8)); + randomResult |= ((uint) randomNumber[i] << ((length - 1 - i)*8)); } - return (int)(randomResult % numSeeds) + 1; + return (int) (randomResult%numSeeds) + 1; } - /// - /// 创建11位的英文与数字组合 - /// - /// System.String. - public static string ShortStr() - { - return Convert(GenerateLong()); - } + static string Seq = "s9LFkgy5RovixI1aOf8UhdY3r4DMplQZJXPqebE0WSjBn7wVzmN2Gc6THCAKut"; + /// /// 10进制转换为62进制 /// /// /// - - private static string Convert(long id) + + private static string Convert(long id) { if (id < 62) { - return Seq[(int)id].ToString(); + return Seq[(int) id].ToString(); } - int y = (int)(id % 62); - long x = (long)(id / 62); + int y = (int) (id%62); + long x = (long) (id/62); return Convert(x) + Seq[y]; } + #endregion + + + } } \ No newline at end of file diff --git a/Infrastructure/Infrastructure.csproj b/Infrastructure/Infrastructure.csproj index 6b721b56..174cf348 100644 --- a/Infrastructure/Infrastructure.csproj +++ b/Infrastructure/Infrastructure.csproj @@ -35,15 +35,29 @@ ..\packages\AutoMapper.4.1.0\lib\net45\AutoMapper.dll + + ..\packages\EnyimMemcached.2.12\lib\net35\Enyim.Caching.dll + True + ..\packages\log4net.2.0.3\lib\net40-full\log4net.dll + + ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + True + False ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + True + @@ -53,12 +67,15 @@ - + + + + @@ -67,12 +84,14 @@ + + - + + + FileSystem + Release + Any CPU + + True + False + E:\测试学习\OpenAuth.Net\Release + False + + \ No newline at end of file diff --git a/OpenAuth.Mvc/Views/Home/Index.cshtml b/OpenAuth.Mvc/Views/Home/Index.cshtml index f23c776e..20e2f066 100644 --- a/OpenAuth.Mvc/Views/Home/Index.cshtml +++ b/OpenAuth.Mvc/Views/Home/Index.cshtml @@ -126,18 +126,21 @@
    - - @foreach (var module in Model) + @if (Model != null) { + foreach (var module in Model) + { -
  • @module.Name
  • +
  • @module.Name
  • + } } +
@@ -175,7 +178,7 @@