From 57554f1ae3a4f5fccf174a1215cfe662d065af45 Mon Sep 17 00:00:00 2001
From: falcon <9504402@qq.com>
Date: Mon, 18 May 2020 11:09:31 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E9=A1=B5=E9=9D=A2=E5=BA=94?=
=?UTF-8?q?=E7=94=A8=E7=AE=A1=E7=90=86=E3=80=81=E7=94=A8=E6=88=B7=E7=AE=A1?=
=?UTF-8?q?=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
FAuth/Controllers/api/ApiControllerBase.cs | 2 -
FAuth/Controllers/api/AppController.cs | 11 +-
FAuth/Controllers/api/UserController.cs | 66 +-
FAuth/Controllers/web/AppController.cs | 32 +
FAuth/Controllers/web/UserController.cs | 9 -
FAuth/Models/ApiBoolResult.cs | 13 +
FAuth/Models/UserInfo.cs | 4 +
FAuth/Startup.cs | 2 +-
FAuth/Views/App/AddNew.cshtml | 28 +
FAuth/Views/App/Index.cshtml | 77 +-
FAuth/Views/Shared/_Layout.cshtml | 76 +-
FAuth/Views/User/Index.cshtml | 88 +-
FAuth/wwwroot/css/site.css | 2 +-
FAuth/wwwroot/js/site.js | 36 +-
FAuth/wwwroot/js/vmTemplate.js | 7 +
FAuth/wwwroot/lib/vue/vue.js | 11972 +++++++++++++++++++
FAuth/wwwroot/lib/vue/vue.min.js | 6 +
17 files changed, 12341 insertions(+), 90 deletions(-)
create mode 100644 FAuth/Models/ApiBoolResult.cs
create mode 100644 FAuth/Views/App/AddNew.cshtml
create mode 100644 FAuth/wwwroot/js/vmTemplate.js
create mode 100644 FAuth/wwwroot/lib/vue/vue.js
create mode 100644 FAuth/wwwroot/lib/vue/vue.min.js
diff --git a/FAuth/Controllers/api/ApiControllerBase.cs b/FAuth/Controllers/api/ApiControllerBase.cs
index 3c225d4..0d634bf 100644
--- a/FAuth/Controllers/api/ApiControllerBase.cs
+++ b/FAuth/Controllers/api/ApiControllerBase.cs
@@ -1,9 +1,7 @@
using System;
-using System.Threading.Tasks;
using FAuth.Extensions;
using FAuth.Models;
using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
namespace FAuth.Controllers.api
diff --git a/FAuth/Controllers/api/AppController.cs b/FAuth/Controllers/api/AppController.cs
index 7395501..53f6b6f 100644
--- a/FAuth/Controllers/api/AppController.cs
+++ b/FAuth/Controllers/api/AppController.cs
@@ -51,14 +51,14 @@ namespace FAuth.Controllers.api
///
/// 删除一个应用
///
- /// 应用名称
+ /// 应用编号
/// 删除结果
[HttpPost]
- public bool RemoveApp(string appName) {
- if(appName.IsNullOrEmpty()) {
- throw new ApiArgumentNullException(nameof(appName));
+ public bool RemoveApp(int id) {
+ if(id == 1) {
+ throw new ApiException("系统应用不可以删除");
}
- var qu = this.Db.Apps.Where(m => m.Name == appName);
+ var qu = this.Db.Apps.Where(m => m.Id == id);
foreach(var item in qu) {
this.Db.Entry(item).State = EntityState.Deleted;
}
@@ -95,6 +95,7 @@ namespace FAuth.Controllers.api
if(this.Account.IsNotSystemAdmin(adminTicket)) {
throw new ApiException("需要提供管理员票据");
}
+ var list = this.Cache.GetObj>("");
var qu = this.Db.Apps;
return qu.ToList();
}
diff --git a/FAuth/Controllers/api/UserController.cs b/FAuth/Controllers/api/UserController.cs
index 57daa6b..36e8142 100644
--- a/FAuth/Controllers/api/UserController.cs
+++ b/FAuth/Controllers/api/UserController.cs
@@ -113,21 +113,36 @@ namespace FAuth.Controllers.api
///
/// 获取用户信息列表
///
+ /// 登录用户名
+ /// 用户名
/// 用户信息列表
[HttpGet]
[ProducesResponseType(typeof(IEnumerable),200)]
- public IEnumerable GetUsers() {
- var key = "FAuth:Users";
- var obj = this.Cache?.GetObj>(key);
- if(obj == null) {
- obj = this.Db.Users
- .Select(m => new UserInfo {
- Id = m.Id,
- UserName = m.UserName,
- }).ToList();
- this.Cache?.SetCache(key,obj,new TimeSpan(0,5,0));
+ public IEnumerable GetUsers(string userName,string name) {
+ var key = $"FAuth:Users:userName:{userName}:name:{name}";
+ List result = null;// this.Cache?.GetObj>(key);
+ if(result == null) {
+ var qu = this.Db.Users
+ .Select(m => new UserInfo {
+ Id = m.Id,
+ UserName = m.UserName,
+ Name = m.Name,
+ LastLoginDatetime = m.LastLoginDatetime,
+ Status =
+ !m.LastLoginDatetime.HasValue ? "未登陆" :
+ !m.LastLogoutDatetime.HasValue ? "在线" :
+ m.LastLoginDatetime.Value > m.LastLogoutDatetime.Value ? "在线" : "离线",
+ });
+ if(userName.IsNotNullOrEmpty()) {
+ qu = qu.Where(m => m.UserName == userName);
+ }
+ if(name.IsNotNullOrEmpty()) {
+ qu = qu.Where(m => m.Name == name);
+ }
+ result = qu.ToList();
+ this.Cache?.SetCache(key,result,new TimeSpan(0,5,0));
}
- return obj;
+ return result;
}
///
@@ -163,7 +178,8 @@ namespace FAuth.Controllers.api
/// 用户密码
/// 是否成功
[HttpPost]
- public bool AddNewUser(string adminTicket,string userName,string name,string password) {
+ [ProducesResponseType(typeof(UserInfo),200)]
+ public UserInfo AddNewUser(string adminTicket,string userName,string name,string password) {
if(adminTicket is null)
throw new ApiArgumentNullException(nameof(adminTicket));
if(userName is null)
@@ -186,7 +202,12 @@ namespace FAuth.Controllers.api
this.Db.Entry(nUser).State = EntityState.Added;
this.Db.SaveChangesAsync().Wait();
this.Logger.LogInformation($"用户{nUser.Id}:{nUser.UserName}:{nUser.Name}添加成功!");
- return true;
+ return new UserInfo {
+ Id = nUser.Id,
+ UserName = nUser.UserName,
+ Name = nUser.Name,
+ LastLoginDatetime = nUser.LastLoginDatetime,
+ };
}
///
@@ -218,5 +239,24 @@ namespace FAuth.Controllers.api
this.Db.SaveChangesAsync().Wait();
return true;
}
+
+ ///
+ /// 删除用户
+ ///
+ /// 管理员凭据
+ /// 要删除的用户编号
+ /// 删除结果
+ [HttpPost, ProducesResponseType(typeof(ApiBoolResult),200)]
+ public ApiBoolResult RemoveUser(string adminTicket,int id) {
+ var user = this.Account.TicketDryptor.Decrypt(adminTicket);
+ if(user.Id == id) {
+ throw new ApiException("当前用户不能删除");
+ }
+ this.Db.Users.Attach(new FUser {
+ Id = id,
+ }).State = EntityState.Deleted;
+ this.Db.SaveChangesAsync().Wait();
+ return new ApiBoolResult { Result = true };
+ }
}
}
diff --git a/FAuth/Controllers/web/AppController.cs b/FAuth/Controllers/web/AppController.cs
index e69de29..945aeee 100644
--- a/FAuth/Controllers/web/AppController.cs
+++ b/FAuth/Controllers/web/AppController.cs
@@ -0,0 +1,32 @@
+using System;
+using Falcon.Extend;
+using FAuth.Extensions;
+using FAuth.Extensions.Account;
+using FAuth.Models;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using api = FAuth.Controllers.api;
+
+namespace FAuth.Controllers.web
+{
+ ///
+ /// Ӧÿ
+ ///
+ public class AppController:WebControllerBase
+ {
+ public AccountHelper Account { get; set; }
+
+ public AppController(ILogger logger,IServiceProvider service) : base(logger,service) {
+ this.Account = this.Services.GetService();
+ }
+
+ public IActionResult Index() {
+ return PartialView();
+ }
+
+ public IActionResult AddNew() {
+ return PartialView();
+ }
+ }
+}
\ No newline at end of file
diff --git a/FAuth/Controllers/web/UserController.cs b/FAuth/Controllers/web/UserController.cs
index bf7a717..e687059 100644
--- a/FAuth/Controllers/web/UserController.cs
+++ b/FAuth/Controllers/web/UserController.cs
@@ -1,15 +1,6 @@
using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
-using FAuth.Models;
-using FAuth.Extensions;
-using Microsoft.Extensions.DependencyInjection;
-using api = FAuth.Controllers.api;
-using Falcon.Extend;
namespace FAuth.Controllers.web
{
diff --git a/FAuth/Models/ApiBoolResult.cs b/FAuth/Models/ApiBoolResult.cs
new file mode 100644
index 0000000..1c0e723
--- /dev/null
+++ b/FAuth/Models/ApiBoolResult.cs
@@ -0,0 +1,13 @@
+namespace FAuth.Models
+{
+ ///
+ /// api返回bool结果
+ ///
+ public class ApiBoolResult
+ {
+ ///
+ /// 是否成功
+ ///
+ public bool Result { get; set; }
+ }
+}
diff --git a/FAuth/Models/UserInfo.cs b/FAuth/Models/UserInfo.cs
index 0f05422..8d7ea4f 100644
--- a/FAuth/Models/UserInfo.cs
+++ b/FAuth/Models/UserInfo.cs
@@ -26,5 +26,9 @@ namespace FAuth.Models
/// 上次登录时间
///
public DateTimeOffset? LastLoginDatetime { get; set; }
+ ///
+ /// 账户状态
+ ///
+ public string Status { get; set; }
}
}
diff --git a/FAuth/Startup.cs b/FAuth/Startup.cs
index a579978..068b596 100644
--- a/FAuth/Startup.cs
+++ b/FAuth/Startup.cs
@@ -105,7 +105,7 @@ namespace FAuth
db.InitSync().Wait();
}
- app.UseHttpsRedirection();
+ //app.UseHttpsRedirection();
app.UseStaticFiles();
diff --git a/FAuth/Views/App/AddNew.cshtml b/FAuth/Views/App/AddNew.cshtml
new file mode 100644
index 0000000..2a5418a
--- /dev/null
+++ b/FAuth/Views/App/AddNew.cshtml
@@ -0,0 +1,28 @@
+
+
\ No newline at end of file
diff --git a/FAuth/Views/App/Index.cshtml b/FAuth/Views/App/Index.cshtml
index 88c424d..e5eccfe 100644
--- a/FAuth/Views/App/Index.cshtml
+++ b/FAuth/Views/App/Index.cshtml
@@ -1,7 +1,70 @@
-
-@{
- ViewData["Title"] = "Index";
-}
-
-AppController Index
-
+
+
\ No newline at end of file
diff --git a/FAuth/Views/Shared/_Layout.cshtml b/FAuth/Views/Shared/_Layout.cshtml
index 5f0e4bd..95b032b 100644
--- a/FAuth/Views/Shared/_Layout.cshtml
+++ b/FAuth/Views/Shared/_Layout.cshtml
@@ -62,57 +62,57 @@
+
@RenderSection("Scripts",required: false)