示例#1
0
 /**
  * Session init
  */
 public static function initializeSession()
 {
     /* Session start here */
     if (version_compare(PHP_VERSION, '5.4.0', '<')) {
         if (session_id() == '') {
             session_start();
         }
     } else {
         if (session_status() == PHP_SESSION_NONE) {
             session_start();
         }
     }
     # if exist session  userid
     if (isset($_SESSION['userid'])) {
         // if not found in database - delete from session storage
         if (!(self::$_user = UserModel::model()->findByPk($_SESSION['userid']))) {
             unset($_SESSION['userid']);
         }
     } else {
         /* if exist session  token. This is split string of
              userid_and md5 hash string. See the  UserModel -> getRemembeMeToken()
            */
         if (isset($_COOKIE['token'])) {
             /*converted into an associative array [userid], [token]
              */
             $tData = array_combine(array('userid', 'token'), explode('_', $_COOKIE['token']));
             /* If the user exists in the database,  */
             if (self::$_user = UserModel::model()->findByPk($tData['userid'])) {
                 /*and token matches */
                 if (strcmp(self::$_user->getRememberMeToken(), $tData['token'] === 0)) {
                     /*identifies the user */
                     $_SESSION['userid'] = self::$_user->userid;
                 }
             }
         }
     }
     if (isset(self::$_smarty)) {
         self::$_smarty->assign('app_user', self::$_user);
     }
 }
示例#2
0
<?php

require_once 'protect/init.php';
use protect\classes\App;
use protect\classes\models\UserModel;
/*if exists uploadImage render  render json image info */
if (isset($_POST['uploadImage'])) {
    $image = new \protect\classes\UploadedFile('image');
    echo json_encode($image->toArray());
    die;
}
$model = new UserModel();
if (isset($_POST['UserModel'])) {
    $model->setAttributes($_POST['UserModel'], App::isAjaxRequest());
    if (App::isAjaxRequest()) {
        echo json_encode($model->getError());
        die;
    }
    if ($model->save()) {
        App::setFlash('User successfully registered. You can sign.', 'success', '/index');
    } else {
        App::setFlash('Please correct the following errors', 'danger');
    }
}
App::smarty()->assign('model', $model)->display('signup.tpl');
示例#3
0
<?php

use protect\classes\App;
use protect\classes\models\UserModel;
use protect\classes\Redirect;
/**
 * @var UserModel $user
 */
require_once 'protect/init.php';
if (isset($_POST['inputName'])) {
    $user = UserModel::model()->findByAttributes(array('loginname' => $_POST['inputName'], 'email' => $_POST['inputName']), array('operator' => 'OR'));
    #Значит пользователь не найден
    #Means user not found
    $error = !$user;
    $error = $error ? true : strcmp($user->password, md5($_POST['inputPassword'])) !== 0;
    if ($error) {
        App::smarty()->assign('login_error', _('Invalid password or UserName'));
    } else {
        App::setFlash('Welcome ' . $user->username);
        $_SESSION['userid'] = $user->userid;
        if (isset($_POST['inputRememberMe'])) {
            setcookie('token', $user->getRememberMeToken(), time() + 60 * 60 * 24 * 30);
        }
        Redirect::go('/');
    }
}
App::smarty()->display('login.tpl');