DeNovoSoftware Posted September 12, 2020 Share Posted September 12, 2020 Hello, We are new to Unigui. It seems that the browser refresh button completely resets the entire session. That is not typical for a web application these days. Is this a limitation of UniGui, or is there a way for the refresh button to not completely create a new session? Quote Link to comment Share on other sites More sharing options...
azago Posted September 12, 2020 Share Posted September 12, 2020 UniMainModule -> BrowserOptions -> boDisableChromeRefresh = True Quote Link to comment Share on other sites More sharing options...
DeNovoSoftware Posted September 12, 2020 Author Share Posted September 12, 2020 I see, but there is a similar issue if someone simply pastes the URL back in the browser. We are coming from Intraweb world, where the session is associated either based on a cookie, or the user's IP address. Thus, even if the user refreshes, or pastes the URL again, they get the same state as they left of at before. Is there a way to do this? Quote Link to comment Share on other sites More sharing options...
Mehmet Emin Posted September 14, 2020 Share Posted September 14, 2020 If you use a cookie you can associate it with a session state/status and recover where you left off. This is not directly built into unigui but I use this method to achieve what you do in the other tool intraweb Quote Link to comment Share on other sites More sharing options...
DeNovoSoftware Posted September 15, 2020 Author Share Posted September 15, 2020 @Mehmet Emin - thank you for the tip. What do you mean by session/state that you can save. When I start a new session I get a new TUniMainModule to hold session information. This is where I store specific data about what the user is doing during that session. If I refresh the browser, I get a new TUniMainModule instance. If I save a cookie and then refresh, how do I tell UniGui to go back to the old TUniMainModule and not use a new one? Quote Link to comment Share on other sites More sharing options...
Mehmet Emin Posted September 15, 2020 Share Posted September 15, 2020 1 minute ago, DaveNovo said: how do I tell UniGui to go back to the old TUniMainModule and not use a new one There is no way to go to old data module. You will get a new data module and using the cookie value you we will check a session table in the database (that you updated in previous unigui session) to retrieve previous session/state like last user login status, open form etc. So that you can continue where you are left off. I use this approach in order not to ask a password at each time user comes back in allowed time. Here is a sample auto login procedure: procedure TfrmMainm.UnimFormCreate(Sender: TObject); begin UniSession.JSCode( 'var sessionCookie = localStorage.getItem("'+SESSION_COOKIE+'");'+ 'param = "'+SESSION_COOKIE+'="+sessionCookie;'+ 'ajaxRequest(frmMainm.form, "UserAutoLogin", [param]);' ); end; procedure TfrmMainm.UnimFormAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); var frmUserLoginm: TfrmUserLoginm; begin if EventName = 'UserAutoLogin' then begin if UniMainModule.UserAutoLogin(Params.Values[SESSION_COOKIE]) then begin ShowMainMenuForm; end else begin frmUserLoginm := TfrmUserLoginm.Create(uniGUIApplication.UniApplication); frmUserLoginm.Show; end; end; end; function TUniMainModule.UserAutoLogin(ASessionCookie: string): Boolean; var qryUser, qryUserSession: TFDQuery; LUserId: Integer; P1: Integer; begin Result := False; P1 := Pos('/', ASessionCookie); if P1 > 0 then begin LUserId := StrToIntDef(Copy(ASessionCookie,P1+1), Length(ASessionCookie)); if LUserId > 0 then begin qryUser := nil; qryUserSession := nil; try qryUser := TFDQuery.Create(nil); FDConnection.Connected := True; qryUser.Connection := FDConnection; with TZUSER do begin qryUser.SQL.Text := 'SELECT *'+ ' FROM '+TABLE+ ' WHERE '+_ID+'=:'+_ID+ ' AND '+_ACTIVE+'=1'; qryUser.ParamByName(_ID).AsInteger := LUserId; qryUser.Open; if not qryUser.Eof then begin with TZUSER_SESSION do begin qryUserSession := TFDQuery.Create(nil); qryUserSession.Connection := FDConnection; qryUserSession.SQL.Text := 'SELECT *'+ ' FROM '+TABLE+ ' WHERE '+_SESSION_COOKIE+'=:'+_SESSION_COOKIE+ ' AND '+_USER_ID+'=:'+_USER_ID; qryUserSession.ParamByName(_SESSION_COOKIE).AsString := ASessionCookie; qryUserSession.ParamByName(_USER_ID).AsInteger := qryUser.FieldByName(TZUSER._ID).AsInteger; qryUserSession.Open; if not qryUserSession.Eof then begin if Now < qryUserSession.FieldByName(_EXPIRES_ON).AsDateTime then begin FUserId := qryUser.FieldByName(TZUSER._ID).AsInteger; FUserType := qryUser.FieldByName(TZUSER._USER_TYPE).AsString; FCompanyId := qryUser.FieldByName(TZUSER._COMPANY_ID).AsInteger; FSessionId := qryUserSession.FieldByName(TZUSER_SESSION._ID).AsInteger; Result := True; end; end; end; end; end; finally qryUser.Free; qryUserSession.Free; end; end; end; end; Quote Link to comment Share on other sites More sharing options...
DeNovoSoftware Posted September 15, 2020 Author Share Posted September 15, 2020 I see. that makes sense. Thank you for the prompt response! Quote Link to comment Share on other sites More sharing options...
Mehmet Emin Posted September 15, 2020 Share Posted September 15, 2020 You are welcome. Quote Link to comment Share on other sites More sharing options...
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.