erich.wanker Posted October 7, 2014 Posted October 7, 2014 Hello, i want to close the old Session - if the same username starts a new Session Any ideas how i can do this? - one user should not be able to start the Software unlimited in his company - every user should buy a licence ;-) Any Ideas? Quote
Administrators Farshad Mohajeri Posted October 7, 2014 Administrators Posted October 7, 2014 var ASessionList: TList; I : Integer; M : TUniMainModule; USession : TUniGUISession; begin ASessionList := UniServerModule.SessionManager.Sessions.SessionList.LockList; try for I := 0 to ASessionList.Count -1 do begin USession := TUniGUISession(ASessionList[i]); M := USession.UniMainModule as TUniMainModule; if M.username = 'ThisUserName' then begin USession.TerminateAfterSecs(0); Break; end; end; finally UniServerModule.SessionManager.Sessions.SessionList.UnlockList; end; end; This may help. Quote
mhmda Posted October 23, 2014 Posted October 23, 2014 How Can I send a message to user before terminating his session? Quote
erich.wanker Posted October 23, 2014 Author Posted October 23, 2014 i hope - i understand you right: In Main / Script: function bunload(){ dontleave="Softwarename"; return dontleave; }; function ounload(){ ajaxRequest(MainForm.window, 'SessionClosed', [] ); }; onbeforeunload = bunload; onunload=ounload; procedure TMainForm.UniFormAjaxEvent(Sender: TComponent; EventName: string; Params: TStrings); begin if EventName ='SessionClosed' then begin UniServerModule.Logger.AddLog('Session Closed..',mainform.aktuell_session+mainform.aktuell_ip+'Softwarename'); uniapplication.terminate; end; aktuell_session:=UniApplication.UniSession.SessionID; aktuell_ip:=UniApplication.RemoteAddress; aktuell_session:='[sessionID:'+aktuell_session+'] '; aktuell_ip:='[DeviceIP:'+aktuell_ip+'] '; Hope that helps ;-) nice greetings erich Quote
maher Posted October 23, 2014 Posted October 23, 2014 ... if M.username = 'ThisUserName' then begin USession.TerminateAfterSecs(0); Break; end; end; .... .... This Code is Work fine but this code Will terminate Other USession without show any message to "Other USession" user Required to show a Message to the "Other USession"..... Like : if M.username = 'ThisUserName' then begin ....USession....(ShowMessage(' The System will terminate after 10 Sec')..... USession.TerminateAfterSecs(10); Thanx Quote
maher Posted October 23, 2014 Posted October 23, 2014 Thanks ZigZig for the reply, But i used callback procedure. ( a procedure to show message on the target Session) it did not work.! Quote
ZigZig Posted October 24, 2014 Posted October 24, 2014 I Ahmad, The callback procedure is not the one that shows a message, but the one called as parameter from the procedure that shows a message. Did you try something like this? //uniFormConfirm is an application form with an uniLabel ("Do you really want to close your session?") and an uniButton "OK" (with ModalResult set to mrOK). uniFormConfirm.ShowModal( procedure(Sender:TObject;Result:Integer); begin if Result=mrOK then TerminateMySession; end ); procedure TerminateMySession; begin //do whatever you want to close properly a session end; Quote
maher Posted October 24, 2014 Posted October 24, 2014 Dear ZigZig The code that Farshad give WORK fine : When I login with username "XXXX" the application search the old Session with the same username "XXXX" and Terminate it I mean the application Terminate the "other Session" not MySession.... The system must sent to the "other Session" Message "The System will terminate after..... The Message Must sent to "USession := TUniGUISession(ASessionList)" Thanx var ASessionList: TList; I : Integer; M : TUniMainModule; USession : TUniGUISession; begin ASessionList := UniServerModule.SessionManager.Sessions.SessionList.LockList; try for I := 0 to ASessionList.Count -1 do begin USession := TUniGUISession(ASessionList[i]); M := USession.UniMainModule as TUniMainModule; if M.username = 'ThisUserName' then begin USession.TerminateAfterSecs(0); Break; end; end; finally UniServerModule.SessionManager.Sessions.SessionList.UnlockList; end; end; This may help. Quote
ZigZig Posted October 24, 2014 Posted October 24, 2014 Dear Ahmad, My mistake, I didn't understand that you need to send a message to another session of the same user. Quote
Oliver Morsch Posted October 24, 2014 Posted October 24, 2014 This may help: http://forums.unigui.com/index.php?/topic/3275-messageserver-push-messages-from-server-to-client-long-polling/ Quote
maher Posted October 25, 2014 Posted October 25, 2014 Thank to Oliver Morsch & ZigZig I want to send message used unigui only . I solved the problem in a primitive method, but it's work fine If there is a better solution please share begin USession := TUniGUISession(ASessionList[i]); M := USession.UniMainModule as TUniMainModule; if M.username = 'ThisUserName' then begin M.LMessageStr := 'Your Session will Terminate after 10 Sec !!!';////// <--- USession.TerminateAfterSecs(10); Break; end; end; // And in the MainForm. a Timer With this code: procedure TMainFrm.UniTimer1Timer(Sender: TObject); begin if UniMainModule.LMessageStr <> '' then begin ShowMessage(UniMainModule.LMessageStr); UniMainModule.LMessageStr := ''; end; end; 1 Quote
erich.wanker Posted January 20, 2016 Author Posted January 20, 2016 To User XUYB19870303 - i think "personal conversation" is not the best way to ask ;-) I made a automatic logoff for old sessions like this: i use a uniTimer ... i didn´t find a solution without timer :-( in unimainmodule: public username:String; LMessageStr:String; in main: procedure TMainForm.UniTimer2Timer(Sender: TObject); begin if UniMainModule.LMessageStr <> '' then begin ShowMessage(UniMainModule.LMessageStr); UniMainModule.LMessageStr := ''; end; in my login-form: // Andere Session finden und beenden.... uniMainModule.username:= uniedit1.text // the username ASessionList := UniServerModule.SessionManager.Sessions.SessionList; try for I := 0 to ASessionList.Count -1 do begin USession := TUniGUISession(ASessionList); M := USession.UniMainModule as TUniMainModule; if UniApplication.UniSession.SessionID <> USession.SessionId then // Do not close my OWN Session begin if M.username = uniedit1.text then begin M.LMessageStr := 'Sie haben sich an einem anderen System angemeldet..'+#13+'Sie werden automatisch in 10 Sekunden abgemeldet!'; USession.TerminateAfterSecs(10); Break; end; end; end; finally // UniServerModule.SessionManager.Sessions.SessionList.UnlockList; end; hth and nice greetings Erich Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.