diff --git a/Infrastructure/Helper/SessionHelper.cs b/Infrastructure/Helper/SessionHelper.cs
new file mode 100644
index 00000000..c8f705cb
--- /dev/null
+++ b/Infrastructure/Helper/SessionHelper.cs
@@ -0,0 +1,50 @@
+// ***********************************************************************
+// Assembly : Infrastructure
+// Author : Administrator
+// Created : 09-22-2015
+//
+// Last Modified By : Administrator
+// Last Modified On : 09-22-2015
+// ***********************************************************************
+//
+// Copyright (c) . All rights reserved.
+//
+// SESSION辅助类
+// ***********************************************************************
+
+using System;
+using System.Web;
+
+namespace Infrastructure.Helper
+{
+ ///
+ /// Session 帮助类
+ ///
+ public class SessionHelper
+ {
+ private static readonly string SessionUser = "SESSION_USER";
+ public static void AddSessionUser(T user)
+ {
+ HttpContext rq = HttpContext.Current;
+ rq.Session[SessionUser] = user;
+ }
+ public static T GetSessionUser()
+ {
+ try
+ {
+ HttpContext rq = HttpContext.Current;
+ return (T)rq.Session[SessionUser];
+ }
+ catch (Exception e)
+ {
+ throw new Exception(e.Message);
+ }
+ }
+
+ public static void Clear()
+ {
+ HttpContext rq = HttpContext.Current;
+ rq.Session[SessionUser] = null;
+ }
+ }
+}
diff --git a/OpenAuth.App/LoginApp.cs b/OpenAuth.App/LoginApp.cs
index 46c11ae3..c96a6faf 100644
--- a/OpenAuth.App/LoginApp.cs
+++ b/OpenAuth.App/LoginApp.cs
@@ -1,4 +1,6 @@
using System;
+using System.Collections.Generic;
+using OpenAuth.Domain;
using OpenAuth.Domain.Interface;
namespace OpenAuth.App
@@ -24,5 +26,10 @@ namespace OpenAuth.App
}
+
+ public IEnumerable LoadUsers()
+ {
+ return _repository.LoadUsers();
+ }
}
}
\ No newline at end of file
diff --git a/OpenAuth.Mvc/Controllers/AccountController.cs b/OpenAuth.Mvc/Controllers/AccountController.cs
index 570fc246..2a4fdaa3 100644
--- a/OpenAuth.Mvc/Controllers/AccountController.cs
+++ b/OpenAuth.Mvc/Controllers/AccountController.cs
@@ -1,16 +1,11 @@
-using Microsoft.AspNet.Identity;
-using Microsoft.Owin.Security;
-using OpenAuth.Mvc.Models;
-using System.Collections.Generic;
-using System.Security.Claims;
+using System;
using System.Threading.Tasks;
-using System.Web;
using System.Web.Mvc;
using Infrastructure.Helper;
using Newtonsoft.Json;
using OpenAuth.App;
-using OpenAuth.Domain;
using OpenAuth.Domain.Interface;
+using OpenAuth.Mvc.Models;
namespace OpenAuth.Mvc.Controllers
{
@@ -18,12 +13,10 @@ namespace OpenAuth.Mvc.Controllers
public class AccountController : Controller
{
private LoginApp _loginApp;
- private IUserRepository _userRepository;
- public AccountController(IUserRepository repository)
+ public AccountController()
{
- _userRepository = repository;
- _loginApp = new LoginApp(_userRepository);
+ _loginApp = (LoginApp) DependencyResolver.Current.GetService(typeof (LoginApp));
}
//
// GET: /Account/Login
@@ -44,15 +37,15 @@ namespace OpenAuth.Mvc.Controllers
if (ModelState.IsValid)
{
//直接生成登陆用户,在实际的项目中采用数据库形式
- var user = new User {Account = "admin"};
- if (user != null)
+ try
{
-
+ _loginApp.Login(model.UserName, model.Password);
+ SessionHelper.AddSessionUser(model);
return RedirectToLocal(returnUrl);
}
- else
+ catch (Exception exception)
{
- ModelState.AddModelError("", "Invalid username or password.");
+ ModelState.AddModelError("", exception.Message);
}
}
@@ -72,10 +65,7 @@ namespace OpenAuth.Mvc.Controllers
{
return View();
}
- public string LoadUsers()
- {
- return JsonConvert.SerializeObject(_userRepository.LoadUsers());
- }
+
diff --git a/OpenAuth.Mvc/Controllers/BaseController.cs b/OpenAuth.Mvc/Controllers/BaseController.cs
index 06c4a6bf..89ecf996 100644
--- a/OpenAuth.Mvc/Controllers/BaseController.cs
+++ b/OpenAuth.Mvc/Controllers/BaseController.cs
@@ -15,6 +15,7 @@
using System.Web.Mvc;
using Infrastructure.Helper;
using OpenAuth.Domain;
+using OpenAuth.Mvc.Models;
namespace OpenAuth.Mvc.Controllers
{
@@ -25,7 +26,7 @@ namespace OpenAuth.Mvc.Controllers
base.OnActionExecuting(filterContext);
#region 当Session过期自动跳出登录画面
- if (SessionHelper.GetSessionUser() == null)
+ if (SessionHelper.GetSessionUser() == null)
{
Response.Redirect("~/Account/Login");
}
diff --git a/OpenAuth.Mvc/Controllers/HomeController.cs b/OpenAuth.Mvc/Controllers/HomeController.cs
index ec463a95..564b2f4f 100644
--- a/OpenAuth.Mvc/Controllers/HomeController.cs
+++ b/OpenAuth.Mvc/Controllers/HomeController.cs
@@ -3,15 +3,28 @@ using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
+using Newtonsoft.Json;
+using OpenAuth.App;
namespace OpenAuth.Mvc.Controllers
{
public class HomeController : BaseController
{
+ private LoginApp _loginApp;
+
+ public HomeController()
+ {
+ _loginApp = (LoginApp)DependencyResolver.Current.GetService(typeof(LoginApp));
+ }
public ActionResult Index()
{
return View();
}
+ public string LoadUsers()
+ {
+ return JsonConvert.SerializeObject(_loginApp.LoadUsers());
+ }
+
}
}
\ No newline at end of file
diff --git a/OpenAuth.Mvc/Global.asax.cs b/OpenAuth.Mvc/Global.asax.cs
index f69c4dd5..ab7d6d2f 100644
--- a/OpenAuth.Mvc/Global.asax.cs
+++ b/OpenAuth.Mvc/Global.asax.cs
@@ -1,56 +1,58 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Web;
-using System.Web.Mvc;
-using System.Web.Optimization;
-using System.Web.Routing;
-using Autofac;
-using Autofac.Integration.Mvc;
-using OpenAuth.Domain.Interface;
-using OpenAuth.Repository;
-
-namespace OpenAuth.Mvc
-{
- public class MvcApplication : System.Web.HttpApplication
- {
- protected void Application_Start()
- {
- InitAutofac();
-
-
- AreaRegistration.RegisterAllAreas();
- FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
- RouteConfig.RegisterRoutes(RouteTable.Routes);
- BundleConfig.RegisterBundles(BundleTable.Bundles);
- }
-
- private static void InitAutofac()
- {
- var builder = new ContainerBuilder();
-
- builder.RegisterType().As();
-
- // Register your MVC controllers.
- builder.RegisterControllers(typeof (MvcApplication).Assembly);
-
- // OPTIONAL: Register model binders that require DI.
- builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
- builder.RegisterModelBinderProvider();
-
- // OPTIONAL: Register web abstractions like HttpContextBase.
- builder.RegisterModule();
-
- // OPTIONAL: Enable property injection in view pages.
- builder.RegisterSource(new ViewRegistrationSource());
-
- // OPTIONAL: Enable property injection into action filters.
- builder.RegisterFilterProvider();
-
- // Set the dependency resolver to be Autofac.
- var container = builder.Build();
- DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
- }
- }
-}
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Web;
+using System.Web.Mvc;
+using System.Web.Optimization;
+using System.Web.Routing;
+using Autofac;
+using Autofac.Integration.Mvc;
+using OpenAuth.App;
+using OpenAuth.Domain.Interface;
+using OpenAuth.Repository;
+
+namespace OpenAuth.Mvc
+{
+ public class MvcApplication : System.Web.HttpApplication
+ {
+ protected void Application_Start()
+ {
+ InitAutofac();
+
+
+ AreaRegistration.RegisterAllAreas();
+ FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
+ RouteConfig.RegisterRoutes(RouteTable.Routes);
+ BundleConfig.RegisterBundles(BundleTable.Bundles);
+ }
+
+ private static void InitAutofac()
+ {
+ var builder = new ContainerBuilder();
+
+ builder.RegisterType().As();
+ builder.RegisterType();
+
+ // Register your MVC controllers.
+ builder.RegisterControllers(typeof (MvcApplication).Assembly);
+
+ // OPTIONAL: Register model binders that require DI.
+ builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
+ builder.RegisterModelBinderProvider();
+
+ // OPTIONAL: Register web abstractions like HttpContextBase.
+ builder.RegisterModule();
+
+ // OPTIONAL: Enable property injection in view pages.
+ builder.RegisterSource(new ViewRegistrationSource());
+
+ // OPTIONAL: Enable property injection into action filters.
+ builder.RegisterFilterProvider();
+
+ // Set the dependency resolver to be Autofac.
+ var container = builder.Build();
+ DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
+ }
+ }
+}
diff --git a/OpenAuth.Mvc/OpenAuth.Mvc.csproj b/OpenAuth.Mvc/OpenAuth.Mvc.csproj
index 9942f133..90fa7019 100644
--- a/OpenAuth.Mvc/OpenAuth.Mvc.csproj
+++ b/OpenAuth.Mvc/OpenAuth.Mvc.csproj
@@ -17,8 +17,8 @@
false
true
-
-
+ enabled
+ disabled
@@ -107,10 +107,6 @@
True
..\packages\WebGrease.1.5.2\lib\WebGrease.dll
-
- True
- ..\packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.dll
-
@@ -119,45 +115,6 @@
..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll
-
- ..\packages\Microsoft.AspNet.Identity.Core.1.0.0\lib\net45\Microsoft.AspNet.Identity.Core.dll
-
-
- ..\packages\Microsoft.AspNet.Identity.Owin.1.0.0\lib\net45\Microsoft.AspNet.Identity.Owin.dll
-
-
- ..\packages\Microsoft.AspNet.Identity.EntityFramework.1.0.0\lib\net45\Microsoft.AspNet.Identity.EntityFramework.dll
-
-
- ..\packages\Owin.1.0\lib\net40\Owin.dll
-
-
- ..\packages\Microsoft.Owin.2.0.0\lib\net45\Microsoft.Owin.dll
-
-
- ..\packages\Microsoft.Owin.Host.SystemWeb.2.0.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll
-
-
- ..\packages\Microsoft.Owin.Security.2.0.0\lib\net45\Microsoft.Owin.Security.dll
-
-
- ..\packages\Microsoft.Owin.Security.Facebook.2.0.0\lib\net45\Microsoft.Owin.Security.Facebook.dll
-
-
- ..\packages\Microsoft.Owin.Security.Cookies.2.0.0\lib\net45\Microsoft.Owin.Security.Cookies.dll
-
-
- ..\packages\Microsoft.Owin.Security.OAuth.2.0.0\lib\net45\Microsoft.Owin.Security.OAuth.dll
-
-
- ..\packages\Microsoft.Owin.Security.Google.2.0.0\lib\net45\Microsoft.Owin.Security.Google.dll
-
-
- ..\packages\Microsoft.Owin.Security.Twitter.2.0.0\lib\net45\Microsoft.Owin.Security.Twitter.dll
-
-
- ..\packages\Microsoft.Owin.Security.MicrosoftAccount.2.0.0\lib\net45\Microsoft.Owin.Security.MicrosoftAccount.dll
-
diff --git a/OpenAuth.Mvc/Properties/AssemblyInfo.cs b/OpenAuth.Mvc/Properties/AssemblyInfo.cs
index f5da915c..d67e7fa4 100644
--- a/OpenAuth.Mvc/Properties/AssemblyInfo.cs
+++ b/OpenAuth.Mvc/Properties/AssemblyInfo.cs
@@ -1,35 +1,35 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// 有关程序集的常规信息是通过以下项进行控制的
-// 控制。更改这些特性值可修改
-// 与程序集关联的信息。
-[assembly: AssemblyTitle("OpenAuth.Mvc")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("OpenAuth.Mvc")]
-[assembly: AssemblyCopyright("版权所有(C) 2015")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// 将 ComVisible 设置为 false 将使此程序集中的类型
-// 对 COM 组件不可见。如果需要
-// 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。
-[assembly: ComVisible(false)]
-
-// 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID
-[assembly: Guid("f8e0455e-d7e7-4ee0-b6df-ba8b36b3d4a5")]
-
-// 程序集的版本信息由下列四个值组成:
-//
-// 主版本
-// 次版本
-// 内部版本号
-// 修订版本
-//
-// 你可以指定所有值,也可以让修订版本和内部版本号采用默认值,
-// 方法是按如下所示使用 "*":
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的常规信息是通过以下项进行控制的
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("OpenAuth.Mvc")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("OpenAuth.Mvc")]
+[assembly: AssemblyCopyright("版权所有(C) 2015")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 将使此程序集中的类型
+// 对 COM 组件不可见。如果需要
+// 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID
+[assembly: Guid("f8e0455e-d7e7-4ee0-b6df-ba8b36b3d4a5")]
+
+// 程序集的版本信息由下列四个值组成:
+//
+// 主版本
+// 次版本
+// 内部版本号
+// 修订版本
+//
+// 你可以指定所有值,也可以让修订版本和内部版本号采用默认值,
+// 方法是按如下所示使用 "*":
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/OpenAuth.Mvc/Views/Home/Index.cshtml b/OpenAuth.Mvc/Views/Home/Index.cshtml
index a4ce7299..ed1275fb 100644
--- a/OpenAuth.Mvc/Views/Home/Index.cshtml
+++ b/OpenAuth.Mvc/Views/Home/Index.cshtml
@@ -1,140 +1,140 @@
-@{
- Layout = "~/Views/Shared/_Layout.cshtml";
-}
-
-
-
-
-
-
-
+
+
+
\ No newline at end of file
diff --git a/OpenAuth.Mvc/Web.config b/OpenAuth.Mvc/Web.config
index eab9aa91..d917e4db 100644
--- a/OpenAuth.Mvc/Web.config
+++ b/OpenAuth.Mvc/Web.config
@@ -1,67 +1,67 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+