예제 #1
0
 /**
  * @param string $scenario
  * @param int $id Model primary key
  */
 function __construct($scenario = self::SC_INSERT, $id = null)
 {
     $this->initAttributes();
     $this->_scenario = $scenario;
     $this->_db = App::db();
     /** If set id search by primary key else create default attributes  */
     if (isset($id)) {
         $this->findByPk($id);
     }
 }
예제 #2
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;
}
예제 #3
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');
예제 #4
0
<?php

use protect\classes\App;
require_once 'protect/init.php';
$errorCode = isset($_GET['e']) && is_numeric($_GET['e']) ? $_GET['e'] : 0;
$error = array('code' => $errorCode);
switch ($errorCode) {
    case 0:
        $error['message'] = _("Unexpected error. Please contact webmaster.");
        break;
    case 404:
        $error['message'] = _("Unable to process your request. Not found.");
        break;
}
App::smarty()->assign('error', $error);
App::smarty()->display('error.tpl');
예제 #5
0
<?php

use protect\classes\App;
require_once 'protect/init.php';
App::checkAccess();
$model = App::user();
if (isset($_POST['UserModel'])) {
    $model->setAttributes($_POST['UserModel'], App::isAjaxRequest());
    if (App::isAjaxRequest()) {
        echo json_encode($model->getError());
        die;
    }
    if ($model->save()) {
        App::setFlash('Successfully updated', 'success', '/index');
    } else {
        App::setFlash('Please correct the following errors', 'danger');
    }
}
App::smarty()->assign('model', $model)->display('edit_profile.tpl');
예제 #6
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', '/');
}
예제 #7
0
 /** Return FileModel path and filename
  * @param bool $base
  * @return string
  */
 public function getFilePath($base = true)
 {
     $separator = $base ? DIRECTORY_SEPARATOR : '/';
     $path = App::getAppc()['directories']['media'] . $separator . $this->getShortClassName() . $separator . floor((int) $this->fileid / 200) . $separator . $this->fileid . (isset($this->extension) ? '.' . $this->extension : '');
     return $base ? App::basePath() . $path : $separator . $path;
 }
예제 #8
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');
예제 #9
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');
예제 #10
0
 /** Save files count */
 public function saveFilesCount()
 {
     $this->saveAttr(array('files_count' => App::db()->runSql('select count(*) from tbl_file where userid = :userid and statusid =  ' . FileModel::SC_STATUS_ACTIVE, array(':userid' => $this->userid))->fetchColumn()));
 }
예제 #11
0
<?php

use protect\classes\App;
require_once 'protect/init.php';
if (!App::user()) {
    App::smarty()->display('main.tpl');
} else {
    App::smarty()->display('userinfo.tpl');
}