Implementation of uniGUI login-free
Under normal circumstances, uniGUI projects always have a login window, which is displayed when the client logs in. Now I want to nest this application into the app. Since the app has already been logged in by the user, in this case, if the login window pops up again, it is unreasonable for the user to enter information. What should I do?
With the help of friends, the user is not logged in. The idea is to add the login information to the url to access uniGUI, and then obtain the login information in the uniGUI application to complete the login action. Specific implementation method:
- Add user exemption and password parameters to the url for accessing uniGUI:
- Then, take over the uniMainDataModule.OnBeforeLogin event:
var userid, pw: string; begin //If the userid is passed in the url, it will be automatically logged in, adapted to be called in the app, and the login window will not pop up. if uniGUIApplication.UniApplication.Parameters.IndexOfName('userid') <> -1 then begin userid := uniGUIApplication.UniApplication.Parameters.Values['userid']; pw := uniGUIApplication.UniApplication.Parameters.Values['pw']; CurrentUser.ValidateUser(userid, pw); if UniMainModule.CurrentUser.LoginStatus = TLoginStatus.lsLogined then begin UniMainModule.CurrentUser.Login('Web'); Handled := True; // Compensate using standard data end end; end;
Look at the code above, first get the login parameters userid and pw from the accessed url. Note that the unit name of uniGUIApplication must be added here. If not, uniMainDatamodule also has an attribute called UniApplication, which will conflict with uniGUIApplication.UniApplication, which is not an object. , I made a point here.
The next step is to implement the login logic. If the user authentication is successful, the event parameter Handled is set to True, which means that the login is completed and the login window is no longer required.
Now use the url with user login information to access the uniGUI application, and the main window will be displayed directly to complete the automatic login.
In addition, by analogy, using this OnBeforeLogin event can also solve the automatic login when F5 refreshes the browser. After the user logs in, save the user name and password in the Cookie, and then read it out like the code above to achieve login. The specific code is not written.
- In your app, generate a url with username and password according to the current user information, and use a browser to access uniGUI, which is perfectly integrated. No reference code is provided here.
The last thing to say is that in ordinary uniGUI web applications, fill in the Login and MainForm on the mobile phone. UniGUI will automatically identify the platform to be accessed. If it is a mobile phone, it will automatically display the login window and main window on the mobile phone. This is good A uniGUI application automatically supports web access and mobile access.
In order to facilitate debugging, we can simulate mobile phone access in the Chrome browser, the specific operation: press crtl+shift+i, switch to developer mode, and then click the marked button to become a mobile phone: