Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace CustoMS\Plugin;
- use CustoMS\Application;
- if (!defined('BASE'))
- {
- exit;
- }
- class cc_login implements iPlugin
- {
- private $base;
- function __Construct()
- {
- $this->base = PLUGINS.'cc_login'.DS;
- }
- public function GetContent()
- {
- ob_start();
- require $this->base.'content.html';
- $content = ob_get_clean();
- $securecode = $_SESSION['plugin']['cc_login']['securecode'] = uniqid();
- $message = '';
- if (isset($_SESSION['plugin']['cc_login']['error']))
- {
- $message = '<div class="message">'.$_SESSION['plugin']['cc_login']['error']."</div>";
- unset($_SESSION['plugin']['cc_login']['error']);
- }
- return str_replace(array('%message%', '%securecode%'), array($message, $securecode), $content);
- }
- public function HandleAction()
- {
- if (!isset($_GET['action']))
- {
- return;
- }
- if (!method_exists($this, $_GET['action']))
- {
- Application::ThrowError('cc_login', 'Unabled to handle the action.');
- }
- call_user_func(array($this, $_GET['action']));
- }
- public function SetSettings($data) { }
- //--
- public function login()
- {
- if (empty($_POST))
- {
- return;
- }
- $username = $_POST['username'];
- $password = $_POST['password'];
- if ($_SESSION['plugin']['cc_login']['securecode'] != $_POST['form_key'])
- {
- Application::ThrowError('cc_login', 'Unsecure login attempt.');
- }
- $result = Application::$DB->Prepare('SELECT * FROM `cms_users` WHERE `username` = ? AND `password` = ? LIMIT 1')->Params('ss', $username, $password)->Execute();
- if ($result->NumRows() > 0)
- {
- $_SESSION['plugin']['cc_login']['loggedin'] = true;
- $_SESSION['plugin']['cc_login']['data'] = $result->NumRows();
- Application::Redirect(URL.'/?page=2');
- }
- $_SESSION['plugin']['cc_login']['error'] = 'Wrong username or password.';
- }
- public function register()
- {
- if (empty($_POST))
- {
- return;
- }
- $username = $_POST['username'];
- $password = $_POST['password'];
- $passwordA = $_POST['password_again'];
- $email = $_POST['email'];
- if ($_SESSION['plugin']['cc_login']['securecode'] != $_POST['form_key'])
- {
- Application::ThrowError('cc_login', 'Unsecure register attempt.');
- }
- $_SESSION['plugin']['cc_login']['error'] = 'Register stuff not finished =3, nice attempt throught!';
- }
- //--
- public static function isAlive()
- {
- return (isset($_SESSION['plugin']['cc_login']['loggedin']));
- }
- }
- ?>
Add Comment
Please, Sign In to add comment