From ea2b423995ae295b315912e894be2ac794f141eb Mon Sep 17 00:00:00 2001 From: Argo-Surface Date: Wed, 21 Nov 2018 21:01:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9BUG=EF=BC=9A=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E6=96=B0=E7=94=A8=E6=88=B7=E5=90=8E=E5=8F=B0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=94=99=E8=AF=AF=EF=BC=8C=E9=87=8D=E5=86=99=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/RegisterController.cs | 4 ++- .../Controllers/Api/UsersController.cs | 2 ++ Bootstrap.Admin/Views/Admin/Profiles.cshtml | 4 +-- Bootstrap.DataAccess/User.cs | 29 +++++++++++-------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Bootstrap.Admin/Controllers/Api/RegisterController.cs b/Bootstrap.Admin/Controllers/Api/RegisterController.cs index 30ec648e..fab2b2f8 100644 --- a/Bootstrap.Admin/Controllers/Api/RegisterController.cs +++ b/Bootstrap.Admin/Controllers/Api/RegisterController.cs @@ -3,6 +3,7 @@ using Longbow.Web.SignalR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; +using System; using System.Linq; using System.Threading.Tasks; @@ -13,7 +14,8 @@ namespace Bootstrap.Admin.Controllers.Api /// [AllowAnonymous] [Route("api/[controller]")] - public class RegisterController : Controller + [ApiController] + public class RegisterController : ControllerBase { /// /// 登录页面注册新用户remote validate调用 diff --git a/Bootstrap.Admin/Controllers/Api/UsersController.cs b/Bootstrap.Admin/Controllers/Api/UsersController.cs index e22b6bc2..132a5cda 100644 --- a/Bootstrap.Admin/Controllers/Api/UsersController.cs +++ b/Bootstrap.Admin/Controllers/Api/UsersController.cs @@ -3,6 +3,7 @@ using Bootstrap.DataAccess; using Longbow.Web.Mvc; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using System; using System.Collections.Generic; using System.Linq; @@ -84,6 +85,7 @@ namespace Bootstrap.Admin.Controllers.Api { value.Description = string.Format("管理员{0}创建用户", User.Identity.Name); value.ApprovedBy = User.Identity.Name; + value.ApprovedTime = DateTime.Now; ret = UserHelper.SaveUser(value); } else diff --git a/Bootstrap.Admin/Views/Admin/Profiles.cshtml b/Bootstrap.Admin/Views/Admin/Profiles.cshtml index 396c722b..13a15689 100644 --- a/Bootstrap.Admin/Views/Admin/Profiles.cshtml +++ b/Bootstrap.Admin/Views/Admin/Profiles.cshtml @@ -26,8 +26,8 @@ - - + + }
diff --git a/Bootstrap.DataAccess/User.cs b/Bootstrap.DataAccess/User.cs index c33da9df..cb5c194d 100644 --- a/Bootstrap.DataAccess/User.cs +++ b/Bootstrap.DataAccess/User.cs @@ -213,27 +213,32 @@ namespace Bootstrap.DataAccess p.PassSalt = LgbCryptography.GenerateSalt(); p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) + var db = DbAccessManager.DBAccess; + using (TransactionPackage transaction = db.BeginTransaction()) { try { - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, "select UserName from Users Where UserName = @userName")) + using (DbCommand cmd = db.CreateCommand(CommandType.Text, "select UserName from Users Where UserName = @userName")) { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", p.UserName)); - var un = DbAccessManager.DBAccess.ExecuteScalar(cmd, transaction); + cmd.Parameters.Add(db.CreateParameter("@userName", p.UserName)); + var un = db.ExecuteScalar(cmd, transaction); if (DbAdapterManager.ToObjectValue(un) == null) { - cmd.CommandText = "Insert Into Users (UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedBy, ApprovedTime, Description) values (@userName, @password, @passSalt, @displayName, datetime('now', 'localtime'), @approvedBy, now(), @description)"; - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@password", p.Password)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@passSalt", p.PassSalt)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@displayName", p.DisplayName)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", DbAdapterManager.ToDBValue(p.ApprovedBy))); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@description", p.Description)); - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); + object approveTime = DBNull.Value; + if (p.ApprovedTime != DateTime.MinValue) approveTime = p.ApprovedTime; + cmd.CommandText = "Insert Into Users (UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedBy, ApprovedTime, Description) values (@userName, @password, @passSalt, @displayName, @registerTime, @approvedBy, @approveTime, @description)"; + cmd.Parameters.Add(db.CreateParameter("@password", p.Password)); + cmd.Parameters.Add(db.CreateParameter("@passSalt", p.PassSalt)); + cmd.Parameters.Add(db.CreateParameter("@registerTime", DateTime.Now)); + cmd.Parameters.Add(db.CreateParameter("@displayName", p.DisplayName)); + cmd.Parameters.Add(db.CreateParameter("@approvedBy", DbAdapterManager.ToDBValue(p.ApprovedBy))); + cmd.Parameters.Add(db.CreateParameter("@approveTime", approveTime)); + cmd.Parameters.Add(db.CreateParameter("@description", p.Description)); + db.ExecuteNonQuery(cmd, transaction); cmd.CommandText = $"insert into UserRole (UserID, RoleID) select ID, (select ID from Roles where RoleName = 'Default') RoleId from Users where UserName = '{p.UserName}'"; cmd.Parameters.Clear(); - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); + db.ExecuteNonQuery(cmd, transaction); transaction.CommitTransaction(); ret = true;