Ejemplo n.º 1
0
 */
/**
 * @namespace
 */
namespace Application;

use Application\Categories;
use Bluz\Proxy\Layout;
use Bluz\Proxy\Messages;
return function ($id = null) use($view) {
    /**
     * @var Bootstrap $this
     * @var \Bluz\View\View $view
     */
    Layout::setTemplate('dashboard.phtml');
    Layout::headStyle($view->baseUrl('css/categories.css'));
    Layout::breadCrumbs([$view->ahref('Dashboard', ['dashboard', 'grid']), __('Categories')]);
    $categoriesTable = Categories\Table::getInstance();
    $rootTree = $categoriesTable->getAllRootCategory();
    if (count($rootTree) == 0) {
        Messages::addNotice('There are no categories');
        return $view;
    }
    $view->rootTree = $rootTree;
    if (!$id) {
        $id = $rootTree[0]->id;
    }
    $view->branch = $id;
    $view->tree = $categoriesTable->buildTree($id);
    return $view;
};
Ejemplo n.º 2
0
         $emailUnique = Users\Table::findRowWhere(['email' => $email]);
         if ($emailUnique && $emailUnique->id != $userId) {
             throw new Exception('User with email "' . htmlentities($email) . '" already exists');
         }
         // generate change mail token and get full url
         $actionRow = UsersActions\Table::getInstance()->generate($userId, Table::ACTION_CHANGE_EMAIL, 5, ['email' => $email]);
         $changeUrl = Router::getFullUrl('users', 'change-email', ['token' => $actionRow->code]);
         $subject = __("Change email");
         $body = $this->dispatch('users', 'mail/template', ['template' => 'change-email', 'vars' => ['user' => $user, 'email' => $email, 'changeUrl' => $changeUrl, 'profileUrl' => Router::getFullUrl('users', 'profile')]])->render();
         try {
             $mail = Mailer::create();
             $mail->Subject = $subject;
             $mail->msgHTML(nl2br($body));
             $mail->addAddress($email);
             Mailer::send($mail);
             Messages::addNotice('Check your email and follow instructions in letter.');
         } catch (\Exception $e) {
             Logger::log('error', $e->getMessage(), ['module' => 'users', 'controller' => 'change-email', 'userId' => $userId]);
             throw new Exception('Unable to send email. Please contact administrator.');
         }
         // try back to index
         Response::redirectTo('users', 'profile');
     } catch (Exception $e) {
         Messages::addError($e->getMessage());
         $this->assign('email', $email);
     } catch (AuthException $e) {
         Messages::addError($e->getMessage());
         $this->assign('email', $email);
     }
 } elseif ($token) {
     // process activation
Ejemplo n.º 3
0
     $this->redirectTo('index', 'index');
 } elseif (Request::isPost()) {
     try {
         if (empty($login)) {
             throw new Exception("Login is empty");
         }
         if (empty($password)) {
             throw new Exception("Password is empty");
         }
         // login/password
         // throw AuthException
         Auth\Table::getInstance()->authenticateEquals($login, $password);
         if ($rememberMe) {
             Auth\Table::getInstance()->generateCookie();
         }
         Messages::addNotice('You are signed');
         // try to rollback to previous called URL
         if ($rollback = Session::get('rollback')) {
             Session::delete('rollback');
             $this->redirect($rollback);
         }
         // try back to index
         $this->redirectTo('index', 'index');
     } catch (Exception $e) {
         Messages::addError($e->getMessage());
         $view->login = $login;
     } catch (AuthException $e) {
         Messages::addError($e->getMessage());
         $view->login = $login;
     }
 }
Ejemplo n.º 4
0
<?php

/**
 * Build list of routers
 *
 * @author   Anton Shevchuk
 * @created  12.06.12 12:27
 */
/**
 * @namespace
 */
namespace Application;

