diff --git a/Bootstrap.Admin/Content/js/Longbow.Common.js b/Bootstrap.Admin/Content/js/Longbow.Common.js
index f8fda4b6..2a0ba784 100644
--- a/Bootstrap.Admin/Content/js/Longbow.Common.js
+++ b/Bootstrap.Admin/Content/js/Longbow.Common.js
@@ -129,14 +129,22 @@
});
that.animate({ marginTop: "+=" + getHeight() });
},
- autoValidate: function (options, handler) {
+ autoValidate: function (rules, messages, handler) {
// validate
var $this = $(this);
+ if (messages && $.isArray(messages.button)) {
+ handler = messages;
+ messages = {};
+ }
+ else {
+ messages = $.extend({}, messages);
+ }
$this.validate({
validClass: "has-success",
errorClass: "has-error",
ignore: ".ignore",
- rules: $.extend({}, options),
+ rules: $.extend({}, rules),
+ messages: $.extend({}, messages),
highlight: function (element, errorClass, validClass) {
$(element).parents('.form-group').addClass(errorClass).removeClass(validClass);
},
diff --git a/Bootstrap.Admin/Controllers/UsersController.cs b/Bootstrap.Admin/Controllers/UsersController.cs
index 0ec0a38d..0b26d72b 100644
--- a/Bootstrap.Admin/Controllers/UsersController.cs
+++ b/Bootstrap.Admin/Controllers/UsersController.cs
@@ -30,6 +30,11 @@ namespace Bootstrap.Admin.Controllers
[HttpPut]
public bool Put([FromBody]User value)
{
+ if (value.UserStatus == 9)
+ {
+ // vlaidate userName
+ return UserHelper.RetrieveUsersByName(value.UserName) == null;
+ }
var ret = false;
var userName = User.Identity.Name;
if (value.UserName == userName && !LgbPrincipal.IsAdmin(userName))
@@ -71,9 +76,9 @@ namespace Bootstrap.Admin.Controllers
///
///
[HttpGet]
- public User Get(int id)
+ public User Get(string userName)
{
- return UserHelper.RetrieveUsers().FirstOrDefault(t => t.ID == id);
+ return UserHelper.RetrieveUsersByName(userName);
}
///
///
diff --git a/Bootstrap.Admin/Scripts/Users.js b/Bootstrap.Admin/Scripts/Users.js
index 297ad6b6..3e95879e 100644
--- a/Bootstrap.Admin/Scripts/Users.js
+++ b/Bootstrap.Admin/Scripts/Users.js
@@ -92,7 +92,14 @@
$('#dataForm').autoValidate({
userName: {
required: true,
- maxlength: 50
+ maxlength: 50,
+ remote: {
+ url: "../api/Users/",
+ type: "PUT",
+ data: {
+ UserStatus: 9
+ }
+ }
},
password: {
required: true,
@@ -106,5 +113,9 @@
required: true,
maxlength: 50
}
+ }, {
+ userName: {
+ remote: "此登陆名称已存在"
+ }
});
});
\ No newline at end of file
diff --git a/Bootstrap.DataAccess/User.cs b/Bootstrap.DataAccess/User.cs
index eb7f9e26..faec8d6f 100644
--- a/Bootstrap.DataAccess/User.cs
+++ b/Bootstrap.DataAccess/User.cs
@@ -40,7 +40,7 @@ namespace Bootstrap.DataAccess
///
public string Description { get; set; }
///
- /// 获得/设置 用户当前状态 0 表示管理员注册用户 1 表示用户自己注册 2 表示管理员批复
+ /// 获得/设置 用户当前状态 0 表示管理员注册用户 1 表示用户自己注册 2 表示管理员批复 9 表示前台remote validate
///
public int UserStatus { get; set; }
///
diff --git a/DatabaseScripts/Procedures.sql b/DatabaseScripts/Procedures.sql
index c9bacdd0..739361cf 100644
--- a/DatabaseScripts/Procedures.sql
+++ b/DatabaseScripts/Procedures.sql
@@ -200,7 +200,7 @@ BEGIN
begin
declare @approveTime datetime = null
if @userStatus = 0 set @approveTime = GETDATE()
- if(@id = 0)
+ if(@id = 0 and not exists (select 1 from Users Where UserName = @userName))
Insert Into Users (UserName, [Password], PassSalt, DisplayName, RegisterTime, ApprovedTime, [Description]) values (@userName, @password, @passSalt, @displayName, GETDATE(), @approveTime, @description)
else
Update Users set UserName = @userName, Password = @password, PassSalt = @passSalt, DisplayName = @displayName where ID = @id