增加功能:个人中心增加自定义默认应用程序功能 #IS0WK

This commit is contained in:
Argo-MacBookPro 2019-02-27 16:48:19 +08:00
parent b1836eb567
commit d6b63281fe
16 changed files with 118 additions and 12 deletions

View File

@ -40,12 +40,14 @@ namespace Bootstrap.Admin.Controllers.Api
{
return UserHelper.SaveUserCssByName(value.UserName, value.Css);
}
if (value.UserName.Equals(User.Identity.Name, System.StringComparison.OrdinalIgnoreCase))
if (value.UserName.Equals(User.Identity.Name, StringComparison.OrdinalIgnoreCase))
{
if (value.UserStatus == UserStates.ChangeDisplayName)
ret = UserHelper.SaveDisplayName(value.UserName, value.DisplayName);
else if (value.UserStatus == UserStates.ChangePassword)
ret = UserHelper.ChangePassword(value.UserName, value.Password, value.NewPassword);
else if (value.UserStatus == UserStates.SaveApp)
ret = UserHelper.SaveApp(value.UserName, value.App);
}
return ret;
}

View File

@ -17,8 +17,9 @@ namespace Bootstrap.Admin.Controllers
/// <returns></returns>
public IActionResult Index()
{
var url = DictHelper.RetrieveHomeUrl();
return url.Equals("~/Home/Index", System.StringComparison.OrdinalIgnoreCase) ? (IActionResult)View(new HeaderBarModel(User.Identity)) : Redirect(url);
var model = new HeaderBarModel(User.Identity);
var url = DictHelper.RetrieveHomeUrl(model.AppCode);
return url.Equals("~/Home/Index", System.StringComparison.OrdinalIgnoreCase) ? (IActionResult)View(model) : Redirect(url);
}
/// <summary>

View File

@ -18,19 +18,28 @@ namespace Bootstrap.Admin.Models
Icon = string.Format("{0}{1}", DictHelper.RetrieveIconFolderPath(), user.Icon);
DisplayName = user.DisplayName;
UserName = user.UserName;
AppCode = user.App;
if (!string.IsNullOrEmpty(user.Css)) Theme = user.Css;
}
/// <summary>
///
/// </summary>
public string UserName { get; }
/// <summary>
///
/// </summary>
public string DisplayName { get; }
/// <summary>
/// 获得/设置 用户头像地址
/// </summary>
public string Icon { get; }
/// <summary>
/// 获得 当前设置的默认应用
/// </summary>
public string AppCode { get; }
}
}

View File

@ -10,13 +10,15 @@ namespace Bootstrap.Admin.Models
public class ProfilesModel : ThemeModel
{
/// <summary>
/// 获得/设置 头像文件大小
/// 获得 头像文件大小
/// </summary>
public long Size { get; }
/// <summary>
///
/// 获得 头像文件名称
/// </summary>
public string FileName { get; }
/// <summary>
///
/// </summary>

View File

@ -76,6 +76,25 @@
</div>
</div>
</div>
<div class="card">
<div class="card-header">默认应用</div>
<div class="card-body">
<div class="form-group">
<div class="btn-group" role="group">
<button id="app" class="btn btn-success dropdown-select dropdown-toggle" data-toggle="dropdown" data-default-val="" value="@Model.AppCode">未设置</button>
<div class="dropdown-menu">
@foreach (var app in Model.Applications)
{
<a href="#" data-val="@app.Key">@app.Value</a>
}
</div>
</div>
</div>
<div class="modal-footer d-none" data-admin="@User.IsInRole("Administrators")">
<button id="btnSaveApp" data-method="app" class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button>
</div>
</div>
</div>
<div class="card">
<div class="card-header">网站皮肤</div>
<div class="card-body">

View File

@ -67,7 +67,8 @@
NewPassword: "#newPassword",
DisplayName: "#displayName",
UserName: "#userName",
Css: "#css"
Css: "#css",
App: '#app'
});
$('button[data-method]').on('click', function (e) {
@ -100,6 +101,16 @@
}
});
break;
case 'app':
data.UserStatus = 'SaveApp';
$.bc({
url: User.url, method: "put", data: data, title: "保存应用", callback: function (result) {
if (result) {
window.setTimeout(function () { window.location.reload(true); }, 1000);
}
}
});
break;
}
});
$('[data-admin="False"]').removeClass('d-none');
@ -107,4 +118,5 @@
$('.card-img').removeClass('d-none');
}
$('#css').dropdown('val');
$('#app').dropdown('val');
});

View File

@ -11,7 +11,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.0.0" />
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.1.0" />
<PackageReference Include="Longbow.Cache" Version="2.2.3" />
<PackageReference Include="Longbow.Data" Version="2.2.6" />
<PackageReference Include="Longbow.Web" Version="2.2.4" />

View File

@ -51,6 +51,13 @@ namespace Bootstrap.DataAccess.MongoDB
return u != null && !string.IsNullOrEmpty(u.PassSalt) && u.Password == LgbCryptography.ComputeHash(password, u.PassSalt);
}
public override bool SaveApp(string userName, string app)
{
var update = Builders<User>.Update.Set(u => u.App, app);
DbManager.Users.FindOneAndUpdate(u => u.UserName.ToLowerInvariant() == UserName.ToLowerInvariant(), update);
return true;
}
/// <summary>
///
/// </summary>

View File

@ -11,7 +11,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.0.0" />
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.1.0" />
<PackageReference Include="Longbow.Data" Version="2.2.6" />
<PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" />
<PackageReference Include="Longbow.Web" Version="2.2.4" />

View File

@ -96,8 +96,26 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 获得默认的前台首页地址,默认为~/Home/Index
/// </summary>
/// <param name="appCode"></param>
/// <returns></returns>
public virtual string RetrieveHomeUrl() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Home/Index" }).Code;
public virtual string RetrieveHomeUrl(string appCode)
{
// https://gitee.com/LongbowEnterprise/dashboard/issues?id=IS0WK
var url = "~/Home/Index";
var dicts = DictHelper.RetrieveDicts();
if (appCode != "0")
{
var appUrl = dicts.FirstOrDefault(d => d.Name.Equals(appCode, StringComparison.OrdinalIgnoreCase) && d.Category == "应用首页" && d.Define == 0)?.Code;
if (!string.IsNullOrEmpty(appUrl))
{
url = appUrl;
return url;
}
}
var defaultUrl = dicts.FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0)?.Code;
if (!string.IsNullOrEmpty(defaultUrl)) url = defaultUrl;
return url;
}
/// <summary>
///

View File

@ -106,8 +106,9 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 获得默认的前台首页地址,默认为~/Home/Index
/// </summary>
/// <param name="appCode">应用程序编码</param>
/// <returns></returns>
public static string RetrieveHomeUrl() => DbContextManager.Create<Dict>().RetrieveHomeUrl();
public static string RetrieveHomeUrl(string appCode) => DbContextManager.Create<Dict>().RetrieveHomeUrl(appCode);
/// <summary>
///

View File

@ -1,6 +1,7 @@
using Bootstrap.Security;
using Longbow.Cache;
using Longbow.Data;
using System;
using System.Collections.Generic;
namespace Bootstrap.DataAccess
@ -48,6 +49,19 @@ namespace Bootstrap.DataAccess
return ret;
}
/// <summary>
/// 保存用户默认App
/// </summary>
/// <param name="userName"></param>
/// <param name="app"></param>
/// <returns></returns>
public static bool SaveApp(string userName, string app)
{
var ret = DbContextManager.Create<User>().SaveApp(userName, app);
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
return ret;
}
/// <summary>
/// 保存新建
/// </summary>
@ -163,6 +177,7 @@ namespace Bootstrap.DataAccess
return ret;
}
/// <summary>
/// 根据用户名修改用户头像
/// </summary>
/// <param name="userName"></param>

View File

@ -81,6 +81,14 @@ namespace Bootstrap.DataAccess
return user != null && !string.IsNullOrEmpty(user.PassSalt) && user.Password == LgbCryptography.ComputeHash(password, user.PassSalt);
}
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <param name="app"></param>
/// <returns></returns>
public virtual bool SaveApp(string userName, string app) => DbManager.Create().Update<User>("set App = @1 where UserName = @0", userName, app) == 1;
/// <summary>
///
/// </summary>
@ -358,6 +366,10 @@ namespace Bootstrap.DataAccess
/// <summary>
///
/// </summary>
RejectUser
RejectUser,
/// <summary>
///
/// </summary>
SaveApp
}
}

View File

@ -11,6 +11,7 @@
"Description": "系统默认创建",
"Icon": "default.jpg",
"Css": null,
"App": null,
"Roles": [
"5bd7cc105fa31256f77e4eb7"
],
@ -30,6 +31,7 @@
"Description": "管理员Admin创建用户",
"Icon": "default.jpg",
"Css": null,
"App": null,
"Groups": [
],

View File

@ -110,6 +110,12 @@ namespace Bootstrap.Admin.Api
resp = await client.PutAsJsonAsync<User, bool>(usr);
Assert.True(resp);
// change app
usr.App = "UnitTest";
usr.UserStatus = UserStates.SaveApp;
resp = await client.PutAsJsonAsync<User, bool>(usr);
Assert.True(resp);
// delete
usr.Delete(usr.Retrieves().Where(u => u.UserName == usr.UserName).Select(u => u.Id));
}

View File

@ -80,7 +80,7 @@ namespace Bootstrap.DataAccess
public void RetrieveHomeUrl_Ok()
{
var dict = new Dict();
Assert.Equal("~/Home/Index", dict.RetrieveHomeUrl());
Assert.Equal("~/Home/Index", dict.RetrieveHomeUrl("0"));
}
[Fact]