Skip to content

Commit

Permalink
input
Browse files Browse the repository at this point in the history
  • Loading branch information
starlying committed Jun 6, 2017
2 parents e7f3009 + 2c048eb commit 88be303
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 58 deletions.
16 changes: 5 additions & 11 deletions source/BaiRong.Core/MessageUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,24 @@ private static string DecodeMessage(string message)
//message = StringUtils.HtmlDecode(message);
message = message.Replace("''", "\"");
}
return message;
return message;
}

public static string GetMessageHtml(Message.EMessageType messageType, string message, Control control)
{
var messageHtml = string.Empty;
message = DecodeMessage(message);
if (messageType == Message.EMessageType.Success)
if (!string.IsNullOrEmpty(message))
{
if (!string.IsNullOrEmpty(message))
if (messageType == Message.EMessageType.Success)
{
messageHtml = $@"<DIV class=""msg_succeed"">{message}</DIV>";
}
}
else if (messageType == Message.EMessageType.Error)
{
if (!string.IsNullOrEmpty(message))
else if (messageType == Message.EMessageType.Error)
{
messageHtml = $@"<DIV class=""msg_failed"">{message}</DIV>";
}
}
else if (messageType == Message.EMessageType.Info)
{
if (!string.IsNullOrEmpty(message))
else if (messageType == Message.EMessageType.Info)
{
messageHtml = $@"<DIV class=""msg_info"">{message}</DIV>";
}
Expand Down
18 changes: 9 additions & 9 deletions source/SiteServer.BackgroundPages/BasePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ namespace SiteServer.BackgroundPages
{
public class BasePage : Page
{
public Literal ltlBreadCrumb;
public Literal ltlBreadCrumb; // 面包屑(头部导航 + 左边一级二级菜单 + 其他)
public Message messageCtrl;

private MessageUtils.Message.EMessageType _messageType;
private string _message = string.Empty;
private string _scripts = string.Empty;

protected virtual bool IsAccessable => false;
protected virtual bool IsAccessable => false; // 页面默认情况下是不能直接访问

protected virtual bool IsSinglePage => false;
protected virtual bool IsSinglePage => false; // 是否为单页(即是否需要放在框架页内运行,false表示需要)

protected bool IsForbidden { get; private set; }

public RequestBody Body { get; private set; }

private void SetMessage(MessageUtils.Message.EMessageType messageType, Exception ex, string message)
{
_messageType = messageType;
_messageType = messageType;
_message = ex != null ? $"{message}<!-- {ex} -->" : message;
}

Expand All @@ -39,7 +39,7 @@ protected override void OnInit(EventArgs e)

Body = new RequestBody();

if (!IsAccessable && !Body.IsAdministratorLoggin)
if (!IsAccessable && !Body.IsAdministratorLoggin) // 如果页面不能直接访问且又没有登录则直接跳登录页
{
IsForbidden = true;
PageUtils.RedirectToLoginPage();
Expand All @@ -53,21 +53,21 @@ protected override void Render(HtmlTextWriter writer)
{
if (!string.IsNullOrEmpty(_message))
{
if (messageCtrl != null)
if (messageCtrl != null) // 页面有消息显示的控件则立即显示消息
{
messageCtrl.IsShowImmidiatary = true;
messageCtrl.MessageType = _messageType;
messageCtrl.Content = _message;
}
else
{
else // 没有的话则把消息存在cookies中到有控件的页面再显示
{
MessageUtils.SaveMessage(_messageType, _message);
}
}

base.Render(writer);

if (!IsAccessable && !IsSinglePage)
if (!IsAccessable && !IsSinglePage) // 页面不能直接访问且不是单页,需要加一段框架检测代码,检测页面是否运行在框架内
{
writer.Write($@"<script type=""text/javascript"">
if (window.top.location.href.toLowerCase().indexOf(""main.aspx"") == -1){{
Expand Down
4 changes: 2 additions & 2 deletions source/SiteServer.BackgroundPages/Controls/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public string Content

protected override void Render(HtmlTextWriter writer)
{
if (isShowImmidiatary)
if (isShowImmidiatary) // 有直接显示的消息
{
writer.Write(MessageUtils.GetMessageHtml(messageType, content, this));
}
else
else // 没有直接显示的消息则去cookies中检查是否有消息需要显示
{
writer.Write(MessageUtils.GetMessageHtml(this));
}
Expand Down
26 changes: 13 additions & 13 deletions source/SiteServer.BackgroundPages/PageInitialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,38 @@ public class PageInitialization : BasePageCms

protected override bool IsSinglePage => true;

public static string GetRedirectUrl()
public static string GetRedirectUrl() // 本页面实际地址获取函数 如果需要从其他地方跳转到本页面,则调用此方法即可
{
return PageUtils.GetSiteServerUrl(nameof(PageInitialization), null);
}

public void Page_Load(object sender, EventArgs e)
{
if (IsForbidden) return;
if (IsForbidden) return; // 检测是否允许访问本页面

if (PageUtils.DetermineRedirectToInstaller()) return;
if (PageUtils.DetermineRedirectToInstaller()) return; // 检测系统是否需要安装,如果需要转到安装页面。

if (!Body.IsAdministratorLoggin)
if (!Body.IsAdministratorLoggin) // 检测管理员是否登录
{
PageUtils.RedirectToLoginPage();
PageUtils.RedirectToLoginPage(); // 如果没有登录则跳到登录页面
return;
}

if (Body.AdministratorInfo.IsLockedOut)
if (Body.AdministratorInfo.IsLockedOut) // 检测管理员帐号是否被锁定
{
PageUtils.RedirectToLoginPage("对不起,您的账号已被锁定,无法进入系统!");
return;
}

var redirectUrl = PageMain.GetRedirectUrl();
var redirectUrl = PageMain.GetRedirectUrl(); // 如果检测登录帐号一切正常,则准备转到框架主页 pagemain.aspx

var permissions = PermissionsManager.GetPermissions(Body.AdministratorName);
var publishmentSystemIdList = ProductPermissionsManager.Current.PublishmentSystemIdList;
if (publishmentSystemIdList == null || publishmentSystemIdList.Count == 0)
var permissions = PermissionsManager.GetPermissions(Body.AdministratorName); // 获取登录管理员的权限
var publishmentSystemIdList = ProductPermissionsManager.Current.PublishmentSystemIdList; // 获取当前站点ID
if (publishmentSystemIdList == null || publishmentSystemIdList.Count == 0) // 如果目前还没有创建站点
{
if (permissions.IsSystemAdministrator)
if (permissions.IsSystemAdministrator) // 如果目前还没有创建站点并且当前登录管理员是系统管理员
{
redirectUrl = PageAppAdd.GetRedirectUrl();
redirectUrl = PageAppAdd.GetRedirectUrl(); // 则直接跳到站点创建页面
}
}

Expand All @@ -56,7 +56,7 @@ function redirectUrl()
}}
setTimeout(""redirectUrl()"", 2000);
</script>
";
"; // 通过输出js来实现2秒之后开始页面跳转
}
}
}
37 changes: 20 additions & 17 deletions source/SiteServer.BackgroundPages/PageLogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,36 @@ public class PageLogin : BasePage
public CheckBox CbRememberMe;
public PlaceHolder PhFindPassword;

private VcManager _vcManager;
protected override bool IsAccessable => true;
private VcManager _vcManager; // 验证码类

public void Page_Load(object sender, EventArgs e)
protected override bool IsAccessable => true; // 设置本页面是否能直接访问 如果为false,则必须管理员登录后才能访问

public void Page_Load(object sender, EventArgs e)
{
if (IsForbidden) return;
if (IsForbidden) return; // 如果无权访问页面,则返回空白页

try
{
_vcManager = VcManager.GetInstance();
_vcManager = VcManager.GetInstance(); // 构建验证码实例
if (Page.IsPostBack) return;

PhFindPassword.Visible = ConfigManager.SystemConfigInfo.IsFindPassword;

if (Body.IsQueryExists("error"))
if (Body.IsQueryExists("error")) // 如果url参数error不为空,则把错误信息显示到页面上
{
LtlMessage.Text = GetMessageHtml(Body.GetQueryString("error"));
}
// 判断是否满足系统的黑白名单限制要求,即查看后台是否启用了黑白名单功能,如果启用了判断一下现在访问的IP是否允许访问
if (RestrictionManager.IsVisitAllowed(ConfigManager.SystemConfigInfo.RestrictionType, ConfigManager.Instance.RestrictionBlackList, ConfigManager.Instance.RestrictionWhiteList))
{
PageUtils.DetermineRedirectToInstaller();
PageUtils.DetermineRedirectToInstaller(); // 判断是否需要安装,如果需要则转到安装页面。

if (FileConfigManager.Instance.IsValidateCode)
if (FileConfigManager.Instance.IsValidateCode) // 根据配置判断是否需要启用验证码
{
LtlValidateCodeImage.Text =
$@"<a href=""javascript:;"" onclick=""$('#imgVerify').attr('src', $('#imgVerify').attr('src') + '&' + new Date().getTime())""><img id=""imgVerify"" name=""imgVerify"" src=""{PageValidateCode.GetRedirectUrl(_vcManager.GetCookieName())}"" align=""absmiddle"" /></a>";
}
else
else // IP被限制了,不允许访问后台
{
PhValidateCode.Visible = false;
}
Expand All @@ -57,6 +59,7 @@ public void Page_Load(object sender, EventArgs e)
}
catch
{
// 再次探测是否需要安装或升级
if (AppManager.IsNeedInstall())
{
PageUtils.Redirect("installer/default.aspx");
Expand All @@ -77,9 +80,9 @@ public override void Submit_OnClick(object sender, EventArgs e)
var account = TbAccount.Text;
var password = TbPassword.Text;

if (FileConfigManager.Instance.IsValidateCode)
if (FileConfigManager.Instance.IsValidateCode) // 根据配置判断是否需要启用验证码
{
if (!_vcManager.IsCodeValid(TbValidateCode.Text))
if (!_vcManager.IsCodeValid(TbValidateCode.Text)) // 检测验证码是否正确
{
LtlMessage.Text = GetMessageHtml("验证码不正确,请重新输入!");
return;
Expand All @@ -88,17 +91,17 @@ public override void Submit_OnClick(object sender, EventArgs e)

string userName;
string errorMessage;
if (!BaiRongDataProvider.AdministratorDao.ValidateAccount(account, password, out userName, out errorMessage))
if (!BaiRongDataProvider.AdministratorDao.ValidateAccount(account, password, out userName, out errorMessage)) // 检测密码是否正确
{
LogUtils.AddAdminLog(userName, "后台管理员登录失败");
BaiRongDataProvider.AdministratorDao.UpdateLastActivityDateAndCountOfFailedLogin(userName);
LtlMessage.Text = GetMessageHtml(errorMessage);
BaiRongDataProvider.AdministratorDao.UpdateLastActivityDateAndCountOfFailedLogin(userName); // 记录最后登录时间、失败次数+1
LtlMessage.Text = GetMessageHtml(errorMessage); // 把错误信息显示在页面上
return;
}

BaiRongDataProvider.AdministratorDao.UpdateLastActivityDateAndCountOfLogin(userName);
Body.AdministratorLogin(userName);
PageUtils.Redirect(PageUtils.GetAdminDirectoryUrl(string.Empty));
BaiRongDataProvider.AdministratorDao.UpdateLastActivityDateAndCountOfLogin(userName); // 记录最后登录时间、失败次数清零
Body.AdministratorLogin(userName); // 写Cookie并记录管理员操作日志
PageUtils.Redirect(PageUtils.GetAdminDirectoryUrl(string.Empty)); // 跳转到登录成功的后台页
}

private string GetMessageHtml(string message) => $@"<div class=""alert alert-error"">{message}</div>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ public Dictionary<int, List<string>> GetPermissionSortedList(string userName)
foreach (GovInteractPermissionsInfo permissionsInfo in permissionsInfoArrayList)
{
var list = new List<string>();
if (sortedlist[permissionsInfo.NodeID] != null)
{
list = sortedlist[permissionsInfo.NodeID];
}
// if (sortedlist[permissionsInfo.NodeID] != null)//此时sortedlist为空,引起'关键字不在字典中'错误导致用户无法登陆
//{
// list = sortedlist[permissionsInfo.NodeID];
//}

var permissionArrayList = TranslateUtils.StringCollectionToStringList(permissionsInfo.Permissions);
foreach (string permission in permissionArrayList)
Expand Down
2 changes: 0 additions & 2 deletions source/SiteServer.Web/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<appSettings>
<add key="PageInspector:ServerCodeMappingSupport" value="Disabled" />
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
<!--<add key="DatabaseType" value="SqlServer" />
<add key="ConnectionString" value="server=localhost;uid=root;pwd=root;database=test2" />-->
<add key="IsProtectData" value="False" />
<add key="DatabaseType" value="MySql" />
<add key="ConnectionString" value="server=localhost;uid=root;pwd=root;database=test3" />
Expand Down

0 comments on commit 88be303

Please sign in to comment.