全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2500
推到 Plurk!
推到 Facebook!

Delphi[問題]IntraWeb有關會員登入登出的程式

答題得分者是:pcplayer99
inglong
初階會員


發表:28
回覆:27
積分:36
註冊:2004-08-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-10-13 11:28:44 IP:218.160.xxx.xxx 未訂閱
我想要用IntraWeb建立一個會員系統,例如從首頁登入之後,到下一頁都是能顯示這個會員的名稱,以及登出的方法...資料庫使用MSSQL 下面是我登入的code.... 因此我的問題就是:1.從首頁登入之後,到下一頁都是能顯示這個會員的名稱 2.我要如何登出(是對資料庫的連結中斷或是其他的方式) procedure TformMain.LoginClick(Sender: TObject); var ManageForm:TformMain1; //登入的頁面 i:Integer; tryaccount,trypassword:String; begin tryaccount:='';//比對帳號用 trypassword:='';//比對密碼 tryaccount:=copy(Account.Text,pos('=',Account.Text) 1,length(Account.Text)); trypassword:=copy(Password.Text,pos('=',Password.Text) 1,length(Password.Text)); Database1.Connected:=True; Query1.Active:=true; Query1.First; For i:=0 to Query1.RecordCount-1 do begin If ( tryaccount<>Query1.Fields[0].AsString ) then Begin Query1.Next; end; If ( tryaccount=Query1.Fields[0].AsString )then Begin If ( trypassword=Query1.Fields[1].AsString )then Begin//帳號密碼都符合便登入 ManageForm:=TformMain1.Create(WebApplication); ManageForm.Show; end; end; If ( tryaccount=Query1.Fields[0].AsString ) and ( trypassword<>Query1.Fields[1].AsString ) then Begin Clear.Caption:='密碼錯誤'; end; end; end; 何需Coding爭峰 千人指 萬人鋒 敢問Coding頂峰 三尺秋水塵不染 天下無雙
------
何需Coding爭峰
千人指 萬人鋒
敢問Coding頂峰
三尺秋水塵不染
天下無雙
pcplayer99
尊榮會員


發表:146
回覆:790
積分:632
註冊:2003-01-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-10-13 16:07:01 IP:219.133.xxx.xxx 未訂閱
我从你的代码里并没看到关于在线的使用者信息的部分。 程序必须实现一个列表,登记在线的使用者。每次这个使用者访问某个页面,就要先对比它留在这个列表里的资料,看他是不是那个最初用UISER ID/PASS来登入人。如果是他,你的程序才可以确认是他。 具体到 IntraWeb,IntraWeb自己为每个在线用户维护一个Session,你可以在那个Session里增加一些字段,比如记录这个User登入时填写的资料。这个用户在访问第二个页面的时候,通过IntraWeb的Session可以知道当前是哪个客户了。 这个 Session 有个TimeOut的设置,用户超过这个时间没访问,IntraWeb为他保留的Session就失效了。再次访问,IntraWeb为他生成一个新的Session,程序就不知道他是谁,他就要重新登入了。 大概的概念就是这样,具体的代码你可以看IntraWeb的例子。不过我手上的IntraWeb的DEMO里对Session的管理有问题,会造成内存泄露。不知道最新的DEMO是否解决了这个问题。
inglong
初階會員


