protected LoginRecordInfo PopulateLoginRecord(IDataReader reader) { LoginRecordInfo entity = new LoginRecordInfo() { ID = (int)reader["ID"], AdminID = (int)reader["AdminID"], LastLoginIP = reader["LastLoginIP"] as string, LoginTime = DataConvert.SafeDate(reader["LoginTime"]), UserName = reader["UserName"] as string }; return(entity); }
/// <summary> /// 用户登录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btSave_Click(object sender, EventArgs e) { if (Page.IsValid) { string userName = StrHelper.Trim(txtUserName.Value); string password = StrHelper.Trim(txtUserPwd.Value); ///用户名,密码,验证码不允许为空 if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password)) { int id = Admins.Instance.ValiUser(userName, EncryptString.MD5(password));//验证用户 if (id > 0) { AdminInfo admin = Admins.Instance.GetAdmin(id); if (admin.State == "1") { admin.LastLoginIP = WebHelper.GetClientsIP(); admin.LastLoginTime = DateTime.Now; admin.LoginTimes++; Admins.Instance.UpdateAdmin(admin); LoginRecordInfo lr = new LoginRecordInfo() { AdminID = admin.ID, LastLoginIP = admin.LastLoginIP, LoginTime = DateTime.Now, UserName = admin.UserName }; Admins.Instance.AddLoginRecord(lr); Session[GlobalKey.SESSION_ADMIN] = admin; ManageCookies.CreateCookie(GlobalKey.SESSION_ADMIN, id.ToString(), true, DateTime.Today.AddDays(1), HXContext.Current.CookieDomain); Response.Redirect("index.aspx"); } else lblMsg.Text = "用户状态异常,请联系管理员"; } else lblMsg.Text = "用户名或密码错误"; Session[GlobalKey.SESSION_ADMIN] = null; } } }
public void AddLoginRecord(LoginRecordInfo lr) { CommonDataProvider.Instance().AddLoginRecord(lr); }
public abstract void AddLoginRecord(LoginRecordInfo lr);
public override void AddLoginRecord(LoginRecordInfo lr) { string sql = @" INSERT INTO ComOpp_LoginRecord( [AdminID] ,[UserName] ,[LastLoginIP] ,[LoginTime] ) VALUES ( @AdminID ,@UserName ,@LastLoginIP ,@LoginTime )"; SqlParameter[] p = { new SqlParameter("@AdminID",lr.AdminID), new SqlParameter("@UserName",lr.UserName), new SqlParameter("@LastLoginIP",lr.LastLoginIP), new SqlParameter("@LoginTime",lr.LoginTime) }; SqlHelper.ExecuteNonQuery(_con, CommandType.Text, sql, p); }
protected LoginRecordInfo PopulateLoginRecord(IDataReader reader) { LoginRecordInfo entity = new LoginRecordInfo() { ID = (int)reader["ID"], AdminID = (int)reader["AdminID"], LastLoginIP = reader["LastLoginIP"] as string, LoginTime = DataConvert.SafeDate(reader["LoginTime"]), UserName = reader["UserName"] as string }; return entity; }