增加页面右上角显示名称功能
This commit is contained in:
parent
1ea4677668
commit
0149819af3
|
@ -15,7 +15,6 @@ namespace Bootstrap.Admin.Controllers
|
|||
public ActionResult Index()
|
||||
{
|
||||
var v = new NavigatorBarModel();
|
||||
v.UserName = "Argo Zhang";
|
||||
v.ShowMenu = "hide";
|
||||
v.HomeUrl = "~/Admin";
|
||||
return View(v);
|
||||
|
@ -27,7 +26,6 @@ namespace Bootstrap.Admin.Controllers
|
|||
public ActionResult Users()
|
||||
{
|
||||
var v = new NavigatorBarModel();
|
||||
v.UserName = "Argo Zhang";
|
||||
v.BreadcrumbName = "用户管理";
|
||||
v.ShowMenu = "hide";
|
||||
v.Menus[1].Active = "active";
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
namespace Bootstrap.Admin.Models
|
||||
using Bootstrap.DataAccess;
|
||||
using System.Web;
|
||||
|
||||
namespace Bootstrap.Admin.Models
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -7,13 +10,13 @@
|
|||
{
|
||||
public HeaderBarModel()
|
||||
{
|
||||
UserName = "Argo Zhang";
|
||||
DisplayName = UserHelper.RetrieveUsersByName(HttpContext.Current.User.Identity.Name).DisplayName;
|
||||
HomeUrl = "~/";
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
map: {
|
||||
ID: "userID",
|
||||
UserName: "userName",
|
||||
Password: "password"
|
||||
Password: "password",
|
||||
DisplayName: "displayName"
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -53,4 +54,6 @@
|
|||
equalTo: "#password"
|
||||
}
|
||||
});
|
||||
|
||||
//TODO: 客户端点击保存用户后,要更新页面右上角用户显示名称
|
||||
});
|
|
@ -15,11 +15,15 @@
|
|||
@section query {
|
||||
<form class="form-horizontal" role="form">
|
||||
<div class="form-group terminal-form-group">
|
||||
<label class="control-label col-lg-1" for="txt_search_name">用户名称</label>
|
||||
<div class="col-lg-4">
|
||||
<label class="control-label col-lg-1" for="txt_search_name">登陆名称</label>
|
||||
<div class="col-lg-2">
|
||||
<input type="text" class="form-control" id="txt_search_name" />
|
||||
</div>
|
||||
<label class="control-label col-lg-1" for="txt_display_name">显示名称</label>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -34,21 +38,25 @@
|
|||
<div class="modal-body">
|
||||
<form class="form-horizontal terminal-form-group" id="dataForm" name="dataForm" role="form">
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-2" for="userName">用户名称</label>
|
||||
<div class="col-sm-4">
|
||||
<label class="control-label col-sm-2" for="userName">登陆名称</label>
|
||||
<div class="col-sm-3">
|
||||
<input type="text" class="form-control" id="userName" name="userName" maxlength="50" />
|
||||
</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" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<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" />
|
||||
</div>
|
||||
<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" />
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<li class="dropdown">
|
||||
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
|
||||
<img alt="" src="../content/images/logo6.jpg">
|
||||
<span class="username">@Model.UserName</span>
|
||||
<span class="username">@Model.DisplayName</span>
|
||||
<b class="caret"></b>
|
||||
</a>
|
||||
<ul class="dropdown-menu extended logout">
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
<add key="TerminalData-CodeTerminalHelper" interval="600" desc="输入口信息缓存" />
|
||||
<add key="GroupData-CodeGroupHelper" interval="600" desc="群组信息缓存" />
|
||||
<add key="UserData-CodeUserHelper" interval="600" desc="用户信息缓存" />
|
||||
<add key="UserData-CodeUserHelper-" interval="600" desc="用户信息缓存" />
|
||||
</cacheManager>
|
||||
|
||||
<cacheManagerList>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
/// </summary>
|
||||
public int ID { get; set; }
|
||||
/// <summary>
|
||||
/// 获得/设置 用户名称
|
||||
/// 获得/设置 登陆账号
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
/// <summary>
|
||||
|
@ -21,5 +21,9 @@
|
|||
/// 获取/设置 验证信息
|
||||
/// </summary>
|
||||
public string PassSalt { get; set; }
|
||||
/// <summary>
|
||||
/// 获取/设置 显示名称
|
||||
/// </summary>
|
||||
public string DisplayName { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace Bootstrap.DataAccess
|
|||
public static class UserHelper
|
||||
{
|
||||
private const string UserDataKey = "UserData-CodeUserHelper";
|
||||
private const string UserDisplayNameDataKey = "UserData-CodeUserHelper-";
|
||||
/// <summary>
|
||||
/// 查询所有用户
|
||||
/// </summary>
|
||||
|
@ -24,7 +25,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
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 =>
|
||||
{
|
||||
List<User> Users = new List<User>();
|
||||
|
@ -38,7 +39,8 @@ namespace Bootstrap.DataAccess
|
|||
Users.Add(new User()
|
||||
{
|
||||
ID = (int)reader[0],
|
||||
UserName = (string)reader[1]
|
||||
UserName = (string)reader[1],
|
||||
DisplayName = (string)reader[2]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -53,30 +55,35 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
private static User RetrieveUsersByName(string userName)
|
||||
public static User RetrieveUsersByName(string userName)
|
||||
{
|
||||
User user = null;
|
||||
string sql = "select ID, UserName, [Password], PassSalt from Users where UserName = @UserName";
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
string key = string.Format("{0}{1}", UserDisplayNameDataKey, userName);
|
||||
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(UserDisplayNameDataKey), k =>
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName, ParameterDirection.Input));
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
User user = null;
|
||||
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],
|
||||
UserName = (string)reader[1],
|
||||
Password = (string)reader[2],
|
||||
PassSalt = (string)reader[3]
|
||||
};
|
||||
user = new User()
|
||||
{
|
||||
ID = (int)reader[0],
|
||||
UserName = (string)reader[1],
|
||||
Password = (string)reader[2],
|
||||
PassSalt = (string)reader[3],
|
||||
DisplayName = (string)reader[4]
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return user;
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return user;
|
||||
}, CacheSection.RetrieveDescByKey(UserDisplayNameDataKey));
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
|
@ -117,8 +124,8 @@ namespace Bootstrap.DataAccess
|
|||
p.PassSalt = LgbCryptography.GenerateSalt();
|
||||
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
|
||||
string sql = p.ID == 0 ?
|
||||
"Insert Into Users (UserName, Password, PassSalt) Values (@UserName, @Password, @PassSalt)" :
|
||||
"Update Users set UserName = @UserName, Password = @Password, PassSalt = @PassSalt where ID = @ID";
|
||||
"Insert Into Users (UserName, Password, PassSalt, DisplayName) Values (@UserName, @Password, @PassSalt, @DisplayName)" :
|
||||
"Update Users set UserName = @UserName, Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @ID";
|
||||
try
|
||||
{
|
||||
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("@Password", p.Password, 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);
|
||||
}
|
||||
ret = true;
|
||||
|
@ -153,6 +161,7 @@ namespace Bootstrap.DataAccess
|
|||
private static void ClearCache()
|
||||
{
|
||||
CacheManager.Clear(key => key == UserDataKey);
|
||||
CacheManager.Clear(key => key.Contains(UserDisplayNameDataKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue