2019-06-30 23:18:33 +08:00
|
|
|
|
using Bootstrap.Security.DataAccess;
|
2018-09-28 10:27:02 +08:00
|
|
|
|
using Longbow.Configuration;
|
2019-06-15 22:11:40 +08:00
|
|
|
|
using Microsoft.AspNetCore;
|
2018-10-10 12:03:00 +08:00
|
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
|
|
using System;
|
2018-09-16 19:33:56 +08:00
|
|
|
|
using System.Security.Principal;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Client.Models
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class HeaderBarModel : ModelBase
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="identity"></param>
|
2018-09-28 10:27:02 +08:00
|
|
|
|
public HeaderBarModel(IIdentity identity)
|
2018-09-16 19:33:56 +08:00
|
|
|
|
{
|
2019-07-09 20:18:17 +08:00
|
|
|
|
var user = DbHelper.RetrieveUserByUserNameWithCache(identity.Name);
|
2018-09-16 19:33:56 +08:00
|
|
|
|
DisplayName = user.DisplayName;
|
|
|
|
|
UserName = user.UserName;
|
2019-06-30 23:18:33 +08:00
|
|
|
|
SettingsUrl = DbHelper.RetrieveSettingsUrl();
|
|
|
|
|
ProfilesUrl = DbHelper.RetrieveProfilesUrl();
|
|
|
|
|
NotisUrl = DbHelper.RetrieveNotisUrl();
|
2019-06-15 22:11:40 +08:00
|
|
|
|
|
|
|
|
|
// set LogoutUrl
|
2019-07-01 15:48:54 +08:00
|
|
|
|
var authHost = ConfigurationManager.Get<BootstrapAdminAuthenticationOptions>().AuthHost;
|
2019-06-15 22:11:40 +08:00
|
|
|
|
var uriBuilder = new UriBuilder(authHost);
|
|
|
|
|
uriBuilder.Path = uriBuilder.Path == "/" ? CookieAuthenticationDefaults.LogoutPath.Value : $"{uriBuilder.Path.TrimEnd('/')}{CookieAuthenticationDefaults.LogoutPath.Value}";
|
2018-10-10 12:03:00 +08:00
|
|
|
|
LogoutUrl = uriBuilder.ToString();
|
2019-06-15 22:11:40 +08:00
|
|
|
|
|
|
|
|
|
// set Icon
|
2019-06-30 23:18:33 +08:00
|
|
|
|
var icon = $"/{DbHelper.RetrieveIconFolderPath().Trim('~', '/')}/{user.Icon}";
|
2019-07-09 20:12:57 +08:00
|
|
|
|
Icon = string.IsNullOrEmpty(ConfigurationManager.GetValue("SimulateUserName", string.Empty)) ? $"{authHost.TrimEnd('/')}{icon}" : "/images/admin.jpg";
|
2018-09-16 19:33:56 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(user.Css)) Theme = user.Css;
|
|
|
|
|
}
|
2019-05-05 16:14:14 +08:00
|
|
|
|
|
2018-09-16 19:33:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string UserName { get; }
|
2019-05-05 16:14:14 +08:00
|
|
|
|
|
2018-09-16 19:33:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string DisplayName { get; }
|
2019-05-05 16:14:14 +08:00
|
|
|
|
|
2018-09-16 19:33:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得/设置 用户头像地址
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Icon { get; }
|
2019-05-05 16:14:14 +08:00
|
|
|
|
|
2018-09-16 19:33:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得/设置 设置网址
|
|
|
|
|
/// </summary>
|
2018-10-10 12:03:00 +08:00
|
|
|
|
public string SettingsUrl { get; }
|
2019-05-05 16:14:14 +08:00
|
|
|
|
|
2018-09-16 19:33:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得/设置 个人中心网址
|
|
|
|
|
/// </summary>
|
2018-10-10 12:03:00 +08:00
|
|
|
|
public string ProfilesUrl { get; }
|
2019-05-05 16:14:14 +08:00
|
|
|
|
|
2018-10-10 12:03:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得 退出登录地址
|
|
|
|
|
/// </summary>
|
2018-10-29 14:33:07 +08:00
|
|
|
|
public string LogoutUrl { get; }
|
2019-05-05 16:14:14 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string NotisUrl { get; }
|
2018-09-16 19:33:56 +08:00
|
|
|
|
}
|
2019-06-15 22:11:40 +08:00
|
|
|
|
}
|