增加演示版本支持,在web.config中配置即可;

增加自定义出差处理,参考ErrorController
This commit is contained in:
yubaolee
2016-04-25 11:53:21 +08:00
parent 3037c3b1f6
commit 6181f9dd47
22 changed files with 182 additions and 33 deletions

View File

@@ -38,7 +38,7 @@ namespace OpenAuth.App
{ {
if (!HttpContext.Current.User.Identity.IsAuthenticated) if (!HttpContext.Current.User.Identity.IsAuthenticated)
{ {
throw new Exception("未登录"); throw new HttpException(401,"未登录");
} }
string username = HttpContext.Current.User.Identity.Name; string username = HttpContext.Current.User.Identity.Name;
_service.GetUserAccessed(username); _service.GetUserAccessed(username);

View File

@@ -23,6 +23,11 @@ $(document).ready(function () {
firstId: $('#firstId').val(), firstId: $('#firstId').val(),
secIds: ids secIds: ids
}, function (json) { }, function (json) {
if (json.statusCode != "200") {
json = $.parseJSON(json);
$(this).alertmsg('warn', json.message);
return;
}
selected.reLoad(); selected.reLoad();
}); });
}); });
@@ -35,6 +40,11 @@ $(document).ready(function () {
firstId: $('#firstId').val(), firstId: $('#firstId').val(),
secIds: ids secIds: ids
}, function (json) { }, function (json) {
if (json.statusCode != "200") {
json = $.parseJSON(json);
$(this).alertmsg('warn', json.message);
return;
}
selected.reLoad(); selected.reLoad();
}); });
}); });

View File

@@ -23,6 +23,11 @@ $(document).ready(function () {
firstId: $('#firstId').val(), firstId: $('#firstId').val(),
secIds: ids secIds: ids
}, function (json) { }, function (json) {
json = $.parseJSON(json);
if (json.statusCode != "200") {
$(this).alertmsg('warn', json.message);
return;
}
dlgList.reload(); dlgList.reload();
}); });
}); });
@@ -35,6 +40,11 @@ $(document).ready(function () {
firstId: $('#firstId').val(), firstId: $('#firstId').val(),
secIds: ids secIds: ids
}, function (json) { }, function (json) {
json = $.parseJSON(json);
if (json.statusCode != "200") {
$(this).alertmsg('warn', json.message);
return;
}
dlgList.reload(); dlgList.reload();
}); });
}); });

View File

@@ -23,6 +23,11 @@ $(document).ready(function () {
firstId: $('#firstId').val(), firstId: $('#firstId').val(),
secIds: ids secIds: ids
}, function (json) { }, function (json) {
if (json.statusCode != "200") {
json = $.parseJSON(json);
$(this).alertmsg('warn', json.message);
return;
}
selected.reLoad(); selected.reLoad();
}); });
}); });
@@ -35,6 +40,11 @@ $(document).ready(function () {
firstId: $('#firstId').val(), firstId: $('#firstId').val(),
secIds: ids secIds: ids
}, function (json) { }, function (json) {
if (json.statusCode != "200") {
json = $.parseJSON(json);
$(this).alertmsg('warn', json.message);
return;
}
selected.reLoad(); selected.reLoad();
}); });
}); });

View File

@@ -23,6 +23,11 @@ $(document).ready(function () {
firstId: $('#firstId').val(), firstId: $('#firstId').val(),
secIds: ids secIds: ids
}, function (json) { }, function (json) {
if (json.statusCode != "200") {
json = $.parseJSON(json);
$(this).alertmsg('warn', json.message);
return;
}
dlgList.reload(); dlgList.reload();
}); });
}); });
@@ -35,6 +40,11 @@ $(document).ready(function () {
firstId: $('#firstId').val(), firstId: $('#firstId').val(),
secIds: ids secIds: ids
}, function (json) { }, function (json) {
if (json.statusCode != "200") {
json = $.parseJSON(json);
$(this).alertmsg('warn', json.message);
return;
}
dlgList.reload(); dlgList.reload();
}); });
}); });

View File