發表:28
回覆:27
積分:36
註冊:2004-08-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-10-13 23:20:31 IP:218.160.xxx.xxx 未訂閱
這是我修改後的 其中IWunit1是我輸入帳號和密碼的地方     Unit1是登入後的地方 現在有一個疑問:我要從Unit1登出回到IWunit1假設我用一個Button來控制 code==>:TformMain.Create(WebApplication).show 但是我無法返回,並出現錯誤...:請問是哪種原因呢?    下面是還沒加登出的code program IWProject; {PUBDIST}    uses   IWInitStandAlone,   ServerController in 'ServerController.pas' {IWServerController: TDataModule},   IWUnit1 in 'IWUnit1.pas' {formMain: TIWForm1},   Unit1 in 'Unit1.pas' {formMain1: TIWAppForm};    {$R *.res}    begin   IWRun(TFormMain, TIWServerController); end.    unit IWunit1; {PUBDIST}    interface    uses   SysUtils, IWAppForm, IWApplication, IWTypes, IWCompLabel, IWCompEdit, Classes,   Controls, IWControl, IWCompButton, DB, DBTables;    type   TformMain = class(TIWAppForm)     IWButton1: TIWButton;     IWEdit1: TIWEdit;     IWLabel1: TIWLabel;     IWLabel2: TIWLabel;     IWEdit2: TIWEdit;     Database1: TDatabase;     Query1: TQuery;     Query2: TQuery;     DataSource1: TDataSource;     procedure IWButton1Click(Sender: TObject);   private     procedure SaveToCookie; //¬ö¿ýcookie     procedure LoadFromCookie; //Ū¨úCookie     procedure RemoveSession(ASessionID:string);//²¾°£session     function CheckUser(AUserName:string;APassword:string):Boolean;//½T»{±b¸¹±K½X¨ç¼Æ   public     procedure DispatchToPage(APageClass:TIWAppFormClass);     procedure GenerateForm(AStream:TStream);override;   end;    implementation {$R *.dfm}    uses   ServerController,IWInit,Unit1;    const s'UserID'; sSessionID='LastSessionID';    procedure TformMain.RemoveSession(ASessionID:string); var I:Integer; vPtr:TIWApplication; vList:TList; Begin vList:=GSessions.LockList; try  for I:=0 to vList.Count-1 do   begin    vPtr:=TIWApplication(vList[I]);    if vPtr.AppID=ASessionID then     begin      vList.Remove(vPtr);      vPtr.Free;      break;     end;   end;  finally    GSessions.UnlockList;  end; end;    procedure TformMain.GenerateForm(AStream:Tstream); begin  LoadFromCookie;  if UserSession.UserName<>'' then    begin     DispatchToPage(TformMain1);     TIWAppForm(RWebApplication.ActiveForm).GenerateForm(AStream);     if UserSession.LastSession<>RWebApplication.AppID then     Begin      RemoveSession(UserSession.LastSession);     end;     SaveToCookie;    end    else    inherited GenerateForm(AStream); end;    procedure TformMain.DispatchToPage(APageClass:TIWAppFormClass); Begin  TIWAppForm(RWebApplication).Release;  APageClass.Create(RWebApplication).show; end;    procedure TformMain.LoadFromCookie; begin   if RwebApplication.Request.CookieFields.Values[sUserID]<>'' then     begin       if CheckUser(RWebApplication.Request.CookieFields.Values[sUserID],'')then        begin         UserSession.UserName:=RWebApplication.Request.CookieFields.Values[sUserID];         UserSession.LastSession:=RWebApplication.Request.CookieFields.Values[sSessionID];        end;     end     else     Begin       UserSession.UserName:='';       UserSession.LastSession:='';     end; end;    procedure TformMain.SaveToCookie; var  vList:TStrings; Begin  vList:=TStringList.Create; try  vList.Add(Format('%s=%s',[sUserID,UserSession.UserName]));  vList.Add(Format('%s=%s',[sSessionID,RWebApplication.AppID]));  RWebApplication.Response.SetCookieField(vList,'127.0.0.1','',Now+2,False); finally  vList.Free;  end; end;    function TformMain.CheckUser(AUserName:string;APassword:string):Boolean; var i:Integer; begin   Database1.Connected:=True;   Query1.Active:=true;   Query1.First;   For i:=0 to Query1.RecordCount-1 do   Begin     If IWEdit1.Text=Query1.Fields[0].AsString then     Begin       If IWedit2.Text=Query1.Fields[1].AsString then       begin         Result:=True       end       else       begin           Result:=false;       end;     end     else     Begin       Query1.Next;       if i=query1.RecordCount-1 then       Begin         Result:=false;       end;     end;   end; end;    procedure TformMain.IWButton1Click(Sender: TObject); begin   if CheckUser(IWEdit1.Text,IWEdit2.Text)then   begin   TIWAppForm(RWebApplication.ActiveForm).Release;   Tformmain1.Create(RWebApplication).show;   UserSession.UserName:=IWedit1.Text;   SaveToCookie;   end   else   begin   RWebApplication.showMessage('error');   end; end;    end.    unit Unit1; {PUBDIST}    interface    uses   SysUtils, IWAppForm, IWApplication, IWTypes, Classes, Controls, IWControl,   IWCompLabel, IWCompButton;    type   TformMain1 = class(TIWAppForm)     IWLabel1: TIWLabel;     procedure IWAppFormRender(Sender: TObject);   public   end;    implementation {$R *.dfm}    uses   ServerController,IWUnit1,IWInit;    procedure TformMain1.IWAppFormRender(Sender: TObject); begin   IWLabel1.Caption:=UserSession.UserName; end;        end.    unit ServerController; {PUBDIST}    interface    uses   SysUtils, Classes, IWServerControllerBase,   // For OnNewSession Event   IWApplication, IWAppForm;    type   TIWServerController = class(TIWServerControllerBase)     procedure IWServerControllerBaseNewSession(ASession: TIWApplication;       var VMainForm: TIWAppForm);   private   public   end;      // This is a class which you can add variables to that are specific to the user. Add variables   // to this class instead of creating global variables. This object can references by using:   //   UserSession   // So if a variable named UserName of type string is added, it can be referenced by using:   //   UserSession.UserName   // Such variables are similar to globals in a normal application, however these variables are   // specific to each user.   //   // See the IntraWeb Manual for more details.   TUserSession = class   private     FUserName:string;     FLastSession:string;   public     property UserName:string read FUserName write FUserName;     property LastSession:string read FLastSession write FLastSession;   end;    // Procs   function UserSession: TUserSession;    implementation {$R *.dfm}    uses   IWInit;    function UserSession: TUserSession; begin   Result := TUserSession(RWebApplication.Data); end;    procedure TIWServerController.IWServerControllerBaseNewSession(   ASession: TIWApplication; var VMainForm: TIWAppForm); begin   ASession.Data := TUserSession.Create; end;    end.     
 
何需Coding爭峰 千人指 萬人鋒 敢問Coding頂峰 三尺秋水塵不染 天下無雙
------
何需Coding爭峰
千人指 萬人鋒
敢問Coding頂峰
三尺秋水塵不染
天下無雙
inglong
初階會員


發表:28
回覆:27
積分:36
註冊:2004-08-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-10-14 09:51:59 IP:218.160.xxx.xxx 未訂閱
Q. 在IntraWeb中如何呼叫另外一個Form 或Form 與 Form 之間要如何傳值? A. 建立Form. TYourForm.Create(WebApplication).Show; 當Form 1 切換到 Form 2,並需要傳遞某變數至Form 2. var OldForm:TYourForm; begin OldForm:=TYourForm(WebApplication.ActiveForm); TYour2Form.Create(WebApplication).Show; TYour2Form(WebApplication.ActiveForm).SomeMember:= OldForm.SomeMember; //release old form OldForm.Release; end; 另外, 你可以用 UserSession 取得變數 // FormMain 中 procedure TformMain.IWButton1Click(Sender: TObject); var Form: TfrmUnit1; begin UserSession.UserName := edUserName.Text; UserSession.Password := edPassword.Text; Form := TfrmUnit1.Create( WebApplication); Form.Show; end; // frmUnit1 中 procedure TfrmUnit1.IWAppFormCreate(Sender: TObject); begin Edit1.Text := UserSession.UserName; Edit2.Text := UserSession.Password; end; 何需Coding爭峰 千人指 萬人鋒 敢問Coding頂峰 三尺秋水塵不染 天下無雙
------
何需Coding爭峰
千人指 萬人鋒
敢問Coding頂峰
三尺秋水塵不染
天下無雙
tonyplus
初階會員


發表:22
回覆:97
積分:28
註冊:2002-04-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-10-15 14:34:26 IP:61.57.xxx.xxx 未訂閱
Code6421前輩在站上針對IntraWeb的問題,有很多精闢的解答, 您可以試著去找找看,也許會更快得到答案的!! 發表人 -
系統時間:2024-05-20 11:16:36
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!