Recently, we were working on a cakephp project. The customer requested that after the user enters their verification code, that they are automatically logged in. I had never seen this before and promptly began searching the intertubes for an answer.
The delema
Surprisingly enough, there is very little to no information online about programatically logging in a user on cakephp. We were just about to give up when curiousity got the best of me. I looked for that auth.php file and tried to figure out exactly what it was expecting for login. As you expect, the function does many checks on username and password fields. Luckily they provided another option.
The solution
The file you are looking for is (cakelibscontrollercomponentsauth.php). The $this->Auth-login actually forwards along to a function called “identify” and it has a nice else statement like goes like the following:
[html](!empty($user) && is_string($user))[/html]
You’ve seen it here first folks. It then moves on to validate against $model->escapeField() which a quick var_dump reveals is “User.id”. Ahh, and there is a condition for “User.status=1”
Conclusion
I have no idea why this was so hard to find. Maybe, i’m the only one on the planet that didn’t know this existed. Hopefully, this saves someone else a few hours.
Recientemente, estábamos trabajando en un proyecto de cakephp. El cliente solicitó, después de que el usuario introduzca su código de verificación, que registran automáticamente en. Yo nunca había visto esto antes y pronto comenzó a buscar los intertubes para una respuesta.
La delema
Sorprendentemente, hay muy poca a ninguna información en línea sobre registro mediante programación en un usuario de cakephp. Comencé a escribir un correo electrónico al cliente cuando previo obtuvo lo mejor de mí. He buscado ese archivo auth.php y trató de averiguar exactamente lo estaba esperando para entrar. Como se espera, la función hace muchos controles en los campos nombre de usuario y contraseña. Por suerte proporcionan otra opción.
La solución
El $esto-> Auth login realmente reenvía junto a una función llamada “identificar” y tiene una instrucción else Linda como va como el siguiente:
(! empty($user) & & is_string($user))
Que has visto aquí gente primera. Entonces mueve de validar contra $modelo – > escapeField() que revela un var_dump rápido es “User.id”. Ahh, y hay una condición para “User.status=1”
Conclusión
No tengo ni idea de por qué fue tan difícil de encontrar. Tal vez, soy el único del planeta que no sabía que esto existía. Esperemos que este alguien guarda unas horas.
Author: beyondprograms
https://beyondprograms.ca Beyond Programs Ltd is a Canadian management consulting firm specializing in sourcing fractional executives and project managers for clients. We focus on projects including Technology Integrations, Event coordination, Asset management, Marketing campaigns, & Sustainability initiatives (TEAMS)