use Bluz\Common\Nil;
use Bluz\Proxy\Cache;
use Bluz\Proxy\Messages;
return function () {
    /**
     * @var Bootstrap $this
     */
    if (!Cache::getInstance() instanceof Nil) {
        Cache::flush();
        Messages::addSuccess("Cache is flushed");
    } else {
        Messages::addNotice("Cache is disabled");
    }
};
Ejemplo n.º 5
0
 /**
  * @return void
  */
 public function authProcess()
 {
     $this->authAdapter = $this->getAuthAdapter();
     $profile = $this->getProfile();
     /**
      * @var Auth\Table $authTable
      */
     $authTable = Auth\Table::getInstance();
     $auth = $authTable->getAuthRow(strtolower($this->providerName), $profile->identifier);
     if ($this->identity) {
         if ($auth) {
             Messages::addNotice(sprintf('You have already linked to %s', $this->providerName));
             $this->response->redirectTo('users', 'profile', ['id' => $this->identity->id]);
         } else {
             $user = Users\Table::findRow($this->identity->id);
             $this->registration($profile, $user);
         }
     }
     if ($auth) {
         $this->alreadyRegisteredLogic($auth);
     } else {
         Messages::addError(sprintf('First you need to be linked to %s', $this->providerName));
         $this->response->redirectTo('users', 'signin');
     }
 }
Ejemplo n.º 6
0
<?php

/**
 * Test CLI
 *
 * @author   Anton Shevchuk
 * @created  18.11.12 19:41
 */
namespace Application;

use Bluz\Proxy\Messages;
return function ($flag = false) use($view) {
    /**
     * @var Bootstrap $this
     * @var \Bluz\View\View $view
     */
    if ($flag) {
        Messages::addNotice('Notice Text');
        Messages::addSuccess('Success Text');
        Messages::addError('Error Text');
        Messages::addError('Another Error Text');
    }
    $view->string = 'bar';
    $view->array = ['some', 'array'];
    $view->object = new \stdClass();
    $view->object->property = 'example';
};
Ejemplo n.º 7
0
<?php

/**
 * Test AJAX
 *
 * @author   Anton Shevchuk
 * @created  26.09.11 17:41
 * @return closure
 */
namespace Application;

use Bluz\Proxy\Messages;
use Bluz\Proxy\Request;
return function ($messages = false) use($view) {
    /**
     * @var Bootstrap $this
     * @var \Bluz\View\View $view
     */
    if ($messages) {
        Messages::addNotice('Notice for AJAX call');
        Messages::addSuccess('Success for AJAX call');
        Messages::addError('Error for AJAX call');
        $view->baz = 'qux';
    }
    Messages::addNotice('Method ' . Request::getMethod());
    $view->foo = 'bar';
};
Ejemplo n.º 8
0
 /**
  * Test Messages container
  */
 public function testMessagesPopAll()
 {
     Proxy\Messages::addError('error');
     Proxy\Messages::addNotice('notice');
     Proxy\Messages::addSuccess('success');
     $messages = Proxy\Messages::popAll();
     $this->assertArrayHasKeyAndSize($messages, 'error', 1);
     $this->assertArrayHasKeyAndSize($messages, 'notice', 1);
     $this->assertArrayHasKeyAndSize($messages, 'success', 1);
 }
Ejemplo n.º 9
0
<?php

/**
 * Logout proccess
 *
 * @author   Anton Shevchuk
 * @created  20.07.11 18:39
 * @return closure
 */
namespace Application;

use Application\Auth as AppAuth;
use Bluz\Controller\Controller;
use Bluz\Proxy\Auth;
use Bluz\Proxy\Messages;
use Bluz\Proxy\Response;
/**
 * @return void
 */
return function () {
    /**
     * @var Controller $this
     */
    if ($this->user()) {
        AppAuth\Table::getInstance()->removeCookieToken($this->user()->id);
        Auth::clearIdentity();
    }
    Messages::addNotice('You are signout');
    Response::redirectTo('index', 'index');
};