增加功能:MongoDB增加用户新建/保存方法
This commit is contained in:
parent
b008a8c46c
commit
4f3b021eb7
|
@ -71,7 +71,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// 前台User View调用,新建/更新用户
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[HttpPost]
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-inline">
|
||||
<input type="hidden" id="userID" data-default-val="0" />
|
||||
<input type="hidden" id="userID" data-default-val="" />
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-6">
|
||||
<label class="control-label" for="userName">登陆名称</label>
|
||||
|
|
|
@ -76,6 +76,10 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
md.AutoMap();
|
||||
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
|
||||
md.IdMemberMap.SetIgnoreIfDefault(true);
|
||||
md.UnmapMember(user => user.Checked);
|
||||
md.UnmapMember(user => user.Period);
|
||||
md.UnmapMember(user => user.NewPassword);
|
||||
md.UnmapMember(user => user.UserStatus);
|
||||
});
|
||||
}
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(BootstrapMenu)))
|
||||
|
|
|
@ -44,5 +44,49 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
var users = MongoDbAccessManager.DBAccess.GetCollection<DataAccess.User>("Users");
|
||||
return users.Find(user => user.ApprovedTime == DateTime.MinValue).SortByDescending(user => user.RegisterTime).ToList();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override IEnumerable<DataAccess.User> RetrieveUsers()
|
||||
{
|
||||
var users = MongoDbAccessManager.DBAccess.GetCollection<DataAccess.User>("Users");
|
||||
return users.Find(user => user.ApprovedTime != DateTime.MinValue).ToList();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="p"></param>
|
||||
/// <returns></returns>
|
||||
public override bool SaveUser(DataAccess.User user)
|
||||
{
|
||||
if (user.Description.Length > 500) user.Description = user.Description.Substring(0, 500);
|
||||
if (user.UserName.Length > 50) user.UserName = user.UserName.Substring(0, 50);
|
||||
user.Id = null;
|
||||
user.PassSalt = LgbCryptography.GenerateSalt();
|
||||
user.Password = LgbCryptography.ComputeHash(user.Password, user.PassSalt);
|
||||
user.RegisterTime = DateTime.Now;
|
||||
user.ApprovedTime = DateTime.Now;
|
||||
user.Icon = $"{DictHelper.RetrieveIconFolderPath().Code}default.jpg";
|
||||
var users = MongoDbAccessManager.DBAccess.GetCollection<DataAccess.User>("Users");
|
||||
users.InsertOne(user);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <param name="displayName"></param>
|
||||
/// <returns></returns>
|
||||
public override bool UpdateUser(string id, string password, string displayName)
|
||||
{
|
||||
var passSalt = LgbCryptography.GenerateSalt();
|
||||
var newPassword = LgbCryptography.ComputeHash(password, passSalt);
|
||||
var update = Builders<DataAccess.User>.Update.Set(u => u.Password, newPassword).Set(u => u.PassSalt, passSalt).Set(u => u.DisplayName, displayName);
|
||||
var users = MongoDbAccessManager.DBAccess.GetCollection<DataAccess.User>("Users");
|
||||
users.FindOneAndUpdate(u => u.Id == id, update);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -183,14 +183,14 @@ namespace Bootstrap.DataAccess
|
|||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存新建
|
||||
/// 新建前台User View调用/注册用户调用
|
||||
/// </summary>
|
||||
/// <param name="p"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool SaveUser(User p)
|
||||
{
|
||||
var ret = false;
|
||||
if (string.IsNullOrEmpty(p.Id) && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500);
|
||||
if (p.Description.Length > 500) p.Description = p.Description.Substring(0, 500);
|
||||
if (p.UserName.Length > 50) p.UserName = p.UserName.Substring(0, 50);
|
||||
p.PassSalt = LgbCryptography.GenerateSalt();
|
||||
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
|
||||
|
@ -208,7 +208,7 @@ namespace Bootstrap.DataAccess
|
|||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// User List 视图保存按钮调用
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="password"></param>
|
||||
|
|
Loading…
Reference in New Issue