mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-19 10:08:04 +08:00
v1.2版,全面实现SSO登陆
This commit is contained in:
@@ -24,21 +24,20 @@ using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.App.SSO;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class BaseController : Controller
|
||||
public class BaseController : SSOController
|
||||
{
|
||||
protected BjuiResponse BjuiResponse = new BjuiResponse();
|
||||
|
||||
protected override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
base.OnActionExecuting(filterContext);
|
||||
|
||||
var loginUser = AutofacExt.GetFromFac<LoginApp>().GetLoginUser();
|
||||
if (!User.Identity.IsAuthenticated)
|
||||
{
|
||||
filterContext.Result = new RedirectResult("/Login/Index");
|
||||
return;
|
||||
}
|
||||
|
||||
var controllername = Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
|
||||
var actionname = filterContext.ActionDescriptor.ActionName.ToLower();
|
||||
|
||||
@@ -69,7 +68,6 @@ namespace OpenAuth.Mvc.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
base.OnActionExecuting(filterContext);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Security;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.App.SSO;
|
||||
using OpenAuth.Mvc.Models;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
@@ -28,8 +25,18 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Login(username, password);
|
||||
return RedirectToAction("Index", "Home");
|
||||
var token = AuthUtil.Login("670b14728ad9902aecba32e22fa4f6bd", username, password);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
return Redirect("/home/index?Token=" + token);
|
||||
else
|
||||
{
|
||||
var response = new BjuiResponse
|
||||
{
|
||||
statusCode = "300",
|
||||
message = "登陆失败"
|
||||
};
|
||||
return View(response);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -50,8 +57,14 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.LoginByDev();
|
||||
return RedirectToAction("Index", "Home");
|
||||
var token = AuthUtil.Login("670b14728ad9902aecba32e22fa4f6bd", "System","");
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
return Redirect("/home/index?Token=" + token);
|
||||
else
|
||||
{
|
||||
return RedirectToAction("Index", "Login");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -63,7 +76,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
public ActionResult Logout()
|
||||
{
|
||||
|
||||
FormsAuthentication.SignOut();
|
||||
AuthUtil.Logout();
|
||||
return RedirectToAction("Index", "Login");
|
||||
}
|
||||
}
|
||||
|
@@ -24,39 +24,39 @@ namespace OpenAuth.Mvc
|
||||
}
|
||||
|
||||
|
||||
//protected void Application_Error(object sender, EventArgs e)
|
||||
//{
|
||||
// var app = (MvcApplication)sender;
|
||||
// var context = app.Context;
|
||||
// var ex = app.Server.GetLastError();
|
||||
// LogHelper.Fatal(ex.Message);
|
||||
protected void Application_Error(object sender, EventArgs e)
|
||||
{
|
||||
var app = (MvcApplication)sender;
|
||||
var context = app.Context;
|
||||
var ex = app.Server.GetLastError();
|
||||
LogHelper.Fatal(ex.Message);
|
||||
|
||||
// context.Response.Clear();
|
||||
// context.ClearError();
|
||||
// var httpException = ex as HttpException;
|
||||
// var routeData = new RouteData();
|
||||
// routeData.Values["controller"] = "error";
|
||||
// routeData.Values["exception"] = ex;
|
||||
// routeData.Values["action"] = "http500";
|
||||
// if (httpException != null)
|
||||
// {
|
||||
context.Response.Clear();
|
||||
context.ClearError();
|
||||
var httpException = ex as HttpException;
|
||||
var routeData = new RouteData();
|
||||
routeData.Values["controller"] = "error";
|
||||
routeData.Values["exception"] = ex;
|
||||
routeData.Values["action"] = "http500";
|
||||
if (httpException != null)
|
||||
{
|
||||
|
||||
|
||||
// switch (httpException.GetHttpCode())
|
||||
// {
|
||||
// case 404:
|
||||
// routeData.Values["action"] = "http404";
|
||||
// break;
|
||||
// case 401: //没有登录
|
||||
// routeData.Values["action"] = "http401";
|
||||
// break;
|
||||
// case 400: //演示版本,没有执行的权限
|
||||
// routeData.Values["action"] = "DemoError";
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// IController controller = new ErrorController();
|
||||
// controller.Execute(new RequestContext(new HttpContextWrapper(context), routeData));
|
||||
//}
|
||||
switch (httpException.GetHttpCode())
|
||||
{
|
||||
case 404:
|
||||
routeData.Values["action"] = "http404";
|
||||
break;
|
||||
case 401: //没有登录
|
||||
routeData.Values["action"] = "http401";
|
||||
break;
|
||||
case 400: //演示版本,没有执行的权限
|
||||
routeData.Values["action"] = "DemoError";
|
||||
break;
|
||||
}
|
||||
}
|
||||
IController controller = new ErrorController();
|
||||
controller.Execute(new RequestContext(new HttpContextWrapper(context), routeData));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user