示例#1
0
 public static function redirect_user_if_not_admin($url = null)
 {
     $auth = new AppAuthService();
     if (!$auth->user) {
         return $auth->redirect_to_login();
     } elseif (!$auth->user_is_admin()) {
         return $auth->forbid_access();
     } else {
         return $auth;
     }
 }
示例#2
0
 public static function create_on_install()
 {
     # Create System user
     $system_user_name = NEECHY_USER;
     $system_user_email = '*****@*****.**';
     $system_user = new User(array('name' => $system_user_name, 'email' => $system_user_email, 'status' => self::$STATUS_LEVELS['NEW']));
     $system_user->set_password(NeechySecurity::random_hex());
     $system_user->save();
     # Create Owner (user currently logged in)
     $app_engine_user = AppAuthService::user();
     if ($app_engine_user) {
         $owner_name = $app_engine_user->getNickname();
         $owner_email = $app_engine_user->getEmail();
         $owner = new User(array('name' => $owner_name, 'email' => $owner_email, 'status' => self::$STATUS_LEVELS['NEW']));
         $owner->set_password(NeechySecurity::random_hex());
         $owner->save();
     } else {
         $owner = null;
     }
     return array($system_user, $owner);
 }
示例#3
0
    public function app_engine_user_button()
    {
        $logged_in_dropdown = <<<HTML5
    <div class="btn btn-group user-button logged-in">
      <button type="button" class="btn btn-info">%s</button>
      <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown"
        aria-haspopup="true" aria-expanded="false">
        <span class="caret"></span>
        <span class="sr-only">Toggle Dropdown</span>
      </button>
      <ul class="dropdown-menu">
        %s
      </ul>
    </div>
HTML5;
        $app_engine_user = AppAuthService::user();
        if ($app_engine_user) {
            $user_email = $app_engine_user->getEmail();
            $dropdown_links = array($this->link(AppAuthService::logout_url(), 'Logout'));
            $link_list = array();
            foreach ($dropdown_links as $dropdown_link) {
                $link_list[] = sprintf('<li>%s</li>', $dropdown_link);
            }
            $user_button = sprintf($logged_in_dropdown, $user_email, join('', $link_list));
        } else {
            $format = <<<HTML5
    <div class="user-button">
      %s
    </div>
HTML5;
            $link = $this->link(AppAuthService::login_url(), 'Login', array('class' => 'btn btn-primary navbar-btn'));
            $user_button = sprintf($format, $link);
        }
        return $user_button;
    }
<?php

$t = $this;
# templater object
$auth = new AppAuthService();
?>
    <?php 
if (NeechyConfig::stage() == 'dev') {
    ?>
      <div class="dev-footer">
        <h4>App Engine Dev Server</h4>
        <p>Using <?php 
    echo NeechyConfig::environment();
    ?>
 config settings.</p>
        <?php 
    if ($auth->user) {
        ?>
        <p>Logged in as <?php 
        echo $auth->user_is_admin() ? 'admin' : 'user';
        ?>
.</p>
        <?php 
    } else {
        ?>
        <p>Not logged in.</p>
        <?php 
    }
    ?>
      </div>
    <?php 
示例#5
0
 public function handle()
 {
     $auth = AppAuthService::redirect_user_if_not_admin();
     $content = $this->route();
     return $this->respond($content);
 }