增加页面右上角显示名称功能

This commit is contained in:
Argo-Lenovo 2016-10-24 01:01:29 +08:00
parent 1ea4677668
commit 0149819af3
8 changed files with 88 additions and 62 deletions

View File

@ -15,7 +15,6 @@ namespace Bootstrap.Admin.Controllers
public ActionResult Index() public ActionResult Index()
{ {
var v = new NavigatorBarModel(); var v = new NavigatorBarModel();
v.UserName = "Argo Zhang";
v.ShowMenu = "hide"; v.ShowMenu = "hide";
v.HomeUrl = "~/Admin"; v.HomeUrl = "~/Admin";
return View(v); return View(v);
@ -27,7 +26,6 @@ namespace Bootstrap.Admin.Controllers
public ActionResult Users() public ActionResult Users()
{ {
var v = new NavigatorBarModel(); var v = new NavigatorBarModel();
v.UserName = "Argo Zhang";
v.BreadcrumbName = "用户管理"; v.BreadcrumbName = "用户管理";
v.ShowMenu = "hide"; v.ShowMenu = "hide";
v.Menus[1].Active = "active"; v.Menus[1].Active = "active";

View File

@ -1,30 +1,33 @@
namespace Bootstrap.Admin.Models using Bootstrap.DataAccess;
{ using System.Web;
/// <summary>
/// namespace Bootstrap.Admin.Models
/// </summary> {
public class HeaderBarModel : ModelBase /// <summary>
{ ///
public HeaderBarModel() /// </summary>
{ public class HeaderBarModel : ModelBase
UserName = "Argo Zhang"; {
HomeUrl = "~/"; public HeaderBarModel()
} {
/// <summary> DisplayName = UserHelper.RetrieveUsersByName(HttpContext.Current.User.Identity.Name).DisplayName;
/// HomeUrl = "~/";
/// </summary> }
public string UserName { get; set; } /// <summary>
/// <summary> ///
/// /// </summary>
/// </summary> public string DisplayName { get; set; }
public string BreadcrumbName { get; set; } /// <summary>
/// <summary> ///
/// /// </summary>
/// </summary> public string BreadcrumbName { get; set; }
public string ShowMenu { get; set; } /// <summary>
/// <summary> ///
/// /// </summary>
/// </summary> public string ShowMenu { get; set; }
public string HomeUrl { get; set; } /// <summary>
} ///
/// </summary>
public string HomeUrl { get; set; }
}
} }

View File

@ -3,7 +3,8 @@
map: { map: {
ID: "userID", ID: "userID",
UserName: "userName", UserName: "userName",
Password: "password" Password: "password",
DisplayName: "displayName"
} }
}); });
@ -53,4 +54,6 @@
equalTo: "#password" equalTo: "#password"
} }
}); });
//TODO: 客户端点击保存用户后,要更新页面右上角用户显示名称
}); });

View File

@ -15,11 +15,15 @@
@section query { @section query {
<form class="form-horizontal" role="form"> <form class="form-horizontal" role="form">
<div class="form-group terminal-form-group"> <div class="form-group terminal-form-group">
<label class="control-label col-lg-1" for="txt_search_name">用户名称</label> <label class="control-label col-lg-1" for="txt_search_name">登陆名称</label>
<div class="col-lg-4"> <div class="col-lg-2">
<input type="text" class="form-control" id="txt_search_name" /> <input type="text" class="form-control" id="txt_search_name" />
</div> </div>
<label class="control-label col-lg-1" for="txt_display_name">显示名称</label>
<div class="col-lg-2"> <div class="col-lg-2">
<input type="text" class="form-control" id="txt_display_name" />
</div>
<div class="col-lg-1">
<button type="button" id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>查询</button> <button type="button" id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>查询</button>
</div> </div>
</div> </div>
@ -34,21 +38,25 @@
<div class="modal-body"> <div class="modal-body">
<form class="form-horizontal terminal-form-group" id="dataForm" name="dataForm" role="form"> <form class="form-horizontal terminal-form-group" id="dataForm" name="dataForm" role="form">
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-2" for="userName">用户名称</label> <label class="control-label col-sm-2" for="userName">登陆名称</label>
<div class="col-sm-4"> <div class="col-sm-3">
<input type="text" class="form-control" id="userName" name="userName" maxlength="50" /> <input type="text" class="form-control" id="userName" name="userName" maxlength="50" />
</div> </div>
<div class="col-sm-1" style="display:none;"> <label class="control-label col-sm-2" for="userName">显示名称</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="displayName" name="displayName" maxlength="50" />
</div>
<div class="col-sm-12" style="display:none;">
<input type="text" class="form-control" id="userID" name="userID" /> <input type="text" class="form-control" id="userID" name="userID" />
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-2" for="password">登录密码</label> <label class="control-label col-sm-2" for="password">登录密码</label>
<div class="col-sm-4"> <div class="col-sm-3">
<input type="password" class="form-control" id="password" name="password" maxlength="15" /> <input type="password" class="form-control" id="password" name="password" maxlength="15" />
</div> </div>
<label class="control-label col-sm-2" for="confirm">确认密码</label> <label class="control-label col-sm-2" for="confirm">确认密码</label>
<div class="col-sm-4"> <div class="col-sm-3">
<input type="password" class="form-control" id="confirm" name="confirm" maxlength="15" /> <input type="password" class="form-control" id="confirm" name="confirm" maxlength="15" />
</div> </div>
</div> </div>

View File

@ -31,7 +31,7 @@
<li class="dropdown"> <li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#"> <a data-toggle="dropdown" class="dropdown-toggle" href="#">
<img alt="" src="../content/images/logo6.jpg"> <img alt="" src="../content/images/logo6.jpg">
<span class="username">@Model.UserName</span> <span class="username">@Model.DisplayName</span>
<b class="caret"></b> <b class="caret"></b>
</a> </a>
<ul class="dropdown-menu extended logout"> <ul class="dropdown-menu extended logout">

View File

@ -26,6 +26,7 @@
<add key="TerminalData-CodeTerminalHelper" interval="600" desc="输入口信息缓存" /> <add key="TerminalData-CodeTerminalHelper" interval="600" desc="输入口信息缓存" />
<add key="GroupData-CodeGroupHelper" interval="600" desc="群组信息缓存" /> <add key="GroupData-CodeGroupHelper" interval="600" desc="群组信息缓存" />
<add key="UserData-CodeUserHelper" interval="600" desc="用户信息缓存" /> <add key="UserData-CodeUserHelper" interval="600" desc="用户信息缓存" />
<add key="UserData-CodeUserHelper-" interval="600" desc="用户信息缓存" />
</cacheManager> </cacheManager>
<cacheManagerList> <cacheManagerList>

View File

@ -10,7 +10,7 @@
/// </summary> /// </summary>
public int ID { get; set; } public int ID { get; set; }
/// <summary> /// <summary>
/// 获得/设置 用户名称 /// 获得/设置 登陆账号
/// </summary> /// </summary>
public string UserName { get; set; } public string UserName { get; set; }
/// <summary> /// <summary>
@ -21,5 +21,9 @@
/// 获取/设置 验证信息 /// 获取/设置 验证信息
/// </summary> /// </summary>
public string PassSalt { get; set; } public string PassSalt { get; set; }
/// <summary>
/// 获取/设置 显示名称
/// </summary>
public string DisplayName { get; set; }
} }
} }

View File

@ -17,6 +17,7 @@ namespace Bootstrap.DataAccess
public static class UserHelper public static class UserHelper
{ {
private const string UserDataKey = "UserData-CodeUserHelper"; private const string UserDataKey = "UserData-CodeUserHelper";
private const string UserDisplayNameDataKey = "UserData-CodeUserHelper-";
/// <summary> /// <summary>
/// 查询所有用户 /// 查询所有用户
/// </summary> /// </summary>
@ -24,7 +25,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns> /// <returns></returns>
public static IEnumerable<User> RetrieveUsers(string tId = null) public static IEnumerable<User> RetrieveUsers(string tId = null)
{ {
string sql = "select * from Users"; string sql = "select ID, UserName, DisplayName from Users";
var ret = CacheManager.GetOrAdd(UserDataKey, CacheSection.RetrieveIntervalByKey(UserDataKey), key => var ret = CacheManager.GetOrAdd(UserDataKey, CacheSection.RetrieveIntervalByKey(UserDataKey), key =>
{ {
List<User> Users = new List<User>(); List<User> Users = new List<User>();
@ -38,7 +39,8 @@ namespace Bootstrap.DataAccess
Users.Add(new User() Users.Add(new User()
{ {
ID = (int)reader[0], ID = (int)reader[0],
UserName = (string)reader[1] UserName = (string)reader[1],
DisplayName = (string)reader[2]
}); });
} }
} }
@ -53,30 +55,35 @@ namespace Bootstrap.DataAccess
/// </summary> /// </summary>
/// <param name="userName"></param> /// <param name="userName"></param>
/// <returns></returns> /// <returns></returns>
private static User RetrieveUsersByName(string userName) public static User RetrieveUsersByName(string userName)
{ {
User user = null; string key = string.Format("{0}{1}", UserDisplayNameDataKey, userName);
string sql = "select ID, UserName, [Password], PassSalt from Users where UserName = @UserName"; return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(UserDisplayNameDataKey), k =>
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
try
{ {
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName, ParameterDirection.Input)); User user = null;
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd)) string sql = "select ID, UserName, [Password], PassSalt, DisplayName from Users where UserName = @UserName";
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
try
{ {
if (reader.Read()) cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName, ParameterDirection.Input));
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
{ {
user = new User() if (reader.Read())
{ {
ID = (int)reader[0], user = new User()
UserName = (string)reader[1], {
Password = (string)reader[2], ID = (int)reader[0],
PassSalt = (string)reader[3] UserName = (string)reader[1],
}; Password = (string)reader[2],
PassSalt = (string)reader[3],
DisplayName = (string)reader[4]
};
}
} }
} }
} catch (Exception ex) { ExceptionManager.Publish(ex); }
catch (Exception ex) { ExceptionManager.Publish(ex); } return user;
return user; }, CacheSection.RetrieveDescByKey(UserDisplayNameDataKey));
} }
/// <summary> /// <summary>
/// 删除用户 /// 删除用户
@ -117,8 +124,8 @@ namespace Bootstrap.DataAccess
p.PassSalt = LgbCryptography.GenerateSalt(); p.PassSalt = LgbCryptography.GenerateSalt();
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt); p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
string sql = p.ID == 0 ? string sql = p.ID == 0 ?
"Insert Into Users (UserName, Password, PassSalt) Values (@UserName, @Password, @PassSalt)" : "Insert Into Users (UserName, Password, PassSalt, DisplayName) Values (@UserName, @Password, @PassSalt, @DisplayName)" :
"Update Users set UserName = @UserName, Password = @Password, PassSalt = @PassSalt where ID = @ID"; "Update Users set UserName = @UserName, Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @ID";
try try
{ {
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql)) using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
@ -127,6 +134,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", p.UserName, ParameterDirection.Input)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", p.UserName, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Password", p.Password, ParameterDirection.Input)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Password", p.Password, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@PassSalt", p.PassSalt, ParameterDirection.Input)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@PassSalt", p.PassSalt, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@DisplayName", p.DisplayName, ParameterDirection.Input));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
} }
ret = true; ret = true;
@ -153,6 +161,7 @@ namespace Bootstrap.DataAccess
private static void ClearCache() private static void ClearCache()
{ {
CacheManager.Clear(key => key == UserDataKey); CacheManager.Clear(key => key == UserDataKey);
CacheManager.Clear(key => key.Contains(UserDisplayNameDataKey));
} }
} }
} }