Exemple #1
0
 /** Set a base FLASH application message
  * @param $message - bootsrap type e.g. danger, info, warning
  * @param string $type
  * @param null $redirectUrl
  */
 public static function setFlash($message, $type = 'success', $redirectUrl = null)
 {
     $_SESSION['flash'] = array('type' => $type, 'message' => _($message));
     if (isset($redirectUrl)) {
         Redirect::go($redirectUrl);
     }
 }
Exemple #2
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');