101 lines
3.5 KiB
C#
101 lines
3.5 KiB
C#
using Microsoft.AspNet.Identity;
|
|
using PagedList;
|
|
using Qcarbon.Database.adminCheck;
|
|
using Qcarbon.Interfaces.adminCheck;
|
|
using Qcarbon.ViewModels.admin;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using System.Web.Routing;
|
|
using Weee.DAL;
|
|
using Weee.Models;
|
|
|
|
namespace Weee.Areas.Admin.Controllers
|
|
{
|
|
public class AccessKeyController : AdminControllerBase
|
|
{
|
|
protected IadminCheckService _adminCheckService;
|
|
public AccessKeyController(WeeeDataContext d) : base(d)
|
|
{
|
|
}
|
|
protected override void Initialize(RequestContext requestContext)
|
|
{
|
|
base.Initialize(requestContext);
|
|
var userid = User.Identity.GetUserId();
|
|
_adminCheckService = new adminCheckService(db, userid);
|
|
}
|
|
|
|
// GET: Admin/AccessKey
|
|
public ActionResult Index(int page = 1)//, string searchString = "")
|
|
{
|
|
accessKeyIndexVM viewModel = new accessKeyIndexVM();
|
|
string curUrl;
|
|
curUrl = Request.Url.AbsoluteUri.Replace("/admin/AccessKey", "");
|
|
try
|
|
{
|
|
viewModel.curAdminAccess = _adminCheckService.getAdminAccess();
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
ModelState.AddModelError("", ex.Message);
|
|
}
|
|
if (!ModelState.IsValid)
|
|
return View(viewModel);
|
|
viewModel.adminAccessHis = _adminCheckService.getAdminAccessHis();
|
|
viewModel.curAdminAccessUsage = _adminCheckService.getAdminAccessUsage(curUrl);
|
|
//var qry = db.AdminAccessHistory.OrderByDescending(a => a.ID)
|
|
// .AsQueryable();//.ToList();
|
|
//if (!qry.Any())
|
|
// viewModel.adminAccessHis = new List<AdminAccessHistory>();
|
|
//else
|
|
//{
|
|
// var onePage = qry.ToPagedList(page, 10);
|
|
// viewModel.adminAccessHis = onePage;
|
|
//}
|
|
return View(viewModel);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult Index(accessKeyIndexVM viewModel)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
return View(viewModel);
|
|
string err;
|
|
string curUrl;
|
|
curUrl = Request.Url.AbsoluteUri.Replace("/admin/AccessKey","");
|
|
viewModel.adminAccessHis = _adminCheckService.getAdminAccessHis();
|
|
viewModel.curAdminAccessUsage = _adminCheckService.getAdminAccessUsage(curUrl);
|
|
GoldenKey gk = new GoldenKey();
|
|
//curUrl = Request.RawUrl;
|
|
//string s2 = Request.Url.OriginalString;
|
|
//string s3 = Request.Url.ToString();
|
|
err = _adminCheckService.parsingKeyText(viewModel.keyText, curUrl
|
|
, ref gk);
|
|
if (!string.IsNullOrWhiteSpace(err))
|
|
{
|
|
ViewBag.errMsg = err;
|
|
return View(viewModel);
|
|
}
|
|
bool verified = _adminCheckService.verifyGoldenKeyHash(gk);
|
|
if (verified)
|
|
{
|
|
err = _adminCheckService.setAdminAccess(curUrl, gk);
|
|
if (string.IsNullOrWhiteSpace(err))
|
|
{
|
|
viewModel.curAdminAccess = _adminCheckService.getAdminAccess();
|
|
ViewBag.OKmsg = "金鑰匯入成功";
|
|
}
|
|
Thread.Sleep(0);
|
|
}
|
|
else
|
|
ViewBag.errMsg = "金鑰已被竄改,匯入失敗";
|
|
return View(viewModel);
|
|
}
|
|
|
|
}
|
|
}
|