Guest User

Untitled

a guest
Apr 12th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.57 KB | None | 0 0
  1. <?php
  2.  
  3.     namespace CustoMS\Plugin;
  4.  
  5.     use CustoMS\Application;
  6.    
  7.     if (!defined('BASE'))
  8.     {
  9.         exit;
  10.     }
  11.  
  12.     class cc_login implements iPlugin
  13.     {
  14.         private $base;
  15.        
  16.         function __Construct()
  17.         {
  18.             $this->base = PLUGINS.'cc_login'.DS;
  19.         }
  20.        
  21.         public function GetContent()
  22.         {
  23.             ob_start();
  24.             require $this->base.'content.html';
  25.             $content = ob_get_clean();
  26.            
  27.             $securecode = $_SESSION['plugin']['cc_login']['securecode'] = uniqid();
  28.            
  29.             $message = '';
  30.             if (isset($_SESSION['plugin']['cc_login']['error']))
  31.             {
  32.                 $message = '<div class="message">'.$_SESSION['plugin']['cc_login']['error']."</div>";
  33.                
  34.                 unset($_SESSION['plugin']['cc_login']['error']);
  35.             }
  36.            
  37.             return str_replace(array('%message%', '%securecode%'), array($message, $securecode), $content);
  38.         }
  39.        
  40.         public function HandleAction()
  41.         {
  42.             if (!isset($_GET['action']))
  43.             {
  44.                 return;
  45.             }
  46.            
  47.             if (!method_exists($this, $_GET['action']))
  48.             {
  49.                 Application::ThrowError('cc_login', 'Unabled to handle the action.');
  50.             }
  51.            
  52.             call_user_func(array($this, $_GET['action']));
  53.         }
  54.        
  55.         public function SetSettings($data) { }
  56.        
  57.         //--
  58.        
  59.         public function login()
  60.         {
  61.             if (empty($_POST))
  62.             {
  63.                 return;
  64.             }
  65.            
  66.             $username = $_POST['username'];
  67.             $password = $_POST['password'];
  68.            
  69.             if ($_SESSION['plugin']['cc_login']['securecode'] != $_POST['form_key'])
  70.             {
  71.                 Application::ThrowError('cc_login', 'Unsecure login attempt.');
  72.             }
  73.            
  74.             $result = Application::$DB->Prepare('SELECT * FROM `cms_users` WHERE `username` = ? AND `password` = ? LIMIT 1')->Params('ss', $username, $password)->Execute();
  75.             if ($result->NumRows() > 0)
  76.             {
  77.                 $_SESSION['plugin']['cc_login']['loggedin'] = true;
  78.                 $_SESSION['plugin']['cc_login']['data'] = $result->NumRows();
  79.                
  80.                 Application::Redirect(URL.'/?page=2');
  81.             }
  82.            
  83.             $_SESSION['plugin']['cc_login']['error'] = 'Wrong username or password.';
  84.         }
  85.        
  86.         public function register()
  87.         {
  88.             if (empty($_POST))
  89.             {
  90.                 return;
  91.             }
  92.            
  93.             $username = $_POST['username'];
  94.             $password = $_POST['password'];
  95.             $passwordA = $_POST['password_again'];
  96.             $email = $_POST['email'];
  97.            
  98.             if ($_SESSION['plugin']['cc_login']['securecode'] != $_POST['form_key'])
  99.             {
  100.                 Application::ThrowError('cc_login', 'Unsecure register attempt.');
  101.             }
  102.            
  103.             $_SESSION['plugin']['cc_login']['error'] = 'Register stuff not finished =3, nice attempt throught!';
  104.         }
  105.        
  106.         //--
  107.        
  108.         public static function isAlive()
  109.         {
  110.             return (isset($_SESSION['plugin']['cc_login']['loggedin']));
  111.         }
  112.     }
  113.  
  114. ?>
Add Comment
Please, Sign In to add comment