使用 IntraWeb (29) - 基本控件之 TIWAutherList、TIWAutherINI、TIWAutherEvent
TIWAutherList //通过一组户名与密码验证登陆
TIWAutherINI //通过记录户名与密码信息的 #Auth.ini 文件验证登陆
TIWAutherEvent //通过其 OnCheck 事件验证登陆 {作为站点级的验证, 验证控件应该是放在 ServerController 的窗体上, 并与其 Auther 属性关联.}
TIWAutherList 所在单元及继承链:
IWAutherList.TIWAutherList
主要成员:
property List: TStrings //户名与密码表; 每行按 User=Pass 的格式输入
property AutherPolicy: TAutherPolicy //该属性有两个选项 apRestrictAll(默认)、apRestrictNone(选这个表示不执行验证) property OnAuthenticate: TOnAuthenticate //验证成功后执行的事件
测试 TIWAutherList:
{在 ServerController 的窗体上放置 IWAutherList1, 然后双击该窗体(激活其 OnCreate 事件)}
procedure TIWServerController.IWServerControllerBaseCreate(Sender: TObject);
begin
Self.Auther := IWAutherList1;
IWAutherList1.List.Add('aaa=111');
IWAutherList1.List.Add('bbb=222');
IWAutherList1.List.Values['ccc'] := '333';
end;
{这就好了, 如果在设计时完成上面工作会更方便}

