Correct flow to implement signin/signout for captive portal

Hello everyone,

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:




<form class="form-horizontal" role="form" name="login" action="<?php echo $linkloginonly; ?>" method="post" target="<?php echo $linkorig; ?>" onSubmit="return doLogin()">

  <input type="hidden" name="dst" value="<?php echo $linkorig; ?>">

  <input type="hidden" name="popup" value="true" />

  <input type="hidden" name="username" value="<?php echo $usernameyii; ?>">

  <input type="hidden" name="password" value="<?php echo $passwordyii; ?>">


  <center><button type="submit" class="btn btn-success">Sign in</button></center>


</form>

<br>

<form class="form-horizontal" role="form" name="logout" action="<?php echo $linklogout; ?>" onSubmit="return openLogout()">

  <center><button type="submit" class="btn btn-warning">Sign off</button></center>

</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?

Could someone be so kind to help me through this?

Thanks,

Dado.

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.

Actually i’m not talking directly with the Radius server but with Mikrotik.

Thanks for the response, i will handle all from the view ;)

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.

I’m wondering now if there’s a way to let manage this from a model, i would like to implement this http://www.yiiframework.com/wiki/690/render-a-form-in-a-modal-popup-using-ajax/ but i don’t know which kind of procedure use inside the model in order to create that kind of request and read the json respose.

Can someone give me some hint?

Thanks.

Ok, i found a way, with a jscript i can retrive the status and i’m trying to send it to my action controller with an ajax post.

Now i’m stucked becouse i don’t know how i can get this from my action, is there a way to do that or i’m on a dead end?

Thanks.

I’m now able to get status data in my action




    public function actionStatus()

    {

        if (Yii::$app->request->isAjax && Yii::$app->request->getIsPost()) {

            if (Yii::$app->request->post('status') == 'offline') {

                # offline

                var_dump(Yii::$app->request->post('status'));

            } elseif (Yii::$app->request->post('status') == 'online') {

                # online

                var_dump(Yii::$app->request->post('data'));

            }

        }

    }



but i can see the returned data only on the browser’s console, how can i update the view with the data i’m passing from my action?

Thanks.