Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Phalcon\Mvc\Controller;
- class SigninController extends Controller
- {
- public function indexAction()
- {
- }
- private function _registerSession($user)
- {
- $this->session->set(
- "auth",
- [
- "id" => $user->id,
- "name" => $user->name,
- ]
- );
- }
- public function loginAction()
- {
- if ($this->request->isPost()) {
- // Get the data from the user
- $email = $this->request->getPost("email");
- $password = $this->request->getPost("password");
- // Find the user in the database
- $user = Users::findFirst(
- [
- "email = :email: AND password = :password:",
- "bind" => [
- "email" => $email,
- "password" => $password,
- ]
- ]
- );
- if ($user !== false) {
- $this->_registerSession($user);
- $this->flash->success(
- "Welcome " . $user->name
- );
- }
- else
- {
- $this->flash->error(
- "Wrong email/password"
- );
- // Forward to the login form again
- return $this->dispatcher->forward(
- [
- "controller" => "signin",
- "action" => "index",
- ]
- );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement