/** * Converts and signs a PHP object or array into a JWT string. * * @param object|array $payload PHP object or array * @param string $key The secret key * @param string $algorithm The signing algorithm. Supported algorithms are 'HS256', 'HS384' and 'HS512' * * @return string A signed JWT */ public static function encode($payload, $key, $algorithm = 'HS256') { $header = ['typ' => 'JWT', 'alg' => $algorithm]; $segments = []; $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header)); $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload)); $signing_input = implode('.', $segments); $signature = JWT::sign($signing_input, $key, $algorithm); $segments[] = JWT::urlsafeB64Encode($signature); return implode('.', $segments); }
public function _default() { // If only unique access allowed if (Settings::getInstance()->get('unique_admin_address')) { // No correct key provided? if (!isset($_GET['admin_key']) || $_GET['admin_key'] != Configuration::getInstance()->get('cms')['unique_key']) { back(); } } // Authorize user by provided token (used by our mobile application) if (isset($_GET['token'])) { try { $payload = JWT::decode($_GET['token'], date('Y-m-d', NOW), true); if ($payload->created_at > strtotime('-5 minutes')) { $user_collection = new AdminUserRepository(); $user_collection->setWhereLogin($payload->login); $user_collection->setWherePassword($payload->password); $user_collection->setWhereActive(1); /** @var AdminUser $user */ $user = $user_collection->getFirstObjectFromCollection(); if ($user) { $this->initLogInProcess($user); } } } catch (Exception $exception) { // Do nothing, I guess... } } // Redirect if user is already logged in if (Users::getInstance()->isLogged()) { go('/cms/?p=home'); } $config = Configuration::getInstance(); $expose = $config->get('options'); $hide_license = $expose && isset($expose['hide_license']) && $expose['hide_license']; PageHead::getInstance()->addClassToBody('login')->addCssUrl('cms/css/login-soft.css'); PageTail::getInstance()->addJsUrl('cms/layout/scripts/login-soft.js')->addJs(' Login.init(); '); // Logo image and link $logo = ''; if (array_key_exists('logo', Configuration::getInstance()->get('cms'))) { $logo = Configuration::getInstance()->get('cms')['logo']; } $logo_link = DIR_CMS_URL; if (array_key_exists('logo_link', Configuration::getInstance()->get('cms'))) { $logo_link = Configuration::getInstance()->get('cms')['logo_link']; } // Registration form $registration_allowed = Settings::get('allow_registration'); ?> <?php if ($logo) { ?> <div class="logo"> <a href="<?php echo $logo_link; ?> " target="_blank"> <img src="<?php echo $logo; ?> " alt="DEVP Web Development"> </a> </div> <?php } ?> <div class="content"> <form class="login-form" action="?p=<?php echo P; ?> &do=_login" method="post"> <?php if (isset($_GET['registered'])) { ?> <h3 class="form-title">User created. Contact admins to activate your account.</h3> <script> setTimeout(function() { window.location = window.history.back(); }, 3000); </script>'; <?php } ?> <h3 class="form-title">Login to your account</h3> <div class="alert alert-danger display-hide"> <button class="close" data-close="alert"></button> <span>Enter any username and password.</span> </div> <div class="form-group"> <label class="control-label visible-ie8 visible-ie9">Username</label> <div class="input-icon"> <i class="fa fa-user"></i> <input class="form-control placeholder-no-fix" type="text" autofocus placeholder="Username" name="login" <?php echo isset($_GET['login']) ? $_GET['login'] : ''; ?> > </div> </div> <div class="form-group"> <label class="control-label visible-ie8 visible-ie9">Password</label> <div class="input-icon"> <i class="fa fa-lock"></i> <input class="form-control placeholder-no-fix" type="password" placeholder="Password" name="password"> </div> </div> <input type="hidden" name="go" value="<?php echo SELF; ?> "> <div class="forget-password"> <h4>Forgot your password ?</h4> <p>no worries, click <a href="javascript:;" id="forget-password"> here </a> to reset your password. </p> </div> <?php if ($registration_allowed) { ?> <div class="create-account"> <p>Don't have an account yet? <a href="javascript:;" id="register-btn">Create an account </a> </p> </div> <?php } ?> </form> <form class="forget-form" action="?p=<?php echo P; ?> &do=_reset_password" method="post"> <h3>Forget Password ?</h3> <p>Enter your e-mail address below to reset your password.</p> <div class="form-group"> <div class="input-icon"> <i class="fa fa-envelope"></i> <input class="form-control placeholder-no-fix" type="text" placeholder="Email" name="email"> </div> </div> <div class="form-actions"> <button type="button" id="back-btn" class="btn"> <i class="m-icon-swapleft"></i> Back </button> <button type="submit" class="btn blue pull-right"> Submit <i class="m-icon-swapright m-icon-white"></i> </button> </div> </form> <?php if ($registration_allowed) { ?> <form class="register-form" action="?p=<?php echo P; ?> &do=_register" method="post"> <h3>Sign Up</h3> <p> Enter your personal details below: </p> <div class="form-group"> <label class="control-label visible-ie8 visible-ie9">Full Name</label> <div class="input-icon"> <i class="fa fa-font"></i> <input class="form-control placeholder-no-fix" type="text" placeholder="Full Name" name="name"/> </div> </div> <div class="form-group"> <label class="control-label visible-ie8 visible-ie9">Email</label> <div class="input-icon"> <i class="fa fa-envelope"></i> <input class="form-control placeholder-no-fix" type="text" placeholder="Email" name="email"/> </div> </div> <div class="form-group"> <label class="control-label visible-ie8 visible-ie9">Phone</label> <div class="input-icon"> <i class="fa fa-envelope"></i> <input class="form-control placeholder-no-fix" type="text" placeholder="Phone" name="phone"/> </div> </div> <p> Enter your account details below: </p> <div class="form-group"> <label class="control-label visible-ie8 visible-ie9">Username</label> <div class="input-icon"> <i class="fa fa-user"></i> <input class="form-control placeholder-no-fix" type="text" placeholder="Username" name="login"> </div> </div> <div class="form-group"> <label class="control-label visible-ie8 visible-ie9">Password</label> <div class="input-icon"> <i class="fa fa-lock"></i> <input class="form-control placeholder-no-fix" type="password" id="register_password" placeholder="Password" name="password"/> </div> </div> <div class="form-group"> <label class="control-label visible-ie8 visible-ie9">Re-type Your Password</label> <div class="controls"> <div class="input-icon"> <i class="fa fa-check"></i> <input class="form-control placeholder-no-fix" type="password" placeholder="Re-type Your Password" name="rpassword"/> </div> </div> </div> <div class="form-actions"> <button id="register-back-btn" type="button" class="btn"> <i class="m-icon-swapleft"></i>Back </button> <button type="submit" id="register-submit-btn" class="btn blue pull-right"> Sign Up <i class="m-icon-swapright m-icon-white"></i> </button> </div> </form> <?php } ?> </div> <?php if ($hide_license) { ?> <!-- <?php } ?> <div class="copyright"> 2007 - <?php echo Y; ?> © <?php echo CMS_NAME; ?> | <a href="<?php echo CMS_SITE; ?> " target="_blank"><?php echo CMS_SITE; ?> </a> </div> <?php if ($hide_license) { ?> --> <?php } }