TIWAutherINI 所在单元及继承链:
IWAutherINI.TIWAutherINI
主要成员:
property AutherPolicy: TAutherPolicy //
property OnAuthenticate: TOnAuthenticate //
{它需要的 ini 文件须命名为 #Auth.ini(它会保证不被用户读取, 应该使用 UTF8 格式保存), 并且和程序文件放在同一目录(而非 wwwroot 下)}
{其格式规范:--------------------
[户名1]
Password=密码1
[户名2]
Password=密码2
...
------------------------------}
{建好文件, 放对地方, 再关联上 Auther 属性就可以了}
TIWAutherEvent 所在单元及继承链:
IWAutherEvent.TIWAutherEvent
主要成员:
property AutherPolicy: TAutherPolicy // property OnCheck: TOnCheck //就是在该事件中验证; 假如要从数据库验证就应该用这种方法
property OnAuthenticate: TOnAuthenticate // {更多时候可能需要把验证函数写在 UserSessionUnit 单元(譬如通过数据库验证时), 这时应该保证 IWServerController.AuthBeforeNewSession = False(这也是默认值)}
测试 TIWAutherEvent:
{IWAutherEvent1 的 OnCheck 事件}
function TIWServerController.IWAutherEvent1Check(const aUser, aPass: string): Boolean;
begin
Result := aPass = aUser + '123'; //假如密码是: 用户名+123
end;
{需要保证关联到 Auther 属性}
procedure TIWServerController.IWServerControllerBaseCreate(Sender: TObject);
begin
Auther := IWAutherEvent1;
end;
还是上面的例子, 现在改成通过 TIWUserSession 的一个方法来验证:
{UserSessionUnit.pas}
unit UserSessionUnit;
interface
uses
IWUserSessionBase, SysUtils, Classes;
type
TIWUserSession = class(TIWUserSessionBase)
private
public
function MyCheck(const AUser, APass: string): Boolean;
end;
implementation
{$R *.dfm}
{ TIWUserSession }
function TIWUserSession.MyCheck(const AUser, APass: string): Boolean;
begin
Result := APass.ToLower = AUser.ToLower + '123';
end;
end.
{-------------------------------------------------}
{ServerController.pas, 有注释的是自己添加的代码}
unit ServerController;
interface
uses
SysUtils, Classes, IWServerControllerBase, IWBaseForm, HTTPApp,
UserSessionUnit, IWApplication, IWAppForm, IW.Browser.Browser, IWAutherEvent, IWAutherINI, IWAutherBase, IWAutherList;
type
TIWServerController = class(TIWServerControllerBase)
IWAutherEvent1: TIWAutherEvent;
procedure IWServerControllerBaseNewSession(ASession: TIWApplication);
procedure IWServerControllerBaseCreate(Sender: TObject);
function IWAutherEvent1Check(const aUser, aPass: string): Boolean;
private
public
end;
function UserSession: TIWUserSession;
function IWServerController: TIWServerController;
implementation
{$R *.dfm}
uses
IWInit, IWGlobal;
function IWServerController: TIWServerController;
begin
Result := TIWServerController(GServerController);
end;
function UserSession: TIWUserSession;
begin
Result := TIWUserSession(WebApplication.Data);
end;
{IWAutherEvent1 的 OnCheck 事件, 调用 UserSessionUnit.TIWUserSession 的验证函数}
function TIWServerController.IWAutherEvent1Check(const aUser, aPass: string): Boolean;
begin
Result := UserSession.MyCheck(aUser, aPass);
end;
{OnCreate 事件, 这个关联可以在设计时做}
procedure TIWServerController.IWServerControllerBaseCreate(Sender: TObject);
begin
Auther := IWAutherEvent1;
end;
procedure TIWServerController.IWServerControllerBaseNewSession(ASession: TIWApplication);
begin
ASession.Data := TIWUserSession.Create(nil, ASession);
end;
initialization
TIWServerController.SetServerControllerClass;
end.
使用 IntraWeb (29) - 基本控件之 TIWAutherList、TIWAutherINI、TIWAutherEvent的更多相关文章
- 使用 IntraWeb (24) - 基本控件之 TIWFileUploader、TIWFile
TIWFileUploader 是基于 Ajax 的上传控件, 最初是 Andrew Valums 开发, 从 IntraWeb XIV 纳入并替换 TIWFile. 虽然从组件面板上还能看到 TIW ...
- 使用 IntraWeb (28) - 基本控件之 TIWTemplateProcessorHTML、TIWLayoutMgrHTML、TIWLayoutMgrForm
TIWTemplateProcessorHTML //使用外部的 html 文件做模板 TIWLayoutMgrHTML //直接输入 Html 文本做模板 TIWLayoutMgrForm //这应 ...
- 使用 IntraWeb (26) - 基本控件之 TIWMenu
TIWMenu 的任务是让原来的 TMainMenu 呈现在网页上, 通过其 AttachedMenu 属性关联一个 TMainMenu 是必需的. TIWMenu 所在单元及继承链: IWCompM ...
- 使用 IntraWeb (25) - 基本控件之 TIWRegion
这应该是 IW 中最重要的容器了, 和它同父的还有 TIWTabControl TIWRegion 所在单元及继承链: IWRegion.TIWRegion 主要成员: property Align: ...
- 使用 IntraWeb (23) - 基本控件之 TIWTimer、TIWProgressBar、TIWProgressIndicator、TIWTimeEdit
TIWTimer //和 TTimer 没多大区别, 它的默认事件现在是异步的(OnAsyncTimer), 在网络上使用 OnTimer 肯定是非常糟糕的 TIWProgressBar //进度条 ...
- 使用 IntraWeb (22) - 基本控件之 TIWCalendar
TIWCalendar: 日历控件, 继承于 TIWCustomGrid, 所以它和 TIWGrid 共同属性特多. 它的 Cell 是 TIWCalendarCell 对象, 直接从 TIWGrid ...
- 使用 IntraWeb (20) - 基本控件之 TIWGrid
TIWGrid 最终通过 Html Table 呈现; 其每个 Cell 都是一个 TIWGridCell 对象, Cell 对象的 Control 属性非常好, 可以非常方便地嵌入其他控件. TIW ...
- 使用 IntraWeb (19) - 基本控件之 TIWTreeView
这是个饱受非议的控件; 我通过尝试, 理解了非议, 也能理解作者. 总之向作者的思路靠拢吧, 还是不错的. TIWTreeView 所在单元及继承链: IWCompTreeview.TIWTreeVi ...
- 使用 IntraWeb (16) - 基本控件之 TIWList、TIWListbox、TIWComboBox、TIWOrderedListbox
TIWList //列表; 它对应 Html 中的 OL.LI(某些选项下会用表格模拟); TIWListbox 和 TIWComboBox 则对应 Html 在的 Option TIWListbox ...
随机推荐
- zabbix3.0.4关于java服务端程序内存溢出的处理
关于java服务端程序内存溢出的处理 java服务端程序内存溢出会产生jvm.log文件,此时程序会挂掉,无法正常处理业务,需要重启服务 思路: 当存在jvm.log这个文件的时候则触发clean_j ...
- elasticsearch5.0集群大数据量迁移方法及注意事项
当es集群的数据量较小的情况下elasticdump这个工具比较方便,但是当数据量达到一定级别比如上百G的时候,elasticdump速度就很慢了,此时我们可以使用快照的方法进行备份 elasticd ...
- centos下httpd-2.4的编译安装
httpd-2.4编译安装 依赖于更高版本的apr和apr-util apr 全称 apache portable runtime 首先停用低版本的httpd服务 service ...
- Android主题切换
一.APK文件方式:(CM9方案) 我们知道Android给每个APK进程分配一个单独的用户空间,其manifest中的userid就是对应一个Linux用户的(Android 系统是基于Linux) ...
- Jquery hover方法使用及 mouseenter与mouseleave和 mouseover与mouseout的区别
定义和用法 hover() 方法规定当鼠标指针悬停在被选元素上时要运行的两个函数. jQuery 1.7 版本前该方法触发 mouseenter 和 mouseleave 事件. jQuery 1.8 ...
- oracle11g客户端配置及使用(Windows系统)
一.安装Oracle客户端 本文环境: 操作系统:Windows XP Pro sp3(简体中文)32位 1. 首先去官网下载Oracle 11g (1) win32_11gR2_database_1 ...
- js闭包实例汇总
本文是通过实例来帮助大家深刻理解js闭包,是篇非常不错的文章,这里推荐给大家,有需要的小伙伴可以参考下 Js闭包 闭包前要了解的知识 1. 函数作用域 (1).Js语言特殊之处在于函数内部可以直接读取 ...
- 温故而知新--JavaScript书摘(一)
前言: 毕业到入职腾讯已经差不多一年的时光了,接触了很多项目,也积累了很多实践经验,在处理问题的方式方法上有很大的提升.随着时间的增加,愈加发现基础知识的重要性,很多开发过程中遇到的问题都是由最基础的 ...
- python的开发环境配置-Eclipse-PyDev插件安装
安装PyDev插件的两种安装方法: 1.百度搜索PyDev 2.4.0.zip,下载后解压,得到Plugins和Feature文件夹,复制两文件夹到Eclipse目录,覆盖即可. 插件的版本要对应py ...
- 移位操作符 << >> >>>
按位操作符只可用于int类型,其它类型都会转化位int类型在操作,并且只有数值右端的低5位才右用(因为2^5=32) << 左移位操作符,低位补零 >> 右移位操作符,有符 ...