Beispiel #1
0
 /**
  * @param locator $locator
  */
 public function __construct($locale)
 {
     APIFactory::getAuthenticator()->setUserSession();
     $this->_view = \Xily\Bean::create($locale->replace(file_get_contents(VIEW_DIR . 'login.xml')));
 }
Beispiel #2
0
require_once dirname(__FILE__) . '/lib/tymio/common.php';
Session::start();
\Xily\Bean::$BEAN_DIRS[] = LIB_DIR . 'beans';
$pluginEvents = array('menu' => array('clocking', 'clockings', 'offtime', 'transaction', 'transactions'));
function registerPluginEvents($pluginEvents)
{
    foreach ($pluginEvents as $entity => $events) {
        foreach ($events as $event) {
            PluginPeer::registerEvent($entity, $event);
        }
    }
}
try {
    registerPluginEvents($pluginEvents);
    $userAuthenticated = APIFactory::getAuthenticator()->authUser(true, true, isset($_REQUEST['autologin']) && $_REQUEST['autologin'] == true);
    $user = APIFactory::getAuthenticator()->getUser();
    PluginPeer::setAuthenticatedUser($user);
    if (isset($_REQUEST['do'])) {
        /* PERFORM THE API CALL
        		-------------------------------------------------------------------- */
        $api = null;
        try {
            $apiName = array_key_exists('api', $_REQUEST) ? strtolower($_REQUEST['api']) : API_DEFAULT;
            $api = APIFactory::get($apiName);
            $api->run();
        } catch (Exception $e) {
            if ($e instanceof APIPermissionDeniedException and !empty($_REQUEST['inline'])) {
                HTTP::forwardTo($_SERVER['SCRIPT_NAME'] . '?view=login' . '&return=' . urlencode($_SERVER['REQUEST_URI']) . '&' . Form::getTokenName() . '=' . urlencode(Form::getToken('loginreturn')));
            } else {
                header('Content-Type: application/json; charset=utf-8');
                if ($api instanceof API) {
Beispiel #3
0
    public function buildHeaderMenu()
    {
        global $locale;
        $html = '
		<div class="navbar navbar-fixed-top">
			<div class="navbar-inner">
				<div class="container" style="width: auto;">
					<a class="brand" href="' . buildLink('clockings') . '" id="loader"><img src="assets/img/logo.png" alt="tymio" /></a>';
        // Workaround with catching the exception but
        // more pretty would be a function like API->isAuthenticated()
        // instead of call complete authentication again (done in index.php)
        try {
            $authenticator = \APIFactory::getAuthenticator();
            $user = $authenticator->authUser();
            if ($user !== null) {
                $email = strtolower($user->getEmail());
                $html .= '<div class="nav-collapse">' . '<ul class="nav">' . $locale->replace($this->compileMenu(Xml::create(APP_DIR . ($user->isAdmin() ? 'menu-admin.xml' : 'menu.xml'), 1))) . '</ul>' . '</div>' . '<div id="login" style="background-image: url(\'https://secure.gravatar.com/avatar/' . md5($email) . '?s=28&d=mm\')">' . 'Logged in as ' . $user->getFQN() . '. <a class="btn btn-mini" href="' . buildLink('logout') . '"><i class="icon icon-off"></i> Logout</a>';
            } else {
                throw new Exception();
            }
        } catch (Exception $e) {
            $html .= '<div id="login" class="loggedout">Not logged in <a class="btn btn-success btn-mini" href="' . buildLink('login') . '"><i class="icon icon-white icon-lock"></i> Login</a>';
        }
        $html .= '
					</div>
					<ul class="nav pull-right">
						<li class="divider-vertical"></li>
					</ul>
				</div>
			</div>
		</div>';
        return $html;
    }