完善个人中心保存显示名称、更改密码功能
This commit is contained in:
parent
80a0b4e3e2
commit
6a989044ca
|
@ -152,4 +152,7 @@ Dotfuscated/
|
|||
#AutoUpdate
|
||||
*/UpdateServer/v*
|
||||
*/UpdateServer/*.dll
|
||||
*/UpdateServer/*.exe
|
||||
*/UpdateServer/*.exe
|
||||
|
||||
#uploader
|
||||
uploader/
|
|
@ -136,6 +136,7 @@
|
|||
<Content Include="Content\images\logo4.jpg" />
|
||||
<Content Include="Content\images\logo5.jpg" />
|
||||
<Content Include="Content\images\logo6.jpg" />
|
||||
<Content Include="Content\images\uploader\Admin.jpg" />
|
||||
<Content Include="Content\images\uploader\default.jpg" />
|
||||
<Content Include="Content\images\uploader\readme.txt" />
|
||||
<Content Include="Content\js\bootstrap-datetimepicker.js" />
|
||||
|
@ -317,9 +318,7 @@
|
|||
<DependentUpon>Web.config</DependentUpon>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Content\images\uploader\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj">
|
||||
<Project>{af16ca71-b8c6-4f51-b38c-0c0300fdebd7}</Project>
|
||||
|
|
|
@ -325,13 +325,20 @@
|
|||
};
|
||||
User.saveUsersByRoleId = function (roleId, userIds, callback) {
|
||||
processData.call(this, { Id: roleId, callback: callback, method: "PUT", data: { type: "role", userIds: userIds } });
|
||||
}
|
||||
};
|
||||
User.getUsersByGroupeId = function (groupId, callback) {
|
||||
processData.call(this, { Id: groupId, callback: callback, data: { type: "group" } });
|
||||
};
|
||||
User.saveUsersByGroupId = function (groupId, userIds, callback) {
|
||||
processData.call(this, { Id: groupId, callback: callback, method: "PUT", data: { type: "group", userIds: userIds } });
|
||||
};
|
||||
User.saveUserDisplayName = function (user, callback) {
|
||||
processData.call(this, { Id: '', callback: callback, method: "PUT", data: user });
|
||||
};
|
||||
User.changePassword = function (user) {
|
||||
processData.call(this, { Id: '', method: "PUT", data: user });
|
||||
}
|
||||
|
||||
// Groups
|
||||
Group = {
|
||||
url: '../api/Groups/',
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Bootstrap.Admin.Models;
|
||||
using Bootstrap.DataAccess;
|
||||
using Longbow.Security.Principal;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -26,6 +27,24 @@ namespace Bootstrap.Admin.Controllers
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public bool Put([FromBody]User value)
|
||||
{
|
||||
var ret = false;
|
||||
var userName = User.Identity.Name;
|
||||
if (value.UserName == userName && !LgbPrincipal.IsAdmin(userName))
|
||||
{
|
||||
if (value.UserStatus == 1)
|
||||
ret = UserHelper.SaveUserInfoByName(value);
|
||||
else if (value.UserStatus == 2)
|
||||
ret = UserHelper.ChangePassword(value);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
|
|
|
@ -17,4 +17,38 @@
|
|||
var url = data.response;
|
||||
if (!!url) $headerIcon.attr('src', url);
|
||||
});
|
||||
|
||||
var bsa = new BootstrapAdmin({
|
||||
url: '../api/Infos',
|
||||
bootstrapTable: null,
|
||||
dataEntity: new DataEntity({
|
||||
map: {
|
||||
Password: "currentPassword",
|
||||
NewPassword: "newPassword",
|
||||
DisplayName: "displayName",
|
||||
UserName: "userName"
|
||||
}
|
||||
}),
|
||||
click: {
|
||||
assign: [{
|
||||
id: 'btnSavePassword',
|
||||
click: function (row, data) {
|
||||
data.UserStatus = 2;
|
||||
User.changePassword(data);
|
||||
}
|
||||
}, {
|
||||
id: 'btnSaveDisplayName',
|
||||
click: function (row, data) {
|
||||
data.UserStatus = 1;
|
||||
User.saveUserDisplayName(data, function (result) {
|
||||
if (result) {
|
||||
$('#userDisplayName').text(data.DisplayName);
|
||||
}
|
||||
});
|
||||
}
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
||||
$('button[data-admin="True"]').attr('disabled', 'disabled');
|
||||
});
|
|
@ -50,7 +50,7 @@
|
|||
},
|
||||
success: function (src, data) {
|
||||
if (src === 'save' && data.ID === $('#userId').val()) {
|
||||
$('.username').text(data.DisplayName);
|
||||
$('#userDisplayName').text(data.DisplayName);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
Layout = "~/Views/Shared/_Admin.cshtml";
|
||||
}
|
||||
@section Javascript {
|
||||
<script src="~/Content/js/longbow.dataentity.js"></script>
|
||||
<script src="~/content/js/sweetalert.js"></script>
|
||||
<script src="~/Content/js/fileinput.js"></script>
|
||||
<script src="~/Content/js/zh.js"></script>
|
||||
|
@ -23,20 +24,20 @@
|
|||
<div class="panel panel-default">
|
||||
<div class="panel-heading">基本资料</div>
|
||||
<div class="panel-body">
|
||||
<form class="form-inline" id="infoDataForm" name="infoDataForm" role="form">
|
||||
<form id="infoDataForm" name="infoDataForm" class="form-inline" role="form">
|
||||
<div class="row">
|
||||
<div class="form-group col-xs-12 col-sm-6">
|
||||
<label class="control-label" for="userName">登陆名称</label>
|
||||
<input type="text" class="form-control" id="userName" name="userName" placeholder="不可为空" maxlength="50" />
|
||||
<input type="text" class="form-control" id="userName" name="userName" value="@Model.UserName" readonly />
|
||||
</div>
|
||||
<div class="form-group col-xs-12 col-sm-6">
|
||||
<label class="control-label" for="DisplayName">显示名称</label>
|
||||
<input type="text" class="form-control" id="DisplayName" name="DisplayName" placeholder="不可为空" maxlength="50" />
|
||||
<input type="text" class="form-control" id="displayName" name="displayName" value="@Model.DisplayName" placeholder="不可为空" maxlength="50" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-default" type="button">保存</button>
|
||||
<button id="btnSaveDisplayName" class="btn btn-default" type="button" data-admin="@LgbPrincipal.IsAdmin(Model.UserName)">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -60,7 +61,7 @@
|
|||
</div>
|
||||
</form>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-default" type="button">保存</button>
|
||||
<button id="btnSavePassword" class="btn btn-default" type="button" data-admin="@LgbPrincipal.IsAdmin(Model.UserName)">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -191,9 +191,9 @@
|
|||
<li class="dropdown">
|
||||
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
|
||||
<img id="headerIcon" alt="" src="@Url.Content(Model.Icon)">
|
||||
<span class="username">@Model.DisplayName</span>
|
||||
<span id="userDisplayName" class="username">@Model.DisplayName</span>
|
||||
<b class="caret"></b>
|
||||
<input id="userId" type="text" class="hide" value="@Model.UserID" />
|
||||
<input id="userId" type="text" class="hidden" value="@Model.UserID" />
|
||||
</a>
|
||||
<ul class="dropdown-menu logout">
|
||||
<div class="arrow-up"></div>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
|
||||
<pages pageBaseType="System.Web.Mvc.WebViewPage">
|
||||
<namespaces>
|
||||
<add namespace="Longbow.Security.Principal" />
|
||||
<add namespace="System.Web.Mvc" />
|
||||
<add namespace="System.Web.Mvc.Ajax" />
|
||||
<add namespace="System.Web.Mvc.Html" />
|
||||
|
|
|
@ -60,8 +60,12 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
public string RejectedTime { get; set; }
|
||||
/// <summary>
|
||||
/// 获取/设置 用户头像
|
||||
/// 获得/设置 用户头像
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
/// <summary>
|
||||
/// 获得/设置 新密码
|
||||
/// </summary>
|
||||
public string NewPassword { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -381,7 +381,66 @@ namespace Bootstrap.DataAccess
|
|||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
ret = true;
|
||||
}
|
||||
CacheManager.Clear(key => key == RetrieveUsersByNameDataKey);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SaveUserInfoByName(User user)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
string sql = "Update Users set DisplayName = @DisplayName where UserName = @userName";
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@DisplayName", user.DisplayName, ParameterDirection.Input));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", user.UserName, ParameterDirection.Input));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
CacheCleanUtility.ClearCache(userIds: string.Empty);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public static bool ChangePassword(User user)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
if (Authenticate(user.UserName, user.Password))
|
||||
{
|
||||
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt where UserName = @userName";
|
||||
user.PassSalt = LgbCryptography.GenerateSalt();
|
||||
user.NewPassword = LgbCryptography.ComputeHash(user.NewPassword, user.PassSalt);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Password", user.NewPassword, ParameterDirection.Input));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@PassSalt", user.PassSalt, ParameterDirection.Input));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", user.UserName, ParameterDirection.Input));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
string key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, user.UserName);
|
||||
CacheManager.Clear(k => k == key);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue