I’m creating a captive portal using mikrotik as hotspot and since i’m a begineer with yii and ajax i would like to be advised on how should be the correct flow.
Right now everything is working, i’m able to gain internet access using username and password from yii database and pass them to mikrotik which talk with freeradius server.
Once user login it’s been redirected to a status page with the following form:
When user press "Sign In" username and password are passed to a javascript function which talk to mikrotik and enable internet connection.
I would like that when user press "Sign In" a loading image appears until (yii or javascript) check the status of the connection by looking at an html page on mikrotik which return 1 or 0 (online/offline) and then submit button will be changed with "Sign off" to logout from internet session.
The problem is i’m not sure on how to do that, the status connection should be done from the controller or from the view with a javascript function?
If you’re talking with Radius server via JavaScript then it should be done via JavaScript. If it’s jQuery AJAX you can check response and react according to data returned.
In the end i found a better way to handle the login/logout/status request with mikrotik, i’m able now to login by using the address: http://{mikrotik_ip}/login?username=user&password=password and it returns me a json array with the result and eventually the error message. The same is with the logout and status request.