Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Add dynamic login/logout dropdown menu to navbar.
Browse files Browse the repository at this point in the history
Add dynamic login/welcome message to index.php.
Change login link from static text to dynamically generated according to the current scheme (http/https), domain and path.
Remove some excessive commenting from functions.php.
  • Loading branch information
dimitrisp2 committed Oct 15, 2018
1 parent 5aed947 commit f6ba24d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 31 deletions.
3 changes: 3 additions & 0 deletions common/head.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<a class="nav-item nav-link" href="projects.php">Projects</a>
<a class="nav-item nav-link" href="tasks.php">Tasks</a>
<a class="nav-item nav-link" href="users.php">Users</a>
<div class="btn-group">
<?php echo GetMenu(); ?>
</div>
</div>
</div>
</nav>
Expand Down
67 changes: 38 additions & 29 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,13 @@
// MySQL DB
$sqldb = "translator";

////////////////////////////////////////////////////////////
// functions.php //
// Contains all the functions that interact with MySQL DB //
// //
// //
// DO NOT EDIT BELOW THIS LINE IF YOU DON'T KNOW WHAT YOU //
// ARE DOING //
// //
// DO NOT EDIT BELOW THIS LINE IF YOU DON'T KNOW WHAT YOU //
// ARE DOING //
// //
// DO NOT EDIT BELOW THIS LINE IF YOU DON'T KNOW WHAT YOU //
// ARE DOING //
// //
// DO NOT EDIT BELOW THIS LINE IF YOU DON'T KNOW WHAT YOU //
// ARE DOING //
// //
// DO NOT EDIT BELOW THIS LINE IF YOU DON'T KNOW WHAT YOU //
// ARE DOING //
// //
// DO NOT EDIT BELOW THIS LINE IF YOU DON'T KNOW WHAT YOU //
// ARE DOING //
// //
// DO NOT EDIT BELOW THIS LINE IF YOU DON'T KNOW WHAT YOU //
// ARE DOING //
// //
////////////////////////////////////////////////////////////
// Below this line, this file holds all the crucial code of the app.
// Please do not edit anything if you don't know what you are doing

//////////////////////////
// //
// GENERIC DB FUNCTIONS //
// //
//////////////////////////

function openSQL() {
$GLOBALS['sqlcon'] = mysqli_connect($GLOBALS['sqlserver'], $GLOBALS['sqluser'], $GLOBALS['sqlpass'], $GLOBALS['sqldb']);
if (mysqli_connect_error()) {
Expand Down Expand Up @@ -500,6 +474,41 @@ function GetAllUsers() {
}
}

function GetMainPageContent() {
if (isset($_COOKIE['username'])) {
$hasaccess = CheckUserAccess($_COOKIE['username']);
} else {
$hasaccess = 0;
}
if ($hasaccess > 0) {
return "Welcome, " . $_COOKIE['username'] . ". You are already logged in, and you are registered as a member with access to the app, so feel free to stick around.";
} else {
return "This app is only intended for use by the <?php echo $teamname; ?> Translation Team. You need to login before you proceed to use anything in this app!<br /><a href=\"https://steemconnect.com/oauth2/authorize?client_id=aristotle.app&redirect_uri=". $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']) . "/callback.php\"; ?>&scope=login\" class=\"font-weight-bold\">Secure login via SteemConnect</a>";
}

}

function GetMenu() {
if (isset($_COOKIE['username'])) {
$hasaccess = CheckUserAccess($_COOKIE['username']);
} else {
$hasaccess = 0;
}
if ($hasaccess > 0) {
return "<button type=\"button\" class=\"btn btn-secondary dropdown-toggle\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\">Welcome ".$_COOKIE['username']."</button><div class=\"dropdown-menu dropdown-menu-right\"><a class=\"btn dropdown-item\" href=\"logout.php\">Logout</a></div>";
} else {
return "<button type=\"button\" class=\"btn btn-secondary dropdown-toggle\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\">Welcome, Guest</button><div class=\"dropdown-menu dropdown-menu-right\"><a class=\"btn dropdown-item\" href=\"https://steemconnect.com/oauth2/authorize?client_id=aristotle.app&redirect_uri=". $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']) . "/callback.php&scope=login\">Login via SteemConnect</a></div>";
}
}

function LogOut() {
unset($_COOKIE['username']);
unset($_COOKIE['code']);
setcookie('username', null, -1);
setcookie('code', null, -1);
Header("Location: index.php");
}

function closeSQL() {
global $sqlcon;
mysqli_close($sqlcon);
Expand Down
3 changes: 1 addition & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
<div class="container">
<div class="row">
<div class="col-lg-8 mx-auto text-center">
This app is only intended for use by the <?php echo $teamname; ?> Translation Team. You need to login before you proceed to use anything in this app!<br />
<a href="https://steemconnect.com/oauth2/authorize?client_id=aristotle.app&redirect_uri=http://localhost/tasklist/callback.php&scope=login" class="font-weight-bold">Secure login via SteemConnect</a><br />
<?php echo GetMainPageContent();?><br />
<hr />
Follow <a href="https://steemit.com/@dimitrisp" target="_blank">@dimitrisp</a> and the app's account <a href="https://steemit.com/@aristotle.team" target="_blank">@aristotle.team</a> for updates!<br />
<span class="font-weight-light font-italic">Right now, this app is only using the 'login' scope of SteemConnect, just to verify your identity. This app can't and won't post/transfer/vote anything with your account. Even if we wanted to, the 'login' scope is not giving us any permissions to do any of those actions.</span>
Expand Down

0 comments on commit f6ba24d

Please sign in to comment.