示例#1
0
/**
 * @param $id
 * @param $scenario
 * @return FileModel|bool
 */
function loadModel($id, $scenario = null)
{
    /** @var FileModel $model */
    $model = FileModel::model()->findByPk($id);
    if (empty($model)) {
        App::setFlash(_('No data found'), 'danger', '/files/');
    }
    if (isset($scenario)) {
        $model->scenario = $scenario;
    }
    return $model;
}
示例#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');
示例#4
0
<?php

use protect\classes\App;
require_once 'protect/init.php';
if (isset($_SESSION['userid'])) {
    if (isset($_COOKIE['token'])) {
        unset($_COOKIE['token']);
        setcookie('token', null, -1);
    }
    unset($_SESSION['userid']);
    App::setFlash('Goodbye ' . App::user()->username, 'success', '/');
}
示例#5
0
<?php

use protect\classes\App;
use protect\classes\models\FileModel;
require_once 'protect/init.php';
App::checkAccess();
if (App::user()->isUserFilesLimit()) {
    App::setFlash('Reached the limit of files', 'danger', '/files/');
}
/** @var FileModel $model */
$model = new FileModel();
if (isset($_FILES['FileModel'])) {
    $model->setUploadedFile('file');
    if ($model->save()) {
        App::user()->saveFilesCount();
        App::setFlash('Uploaded successfully', 'success', '/files');
    } else {
        App::setFlash($model->getErrorsAsString(), 'danger');
    }
}
App::smarty()->assign('model', $model)->display('upload.tpl');