Exemplo n.º 1
0
    public function top()
    {
        $userSession = new userSessions();
        $userID = (int) $userSession->getUserID();
        if ($userID) {
            /*
             * Home, Profile, Photo, Notification, Message, Settings
             */
            return <<<EOF
            <div class="navbar-fixed-top">
    <nav class="socialSample-navbar" role="navigation" ng-controller="navController">
<ul class="socialSample-navbar-right">
     <li class="nav-item"><a ui-sref=".home" class="home-nav-btn circle"><span class="glyphicon glyphicon-home"></span></span></a></li>
     <li class="nav-item"><a ui-sref=".profile({ uid: (mc.user.username || mc.user.uid) })" class="profile-nav-btn circle"><span class="glyphicon glyphicon-user"></span></a></li>
     <li class="nav-item"><a ui-sref=".message({ uid: (mc.user.username || mc.user.uid) })" class="message-nav-btn circle"><span class="glyphicon glyphicon-comment"></span><span class="label label-danger label-as-badge">200</span></a></li>
     <li class="nav-item"><a href="#" data-template="/notifications?ng-view=false" data-placement="left" data-animation="am-slide-left" bs-aside="aside" data-container="body" data-backdrop="false" class="notification-nav-btn circle"><span class="glyphicon glyphicon-globe"></span><span class="label label-danger label-as-badge">1</span></a></li>
     <li class="nav-item"><a href="#" class="settings-nav-btn circle" onclick="return false;" settings-popover><span class="glyphicon glyphicon-cog"></span></a></li>
</ul>
    </nav>
</div>
EOF;
        } else {
            return <<<EOF
                        <div class="navbar-fixed-top">
    <nav class="socialSample-navbar" role="navigation">
        <div class="navbar-header">
            <a target="_self" class="navbar-brand" href="/">socialSample</a>
        </div>
<ul class="nav navbar-nav navbar-right">
     <li class="nav-item"><a target="_self" href="/login" class="default-btn">Log in</a></li>
     <li class="nav-item"><a target="_self" href="/signup" class="default-btn">Sign up</a></li>
</ul>
    </nav>
    </div>
EOF;
        }
    }
 public function loginAction()
 {
     session_start();
     /*
     if ($this->detect->isMobile() || $this->detect->isTablet())
         {
             $this->view->pick('mobile/auth/login');
         } else
         {
             $this->view->pick('auth/login');
         }
     */
     $this->view->pick('auth/login');
     $userSession = new userSessions();
     $this->view->setVar('title', 'Login');
     //$this->view->setRenderLevel($this->view->setRenderLevel(View::LEVEL_LAYOUT));
     $_userID = $userSession->getUserID();
     if ($this->request->isPost() && $_userID) {
         $this->response->setJsonContent(array("redirect" => null, "success" => true));
         $this->response->send();
         exit;
     }
     if ($_userID) {
         $this->response->redirect('/home/');
     }
     if ($this->request->isGet()) {
         $provider = $this->request->get('provider');
         if ($provider) {
             $adapter = $this->auth->authenticate($provider);
             $userProfile = $adapter->getUserProfile();
             $user_contacts = $adapter->getUserContacts();
             $uid = self::accountExists($userProfile, $provider);
             $adapter->logout();
             if (!$uid) {
                 $uid = self::createSocialAccount($userProfile, $provider);
             }
             $userSession->registerSession($uid);
             $this->response->redirect('/home/', true);
             $this->response->send();
             exit;
             //Account Setup
         } else {
             //missing provider
             //$this->flash->error('Provider is missing.');
         }
     }
     if ($this->request->isPost()) {
         $this->view->setRenderLevel(view::LEVEL_NO_RENDER);
         $userSession = new userSessions();
         $json = $this->request->getJsonRawBody();
         $user = (new users())->getUserWithEmail($json->email);
         if ($user == null) {
             $this->response->setJsonContent(array("redirect" => null, "success" => false, "alerts" => array('title' => '', 'message' => 'Either email or password is incorrect you entered.', 'type' => 'danger')));
             $this->response->send();
             exit;
         }
         $hash = (new password())->testPass((string) $json->password, (string) $user->password['salt'], (int) $this->config->password->length, (int) $user->password['iterations'], (string) $user->password['alg']);
         if ($user && $hash == $user->password['hash']) {
             $userSession->registerSession($user->uid);
             $this->response->setJsonContent(array("redirect" => null, "success" => true));
             $this->response->send();
             exit;
         } else {
             $this->response->setJsonContent(array("redirect" => null, "success" => false, "alerts" => array('title' => '', 'message' => 'Either email or password is incorrect you entered.', 'type' => 'danger')));
             $this->response->send();
             exit;
         }
     }
     session_write_close();
 }