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. Ex 6_23 一个生产系统共包含n个顺序执行的阶段..._第七次作业

  2. Ex 6_17 数量无限的硬币兑换问题_第七次作业

    子问题定义:定义一个数组b,大小比兑换价格的大小多一个元素,其中b[i]表示是否能用面值为x1,x2,x3,..,xn的硬币兑换价格i. 递归关系: 初值设定:设b[0]=true 求解顺序:按下标从 ...

  3. [译]bootstrap-select (selectpicker)方法

    方法 .selectpicker('val') 您可以通过调用val元素上的方法来设置所选值. $('.selectpicker').selectpicker('val', 'Mustard'); $ ...

  4. Go语言规格说明书 之 变量声明(Variable/Short variable declarations)

    go version go1.11 windows/amd64 本文为阅读Go语言中文官网的规则说明书(https://golang.google.cn/ref/spec)而做的笔记,完整的介绍Go语 ...

  5. 《Oracle 11g 入门到精通.明日科技.pdf》学习笔记

    本博文整理者:刘军 本博文出自于: <Oracle 11g 入门到精通>一书 声明:1:转载请标注出处.本文不得作为商业活动.本人不负法律责任.违法者自负一切法律责任. ————————— ...

  6. poj3237树链剖分边权+区间取负

    树链剖分+线段树lazy-tag在树链上操作时千万不要写错.. /* 树链剖分+线段树区间变负 */ #include<iostream> #include<cstring> ...

  7. 【APUE | 08】进程控制

    函数fork 博文链接: 1. 代码示例: #include "apue.h" ; char buf[] = "a write to stdout\n"; in ...

  8. .NetCore源码阅读笔记系列之Security (四) Authentication & AddJwtBearer

    接下来我们在来看下AddJwtBearer,这个与AddOpenIdConnect不太一样,后者是远程发起身份认证请求是一种主动发起式的,多用于web等客户端,验证发生在身份认证服务端,而前者是一种被 ...

  9. bootstrapTable 参数说明

  10. 036 关于网站的UV分析

    一:准备 1.统计的维度 guid tracktime provice 2.key与value的设定 key:date+provice_guid value:NullWritable 3.案例分析 表 ...