protected void Page_Load(object sender, EventArgs e) { Security.CheckAdministerAndRedirect(); if (!Page.IsPostBack) { if (this.Action == "edit") { int adminid = HYRequest.GetQueryInt("adminid", 0); AdminModel info = AdminFactory.Get(adminid); this.txtusername.Text = info.username; this.txtusername.Enabled = false; } } }
public static bool Login(string username, string password, out string tips) { AdminModel info = AdminFactory.Get(username); if (info == null) { tips = "此用户不存在!"; return(false); } if (info.userpwd != Utils.MD5(password)) { tips = "密码不正确!"; return(false); } WriteUserCookie(info, 0); tips = "登陆成功!"; return(true); }
protected void btnSave_Click(object sender, EventArgs e) { if (this.Action == "edit") { int adminid = HYRequest.GetQueryInt("adminid", 0); AdminModel info = AdminFactory.Get(adminid); if (info != null) { string pwdstr = this.txtpassword.Text.Trim(); if (!string.IsNullOrEmpty(pwdstr)) { info.userpwd = Utils.MD5(pwdstr); } AdminFactory.Update(info); Response.Redirect("adminlist.aspx"); } } else if (this.Action == "add") { //验证是否存在同名的帐号 AdminModel info = null; string username = this.txtusername.Text.Trim(); info = AdminFactory.Get(username); if (info != null) { ClientScript.RegisterStartupScript(this.GetType(), "AddEditTips", "<script language=\"javascript\">alert('已存在相同的帐号!');window.location='adminedit.aspx?action=add';</script>"); return; } info = new AdminModel(); info.username = this.txtusername.Text.Trim(); info.userpwd = Utils.MD5(this.txtpassword.Text.Trim()); AdminFactory.Add(info); Response.Redirect("adminlist.aspx"); } }