I have implemented the MVC pattern (samopiska). There are a lot of modal HTML + CSS login forms in the network, but there is no information how to transfer control to the server. Here is an example of the login form I chose:

Authorization

Login with:

No account? Check in.
Forgot your password?

check in

Login with:

Already a member? To come in.

But! My authorization is handled by the UsersController controller. How to transfer the entered data to it? As a result of the check, or display the same authorization form with an error message (if an error), or enter the site if everything is OK? Be grateful for any links or responses.

  • I have implemented the MVC pattern (samopiska). There are a lot of modal HTML + CSS login forms in the network, but there is no information how to transfer control to the server. But! My authorization is handled by the UsersController controller. How to transfer the entered data to it? As a result of the check, or display the same authorization form with an error message (if an error), or enter the site if everything is OK? Be grateful for any links or responses. - Alexander Gerasimov

1 answer 1

It can be implemented via an Ajax request, this way: you enter data into the form, by clicking on the enter button you collect the login password from the form and send it to the server, for example, to a specific user identification file (let it be auth.php ). In it, you connect your file and transfer to it the parameters that came from the client. Your controller should be responsible for this.

 $login = $_POST['login']; $password = md5($_POST['password']); // проверить входные параметры на валидность, а так же экранировать 

Next send:

 $res = $db->query('SELECT id FROM users WHERE login = $login and password = md5($password) LIMIT 1' $isAuth = false; if (sizeOf($res) == 1) { // пользователь найден, авторизовать =>> $isAuth = true; } 

If there are such users, at least one result will be returned to you. Well, here is the comparison and return of the result (better in json , like: {isAuth: $isAuth} )

And on the client to check, on $.ajax.success if you returned res.isAuth == true then authorize (fill out the cookie, etc.).

  • Otherwise, the data will be sent to you, the page will reload (completely), where you will set a condition if you have sent the authorization => open a modal window and display some message about incorrect / non-existing user - Vasily Barbashev