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的更多相关文章

  1. 使用 IntraWeb (24) - 基本控件之 TIWFileUploader、TIWFile

    TIWFileUploader 是基于 Ajax 的上传控件, 最初是 Andrew Valums 开发, 从 IntraWeb XIV 纳入并替换 TIWFile. 虽然从组件面板上还能看到 TIW ...

  2. 使用 IntraWeb (28) - 基本控件之 TIWTemplateProcessorHTML、TIWLayoutMgrHTML、TIWLayoutMgrForm

    TIWTemplateProcessorHTML //使用外部的 html 文件做模板 TIWLayoutMgrHTML //直接输入 Html 文本做模板 TIWLayoutMgrForm //这应 ...

  3. 使用 IntraWeb (26) - 基本控件之 TIWMenu

    TIWMenu 的任务是让原来的 TMainMenu 呈现在网页上, 通过其 AttachedMenu 属性关联一个 TMainMenu 是必需的. TIWMenu 所在单元及继承链: IWCompM ...

  4. 使用 IntraWeb (25) - 基本控件之 TIWRegion

    这应该是 IW 中最重要的容器了, 和它同父的还有 TIWTabControl TIWRegion 所在单元及继承链: IWRegion.TIWRegion 主要成员: property Align: ...

  5. 使用 IntraWeb (23) - 基本控件之 TIWTimer、TIWProgressBar、TIWProgressIndicator、TIWTimeEdit

    TIWTimer //和 TTimer 没多大区别, 它的默认事件现在是异步的(OnAsyncTimer), 在网络上使用 OnTimer 肯定是非常糟糕的 TIWProgressBar //进度条 ...

  6. 使用 IntraWeb (22) - 基本控件之 TIWCalendar

    TIWCalendar: 日历控件, 继承于 TIWCustomGrid, 所以它和 TIWGrid 共同属性特多. 它的 Cell 是 TIWCalendarCell 对象, 直接从 TIWGrid ...

  7. 使用 IntraWeb (20) - 基本控件之 TIWGrid

    TIWGrid 最终通过 Html Table 呈现; 其每个 Cell 都是一个 TIWGridCell 对象, Cell 对象的 Control 属性非常好, 可以非常方便地嵌入其他控件. TIW ...

  8. 使用 IntraWeb (19) - 基本控件之 TIWTreeView

    这是个饱受非议的控件; 我通过尝试, 理解了非议, 也能理解作者. 总之向作者的思路靠拢吧, 还是不错的. TIWTreeView 所在单元及继承链: IWCompTreeview.TIWTreeVi ...

  9. 使用 IntraWeb (16) - 基本控件之 TIWList、TIWListbox、TIWComboBox、TIWOrderedListbox

    TIWList //列表; 它对应 Html 中的 OL.LI(某些选项下会用表格模拟); TIWListbox 和 TIWComboBox 则对应 Html 在的 Option TIWListbox ...

随机推荐

  1. 使用FreeSWITCH做电话自动回访设置

    一.背景介绍: 目前公司在处理客户回访方面,需要人工进行电话回访,尤其是逢年过节的时候,电话问候更能体现服务的品质: 在某些公司,电话销售员需要给大批量的陌生用户打电话,如果能过滤掉不关心的用户,销售 ...

  2. 5种PHP创建数组的方式

    在PHP以及其他程序语言程序设计中,经常会用到数组的创建,在前端开发中,js的数组创建可以由[]和new Array()直接创建和赋值.然而PHP创建数组的方法有哪些呢?在查阅资料并且网上收集整理总结 ...

  3. excel导出的时候从程序后台写到excel里的是文本,所以无法在excel中计算怎么办?

    文章引用自:http://www.cnblogs.com/rayray/p/3414452.html excel导出的时候从程序后台写到excel里的是文本,所以无法在excel中计算怎么办? 需要导 ...

  4. window.open子窗口获取父窗口的值

    //子窗口获取父窗口id的值 window.opener.document.getElementById("id").value; //子窗口调用父窗口的函数 window.ope ...

  5. python 全栈开发,Day86(上传文件,上传头像,CBV,python读写Excel,虚拟环境virtualenv)

    一.上传文件 上传一个图片 使用input type="file",来上传一个文件.注意:form表单必须添加属性enctype="multipart/form-data ...

  6. python 全栈开发,Day21(抽象类,接口类,多态,鸭子类型)

    一.昨日复习 派生方法和派生属性 super 只有在子父类拥有同名方法的时候, 想使用子类的对象调用父类的方法时,才使用super super在类内 : super().方法名(arg1,..) 指名 ...

  7. String中的toCharArray:将此字符串转换为新的字符数组,并统计次数

    package stringyiwen; public class StringTestToCharArray { public static void main(String[] args) { S ...

  8. thinkphp注册验证

    在model中新建一个UserModel //覆盖原本的设置 //一次性获得全部验证错误 protected $patchValidate = true; //实现表单项目验证 //通过重写父类属性_ ...

  9. k8s 使用详解

    转自:https://www.cnblogs.com/gaoyuechen/p/8685771.html

  10. C语言 —— sprintf()函数

    sprintf() 函数 例如: #include<stdio.h> int main() { //注意s一定要先初始化! *sizeof(char)); //或char s[40]; s ...