public function actionNewUser() { $session = \Yii::$app->session; $newUser = $session->get('newUser'); $db = new \SQLite3('flair'); $tablename = "userAccounts"; $alreadyExists = ProfileController::getUsername(0, $newUser["username"]); if ($alreadyExists) { $session->set("alreadyExists", true); return $this->redirect('@web/index.php/account'); } //CREATE TABLE userAccounts (ID INTEGER PRIMARY KEY AUTOINCREMENT, username VARCHAR(30), password VARCHAR(20)); $db->exec("INSERT INTO {$tablename}\n\t\t(username, password)\n\t\tVALUES ('{$newUser["username"]}', '{$newUser["password"]}')"); $db->close(); unset($db); return $this->redirect('@web/index.php/login/from-account'); }
/** * Finds the Number of Notifications that should be displayed to an Admin. Both for proposed APIs and CBS. * @return int */ public function getAdminNotifNum() { // Count and add the APIs that are under review $apis = Apis::find()->where(['cbs' => 0, 'status' => 'Under Review']); $notifNum = $apis->count(); // Count and add the CBS that are still pending review $cbs = Apis::find()->where(['cbs' => 1, 'status' => 'pending']); $notifNum += $cbs->count(); // Add the usual following notification count $notifNum += ProfileController::getFollowingAPIsUsersNotifNum(); return $notifNum; }
use App\Controllers\AboutController; use App\Controllers\ThreadsController; use App\Controllers\MerchandiseController; use App\Controllers\ThreadSuggestController; use App\Controllers\ErrorController; use App\Controllers\AuthenticationController; use App\Controllers\CommentsController; use App\Controllers\ProfileController; use App\Controllers\SearchController; use App\Services\Exceptions\InsufficientPrivilegesException; use App\Models\Exceptions\ModelNotFoundException; $page = isset($_GET['page']) ? $_GET['page'] : 'threads'; try { switch ($page) { case "profile": $controller = new ProfileController(); $controller->show(); break; case "search": $controller = new SearchController(); $controller->search(); break; //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// case "login": $controller = new AuthenticationController(); $controller->login(); break; case "auth.attempt": $controller = new AuthenticationController(); $controller->attempt();
<?php $this->beginBody(); ?> <div class="wrap"> <?php NavBar::begin(['brandLabel' => '<img src="' . Yii::getAlias('@web') . '/images/OPENi_logo.png">', 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar navbar-default navbar-fixed-top']]); $menuItems = [['label' => 'Home', 'url' => ['/']], ['label' => 'Categories', 'url' => ['/categories/']], ['label' => 'APIs', 'url' => ['/apis/']], ['label' => 'Objects', 'url' => ['/objects/']], ['label' => 'CBS', 'url' => ['/cbs/']], ['label' => 'Swagger', 'url' => ['/swagger']], ['label' => 'About', 'url' => ['/site/about']]]; if (Yii::$app->user->isGuest) { $menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']]; $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']]; } else { $menuItems[] = ['label' => 'Profile', 'url' => ['/profile/']]; if (array_key_exists('admin', Yii::$app->authManager->getRolesByUser(Yii::$app->user->id))) { $menuItems[] = '<li role="presentation"><a href="' . Yii::getAlias('@web') . '/profile/adminnotifications" class="navbar-badge-link"><span class="badge navbar-badge" data-toggle="tooltip" data-placement="bottom" title="New Notifications">' . ProfileController::getAdminNotifNum() . '</span></a></li>'; } else { $menuItems[] = '<li role="presentation"><a href="' . Yii::getAlias('@web') . '/profile/notifications" class="navbar-badge-link"><span class="badge navbar-badge" data-toggle="tooltip" data-placement="bottom" title="New Notifications">' . ProfileController::getFollowingAPIsUsersNotifNum() . '</span></a></li>'; } $menuItems[] = ['label' => 'Logout (' . Yii::$app->user->identity->username . ')', 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']]; } echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right'], 'items' => $menuItems]); NavBar::end(); ?> <div class="container"> <?php echo Breadcrumbs::widget(['links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : []]); ?> <?php echo Alert::widget(); ?> <?php