📄 userlogin.cs
字号:
namespace PowerEasy.WebSite
{
using PowerEasy.Components;
using PowerEasy.Controls;
using PowerEasy.Enumerations;
using PowerEasy.Model.UserManage;
using PowerEasy.UserManage;
using PowerEasy.Web.UI;
using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class UserLogin : DynamicPage
{
protected DropDownList DropExpiration;
protected ImageButton IbtnEnter;
protected HtmlForm Login;
protected PlaceHolder PhValCode;
protected TextBox TxtPassword;
protected TextBox TxtUserName;
protected TextBox TxtValidateCode;
protected ValidationSummary ValidationSummary1;
protected PowerEasy.Controls.RequiredFieldValidator ValrPassword;
protected PowerEasy.Controls.RequiredFieldValidator ValrUserName;
protected PowerEasy.Controls.RequiredFieldValidator ValrValidateCode;
protected ValidateCode VcodeLogin;
internal static string GetRedirectUrl()
{
HttpContext current = HttpContext.Current;
string str = current.Request.QueryString["ReturnUrl"];
if (str == null)
{
str = current.Request.Form["ReturnUrl"];
if ((!string.IsNullOrEmpty(str) && !str.Contains("/")) && str.Contains("%"))
{
str = HttpUtility.UrlDecode(str);
}
}
if ((!string.IsNullOrEmpty(str) && !FormsAuthentication.EnableCrossAppRedirects) && !IsPathOnSameServer(str, current.Request.Url))
{
str = null;
}
if (str == null)
{
return FormsAuthentication.DefaultUrl;
}
return str;
}
protected void IbtnEnter_Click(object sender, ImageClickEventArgs e)
{
UserPrincipal principal;
UserInfo userInfo = new UserInfo();
userInfo.UserName = this.TxtUserName.Text.Trim();
userInfo.UserPassword = this.TxtPassword.Text.Trim();
if (SiteConfig.UserConfig.EnableCheckCodeOfLogin && (string.Compare(this.TxtValidateCode.Text.Trim(), this.VcodeLogin.ValidateCodeValue, true) != 0))
{
DynamicPage.WriteErrMsg("<li>您输入的验证码和系统产生的不一致,请重新输入。</li>");
}
if (Users.ValidateUser(userInfo) != UserStatus.None)
{
DynamicPage.WriteErrMsg("<li>用户登录名称或用户密码不对或用户帐号处于非正常状态!</li>");
return;
}
bool isPersistent = false;
DateTime now = DateTime.Now;
DateTime expiration = DateTime.Now;
string selectedValue = this.DropExpiration.SelectedValue;
if (selectedValue != null)
{
if (!(selectedValue == "None"))
{
if (selectedValue == "Day")
{
isPersistent = true;
expiration = now.AddDays(1.0);
goto Label_0130;
}
if (selectedValue == "Month")
{
isPersistent = true;
expiration = now.AddMonths(1);
goto Label_0130;
}
if (selectedValue == "Year")
{
isPersistent = true;
expiration = now.AddYears(1);
goto Label_0130;
}
}
else
{
isPersistent = false;
expiration = now.AddDays(1.0);
goto Label_0130;
}
}
isPersistent = false;
expiration = now.AddMinutes(20.0);
Label_0130:
principal = new UserPrincipal();
principal.UserName = userInfo.UserName;
principal.LastPassword = userInfo.LastPassword;
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userInfo.UserName, now, expiration, isPersistent, principal.SerializeToString());
string str = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, str);
if (isPersistent)
{
cookie.Expires = expiration;
}
cookie.HttpOnly = true;
cookie.Path = FormsAuthentication.FormsCookiePath;
cookie.Secure = FormsAuthentication.RequireSSL;
base.Response.Cookies.Add(cookie);
this.Session["UserName"] = userInfo.UserName;
base.Response.Redirect(GetRedirectUrl());
}
internal static bool IsPathOnSameServer(string absUriOrLocalPath, Uri currentRequestUri)
{
Uri uri;
if (Uri.TryCreate(absUriOrLocalPath, UriKind.Absolute, out uri) && !uri.IsLoopback)
{
return string.Equals(currentRequestUri.Host, uri.Host, StringComparison.OrdinalIgnoreCase);
}
return true;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!SiteConfig.UserConfig.EnableCheckCodeOfLogin)
{
this.PhValCode.Visible = false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -