Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.95 KB | None | 0 0
  1. <?php
  2. /**
  3.  * IlluCS 2.0
  4.  * Content Management System
  5.  *
  6.  * All rights reserved to the developers of this project. This project
  7.  * is private and may not be released to the public.
  8.  *
  9.  * @author Merijn
  10.  */
  11.  
  12. namespace Arrowhead\Controllers;
  13.  
  14. use Arrowhead\Models\Users,
  15.     Arrowhead\Models\Bans;
  16.  
  17. class AccountController extends ControllerBase
  18. {
  19.  
  20.     public function loginAction()
  21.     {
  22.         if ($this->request->isPost()) {
  23.  
  24.             $username = $this->request->getPost('username', 'string');
  25.             $password = $this->request->getPost('password', 'string');
  26.  
  27.  
  28.             if ($this->security->checkToken()) {
  29.                 $userSettings = Users::findFirstByUsername($username);
  30.  
  31.                 // User settings are okay. Let's validate and check the password.
  32.                 // If the password is correct, log 'em in.
  33.                 if ($userSettings) {
  34.                     // Do a check and see if the hashing algorithm is sha1.
  35.                     // If the hashing algorithm is sha1, convert it to bcrypt
  36.                     // and save it in the database.
  37.                     if (sha1($password) == $userSettings->password) {
  38.                         // It's sha1. Convert it into bcrypt and save the result.
  39.                         $userSettings->password = $this->security->hash($password);
  40.                         $userSettings->save();
  41.                     }
  42.  
  43.                     if ($this->security->checkHash($password, $userSettings->password)) {
  44.                         // Because some morons try to use SQL injections within the IP Address
  45.                         $ipAddress = ((filter_var($this->request->getClientAddress(), FILTER_VALIDATE_IP)) ? $this->request->getClientAddress() : false);
  46.  
  47.                         $bans = Bans::findFirstByValue($username);
  48.  
  49.                         // Oh, bad boy. You're banned. Check the expiration
  50.                         // date. If expired, it'll go away.
  51.                         if ($bans != false) {
  52.  
  53.                             $date = new \DateTime("NOW", new \DateTimeZone("Europe/Amsterdam"));
  54.  
  55.                             if ($bans->expire <= $date->getTimestamp() && $bans->appeal_state > 0) {
  56.                                 // Remove bans from database and move on.
  57.  
  58.                                 $bans->appeal_state = (int) 0;
  59.                                 $bans->save();
  60.                             } else {
  61.                                 $this->flash->error('Je bent verbannen door de World Staff. De volgende reden is bij je ban gegeven ' . $bans->reason);
  62.                             }
  63.  
  64.  
  65.                         }
  66.  
  67.                         // Je bent niet verbannen, so move on.
  68.                         $this->session->set('world', array(
  69.                             'username'   =>  $username,
  70.                             'motto'      =>  $userSettings->motto,
  71.                             'credits'    =>  $userSettings->credits
  72.                         ));
  73.  
  74.                         // Verander last_ip naar het nieuwe IP-adres
  75.                         $userSettings->ip_last = $ipAddress;
  76.                         $userSettings->save();
  77.  
  78.                         return $this->response->redirect('me');
  79.                     }
  80.  
  81.                     $this->flash->error('Het ingevoerde wachtwoord is incorrect. Probeer het opnieuw.');
  82.  
  83.                     return $this->dispatcher->forward(array(
  84.                         'controller'    =>  "index",
  85.                         'action'        =>  "index"
  86.                     ));
  87.  
  88.                 } else {
  89.                     $this->flash->error('Deze Worldnaam bestaat niet. Heb je het verkeerd ingevuld?');
  90.  
  91.                     return $this->dispatcher->forward(array(
  92.                         'controller'    =>  "index",
  93.                         'action'        =>  "index"
  94.                     ));
  95.                 }
  96.  
  97.             }
  98.  
  99.         }
  100.  
  101.         return $this->response->redirect('index');
  102.  
  103.  
  104.  
  105.     }
  106.  
  107.  
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement