Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class SessionController extends ControllerBase {
- private function _registerSession($user)
- {
- $this->session->set(
- "auth",
- [
- "ID" => $user->ID,
- "name" => $user->name,
- ]
- );
- }
- /**
- * This action authenticate and logs a user into the application
- */
- public function startAction()
- {
- if ($this->request->isPost()) {
- // Get the data from the user
- $username = $this->request->getPost("username");
- $password = $this->request->getPost("password");
- // Find the user in the database
- $user = Users::findFirst(
- [
- "username = :username: AND password = :password:",
- "bind" => [
- "username" => $username,
- "password" => mda5($password),
- ]
- ]
- );
- if ($user !== false) {
- $this->_registerSession($user);
- $this->flash->success(
- "Welcome " . $user->name
- );
- // Forward to the 'invoices' controller if the user is valid
- return $this->dispatcher->forward(
- [
- "controller" => "articles",
- "action" => "index",
- ]
- );
- }
- $this->flash->error(
- "Wrong username/password"
- );
- }
- // Forward to the login form again
- return $this->dispatcher->forward(
- [
- "controller" => "session",
- "action" => "index",
- ]
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement