示例#1
0
 /**
  * Test Auth Identity clear
  *
  * @covers \Bluz\Auth\Auth::getIdentity
  * @covers \Bluz\Auth\Auth::clearIdentity
  */
 public function testAuthClearIdentityWithWrongUserAgent()
 {
     $adminIdentity = new UserAdmin();
     Session::set('auth:agent', 'agent:php');
     Session::set('auth:identity', $adminIdentity);
     $_SERVER['HTTP_USER_AGENT'] = 'agent:cli';
     $this->assertNull(Auth::getIdentity());
 }
示例#2
0
 /**
  * Setup identity
  * @api
  * @param EntityInterface $identity
  * @return void
  */
 public function setIdentity(EntityInterface $identity)
 {
     // save identity to Auth
     $this->identity = $identity;
     // save identity to session
     Session::set('auth:identity', $identity);
     // save user agent to session
     Session::set('auth:agent', Request::getServer('HTTP_USER_AGENT'));
 }
示例#3
0
 public function deleteOne($primary)
 {
     //get saved data
     $existFilesData = Session::get('files');
     $files = unserialize($existFilesData);
     $fileId = reset($primary);
     $file = $files[$fileId];
     if (is_file(PATH_PUBLIC . '/uploads/menu/' . $file->getName() . '.' . $file->getExtension())) {
         @unlink(PATH_PUBLIC . '/uploads/menu/' . $file->getName() . '.' . $file->getExtension());
     }
     unset($files[$fileId]);
     Session::set('files', serialize($files));
 }
示例#4
0
 /**
  * Denied access
  * @throws ForbiddenException
  * @return void
  */
 public function denied()
 {
     // add messages make sense only if presentation is not json, xml, etc
     if (!$this->getResponse()->getPresentation()) {
         Messages::addError('You don\'t have permissions, please sign in');
     }
     // redirect to login page
     if (!$this->user()) {
         // save URL to session and redirect make sense if presentation is null
         if (!$this->getResponse()->getPresentation()) {
             Session::set('rollback', Request::getRequestUri());
             $this->redirectTo('users', 'signin');
         }
     }
     throw new ForbiddenException();
 }
示例#5
0
文件: Upload.php 项目: Kit-kat1/bluz
 /**
  * @param array $data
  * @throws Exception
  * @throws \Bluz\Request\RequestException
  * @return integer
  */
 public function upload()
 {
     /** @var \Bluz\Http\File $file */
     $file = Request::getFileUpload()->getFile('files');
     $type = $file->getType();
     $row = new \Application\MusicianImage\Row();
     $row->getTable()->create();
     $row->setFromArray(['type' => $type]);
     $row->beforeSave();
     $row->afterSave();
     if (!$file or $file->getErrorCode() != UPLOAD_ERR_OK) {
         if (!$file || $file->getErrorCode() == UPLOAD_ERR_NO_FILE) {
             throw new Exception('Please choose file to upload');
         }
         throw new Exception('Sorry I can`t receive file');
     }
     $name = uniqid();
     $filename = $name . "." . $file->getExtension();
     $file->setName($name);
     $file->moveTo($this->uploadDir);
     Session::set('image', $filename);
     return $file;
 }
示例#6
0
文件: session.php 项目: Kit-kat1/bluz
<?php

/**
 * Default module/controllers
 *
 * @author   Anton Shevchuk
 * @created  06.07.11 18:39
 * @return closure
 */
namespace Application;

use Bluz\Proxy\Layout;
use Bluz\Proxy\Session;
return function () use($view) {
    /**
     * @var Bootstrap $this
     * @var \Bluz\View\View $view
     */
    Layout::breadCrumbs([$view->ahref('Test', ['test', 'index']), 'Session']);
    Layout::title("Test/Index");
    Session::set('test', Session::get('test') ?: 'Session time: ' . date("H:i:s"));
    $view->title = Layout::title();
    $view->session = Session::get('test');
    //    if ($identity = $app->user()) {
    //        var_dump($acl->isAllowed('index/index', $identity['sid']));
    //        var_dump($acl->isAllowed('index/test', $identity['sid']));
    //        var_dump($acl->isAllowed('index/error', $identity['sid']));
    //    } else {
    //        Auth::authenticate('admin', '123456');
    //    }
};
示例#7
0
 /**
  * Reset messages
  *
  * @return void
  */
 public function reset()
 {
     Session::set('messages:store', $this->createEmptyMessagesStore());
 }
示例#8
0
 /**
  * Denied access
  * @param ForbiddenException $exception
  * @return \Bluz\Controller\Controller|null
  */
 public function forbidden(ForbiddenException $exception)
 {
     if (AuthProxy::getIdentity()) {
         $message = Translator::translate("You don't have permissions to access this page");
     } else {
         $message = Translator::translate("You don't have permissions, please sign in");
     }
     // for AJAX and API calls (over JSON)
     $jsonOrApi = Request::isXmlHttpRequest() || Request::getAccept([Request::TYPE_HTML, Request::TYPE_JSON]) == Request::TYPE_JSON;
     // for guest, for requests
     if (!AuthProxy::getIdentity() && !$jsonOrApi) {
         // save URL to session and redirect make sense if presentation is null
         Session::set('rollback', Request::getUri()->__toString());
         // add error notice
         Messages::addError($message);
         // redirect to Sign In page
         $url = Router::getUrl('users', 'signin');
         return $this->redirect($url);
     } else {
         return $this->error(new ForbiddenException($message, 403, $exception));
     }
 }