@@ -214,7 +214,11 @@ var editDlg = function () {
if (!v) return; //验证没通过 if (!v) return; //验证没通过
$("#editForm").bjuiajax('ajaxForm', { $("#editForm").bjuiajax('ajaxForm', {
reload: false, reload: false,
callback:function(json) { callback: function (json) {
if (json.statusCode == "400") {
$(this).alertmsg('warn', json.message);
return null;
}
list.reload(); list.reload();
ztree.reload(); ztree.reload();
} }

View File

@@ -39,9 +39,12 @@ $(document).ready(function () {
}, },
function (data) { function (data) {
data = $.parseJSON(data); data = $.parseJSON(data);
if (data.statusCode == "200") { if (data.statusCode != "200") {
thisDlg.reload(); $(this).alertmsg('warn', json.message);
return;
} }
thisDlg.reload();
}); });
}); });
}); });
@@ -185,6 +188,10 @@ var editEleDlg = function () {
$("#editElementForm").bjuiajax('ajaxForm', { $("#editElementForm").bjuiajax('ajaxForm', {
reload: false, reload: false,
callback: function (json) { callback: function (json) {
if (json.statusCode != "200") {
$(this).alertmsg('warn', json.message);
return;
}
thisDlg.reload(); thisDlg.reload();
} }
}); });

View File

@@ -243,6 +243,10 @@ var editDlg = function () {
$("#editForm").bjuiajax('ajaxForm', { $("#editForm").bjuiajax('ajaxForm', {
reload: false, reload: false,
callback: function (json) { callback: function (json) {
if (json.statusCode != "200") {
$(this).alertmsg('warn', json.message);
return;
}
list.reload(); list.reload();
ztree.reload(); ztree.reload();
} }

View File

@@ -211,6 +211,10 @@ var editDlg = function () {
$("#editForm").bjuiajax('ajaxForm', { $("#editForm").bjuiajax('ajaxForm', {
reload: false, reload: false,
callback: function (json) { callback: function (json) {
if (json.statusCode != "200") {
$(this).alertmsg('warn', json.message);
return;
}
list.reload(); list.reload();
ztree.reload(); ztree.reload();
} }

View File

@@ -201,6 +201,10 @@ var editDlg = function () {
$("#editForm").bjuiajax('ajaxForm', { $("#editForm").bjuiajax('ajaxForm', {
reload: false, reload: false,
callback: function (json) { callback: function (json) {
if (json.statusCode != "200") {
$(this).alertmsg('warn', json.message);
return;
}
list.reload(); list.reload();
ztree.reload(); ztree.reload();
} }

View File

@@ -192,6 +192,10 @@ var editDlg = function () {
$("#editForm").bjuiajax('ajaxForm', { $("#editForm").bjuiajax('ajaxForm', {
reload: false, reload: false,
callback: function (json) { callback: function (json) {
if (json.statusCode != "200") {
$(this).alertmsg('warn', json.message);
return;
}
list.reload(); list.reload();
ztree.reload(); ztree.reload();
} }

View File

@@ -203,6 +203,10 @@ var editDlg = function () {
$("#editForm").bjuiajax('ajaxForm', { $("#editForm").bjuiajax('ajaxForm', {
reload: false, reload: false,
callback: function (json) { callback: function (json) {
if (json.statusCode != "200") {
$(this).alertmsg('warn', json.message);
return;
}
list.reload(); list.reload();
ztree.reload(); ztree.reload();
} }

View File

@@ -16,13 +16,12 @@
// </summary> // </summary>
// *********************************************************************** // ***********************************************************************
using Infrastructure.Helper;
using OpenAuth.App.ViewModel;
using OpenAuth.Mvc.Models; using OpenAuth.Mvc.Models;
using System; using System;
using System.Diagnostics; using System.Configuration;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using OpenAuth.App; using OpenAuth.App;
@@ -60,6 +59,16 @@ namespace OpenAuth.Mvc.Controllers
ViewBag.Module = module; //为View显示服务主要是为了显示按钮 ViewBag.Module = module; //为View显示服务主要是为了显示按钮
} }
var version = ConfigurationManager.AppSettings["version"];
if (version == "demo")
{
HttpPostAttribute hobbyAttr = (HttpPostAttribute)Attribute.GetCustomAttribute(function, typeof(HttpPostAttribute));
if (actionname.Contains("del") || hobbyAttr != null) //客户端提交数据
{
throw new HttpException(400, "演示版本,不能进行该操作,当前模块:" + controllername +"/" +actionname);
}
}
base.OnActionExecuting(filterContext); base.OnActionExecuting(filterContext);
} }
} }

View File

@@ -45,11 +45,6 @@ namespace OpenAuth.Mvc.Controllers
return JsonHelper.Instance.Serialize(models); return JsonHelper.Instance.Serialize(models);
} }
public ActionResult Add(int id = 0)
{
return View(_app.Find(id));
}
//添加或修改Category //添加或修改Category
[HttpPost] [HttpPost]
public string Add(Category model) public string Add(Category model)

View File

@@ -1,17 +1,54 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Web; using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using Infrastructure;
using OpenAuth.Mvc.Models;
namespace OpenAuth.Mvc.Controllers namespace OpenAuth.Mvc.Controllers
{ {
public class ErrorController : Controller public class ErrorController : Controller
{ {
// GET: Error public ActionResult Http404()
public ActionResult NoAccess()
{ {
return View(); return Content("貌似URL不在~~", "text/plain");
}
/// <summary>
/// 演示版本禁止提交
/// </summary>
public string DemoError()
{
Response.Charset = "utf-8";
var response = new BjuiResponse
{
statusCode = "400",
message = "演示版本,不能进行此操作"
};
return JsonHelper.Instance.Serialize(response);
}
/// <summary>
/// 没有登录
/// </summary>
/// <returns>ActionResult.</returns>
public ActionResult Http401()
{
return RedirectToAction("Index", "Login");
}
public string Http500()
{
Response.Charset = "utf-8";
var response = new BjuiResponse
{
statusCode = "500",
message = "服务器内部错误,请联系管理员"
};
return JsonHelper.Instance.Serialize(response);
} }
} }
} }

View File

@@ -22,7 +22,7 @@ using System.Web.Mvc;
namespace OpenAuth.Mvc.Controllers namespace OpenAuth.Mvc.Controllers
{ {
public class ModuleElementManagerController : Controller public class ModuleElementManagerController : BaseController
{ {
private readonly BjuiResponse _bjuiResponse = new BjuiResponse(); private readonly BjuiResponse _bjuiResponse = new BjuiResponse();
private ModuleElementManagerApp _app; private ModuleElementManagerApp _app;
@@ -31,18 +31,18 @@ namespace OpenAuth.Mvc.Controllers
{ {
_app = AutofacExt.GetFromFac<ModuleElementManagerApp>(); _app = AutofacExt.GetFromFac<ModuleElementManagerApp>();
} }
[Anonymous]
public ActionResult Index(int id) public ActionResult Index(int id)
{ {
ViewBag.ModuleId = id; ViewBag.ModuleId = id;
return View(); return View();
} }
[Anonymous]
public ActionResult Get(int moduleId = 0) public ActionResult Get(int moduleId = 0)
{ {
return Json(_app.LoadByModuleId(moduleId)); return Json(_app.LoadByModuleId(moduleId));
} }
[Anonymous]
[HttpPost] [HttpPost]
public string AddOrEditButton(ModuleElement button) public string AddOrEditButton(ModuleElement button)
{ {
@@ -57,7 +57,7 @@ namespace OpenAuth.Mvc.Controllers
} }
return JsonHelper.Instance.Serialize(_bjuiResponse); return JsonHelper.Instance.Serialize(_bjuiResponse);
} }
[Anonymous]
public string Del(string moduleElements) public string Del(string moduleElements)
{ {
try try
@@ -80,13 +80,14 @@ namespace OpenAuth.Mvc.Controllers
/// <param name="firstId">The first identifier.</param> /// <param name="firstId">The first identifier.</param>
/// <param name="key">The key.</param> /// <param name="key">The key.</param>
/// <returns>ActionResult.</returns> /// <returns>ActionResult.</returns>
[Anonymous]
public ActionResult AssignModuleElement(int firstId, string key) public ActionResult AssignModuleElement(int firstId, string key)
{ {
ViewBag.FirstId = firstId; ViewBag.FirstId = firstId;
ViewBag.ModuleType = key; ViewBag.ModuleType = key;
return View(); return View();
} }
[Anonymous]
public string LoadWithAccess(int tId, int firstId, string key) public string LoadWithAccess(int tId, int firstId, string key)
{ {
return JsonHelper.Instance.Serialize(_app.LoadWithAccess(key, firstId, tId)); return JsonHelper.Instance.Serialize(_app.LoadWithAccess(key, firstId, tId));

View File

@@ -23,11 +23,6 @@ namespace OpenAuth.Mvc.Controllers
return View(); return View();
} }
public ActionResult Add(int id = 0)
{
return View(_app.Find(id));
}
//添加或修改角色 //添加或修改角色
[HttpPost] [HttpPost]
public string Add(Role role) public string Add(Role role)

View File

@@ -1,8 +1,10 @@
using System.Web; using System;
using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using System.Web.Optimization; using System.Web.Optimization;
using System.Web.Routing; using System.Web.Routing;
using Infrastructure; using Infrastructure;
using OpenAuth.Mvc.Controllers;
namespace OpenAuth.Mvc namespace OpenAuth.Mvc
{ {
@@ -20,5 +22,41 @@ namespace OpenAuth.Mvc
LogHelper.Log("启动Web"); LogHelper.Log("启动Web");
} }
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)
{
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));
}
} }
} }

View File

@@ -676,7 +676,7 @@
<Content Include="Views\ModuleManager\Index.cshtml" /> <Content Include="Views\ModuleManager\Index.cshtml" />
<Content Include="Views\ModuleManager\Assign.cshtml" /> <Content Include="Views\ModuleManager\Assign.cshtml" />
<Content Include="Views\Home\MenuHeader.cshtml" /> <Content Include="Views\Home\MenuHeader.cshtml" />
<None Include="Views\ModuleElementManager\Index.cshtml" /> <Content Include="Views\ModuleElementManager\Index.cshtml" />
<Content Include="Views\ModuleElementManager\AssignModuleElement.cshtml" /> <Content Include="Views\ModuleElementManager\AssignModuleElement.cshtml" />
<Content Include="Views\UserManager\Index.cshtml" /> <Content Include="Views\UserManager\Index.cshtml" />
<Content Include="Views\RoleManager\Index.cshtml" /> <Content Include="Views\RoleManager\Index.cshtml" />

View File

@@ -12,8 +12,8 @@
基于经典DDD架构的权限管理系统  基于经典DDD架构的权限管理系统 
</h4> </h4>
<div style=" margin-top:22px; padding-left:6px;"> <div style="margin-top: 22px; padding-left: 6px;">
<div class="alert alert-danger">QQ群484498493</div>
<span style="padding-left: 30px;">官方博客:</span> <span style="padding-left: 30px;">官方博客:</span>
<a href="http://www.cnblogs.com/yubaolee/" target="_blank">http://www.cnblogs.com/yubaolee/</a> <a href="http://www.cnblogs.com/yubaolee/" target="_blank">http://www.cnblogs.com/yubaolee/</a>
</div> </div>

View File

@@ -232,7 +232,10 @@
</form> </form>
</div> </div>
</div> </div>
<div class="bottom">Copyright &copy; 2015 <a href="/Login/LoginByDev">基于精典DDD的权限管理 - 点击以开发者账号登录</a></div> <div class="bottom">
可以用admin(密码:admin) /test(密码:test) 查看不同账号登陆情况<br>
Copyright &copy; 2015 <a href="/Login/LoginByDev">基于精典DDD的权限管理 - 点击以开发者账号登录</a>
</div>
</div> </div>
</body> </body>
</html> </html>

View File

@@ -58,14 +58,14 @@
<add key="webpages:Enabled" value="false" /> <add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" /> <add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" />
<!--系统版本,如果值为演示版本"demo"则关闭部分post功能-->
<add key="version" value=""/>
</appSettings> </appSettings>
<system.web> <system.web>
<authentication mode="Forms" /> <authentication mode="Forms" />
<compilation debug="true" targetFramework="4.5" /> <compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" /> <httpRuntime targetFramework="4.5" />
<sessionState mode="InProc" timeout="60"/> <sessionState mode="InProc" timeout="60"/>
<customErrors mode="On" defaultRedirect="/Login/Index">
</customErrors>
</system.web> </system.web>
<system.webServer> <system.webServer>
<modules> <modules>