Skip to content

Commit

Permalink
login: move to login page
Browse files Browse the repository at this point in the history
This allows us to protect other pages too in future.

Change-Id: I666e56f9cc287bbfea2a6dfe2049146765164331
  • Loading branch information
andi34 committed Jan 3, 2020
1 parent 515497c commit 42f2bf4
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ resources/css/admin.css
resources/css/style.css
/archives/
resources/css/rounded.css
resources/css/login.css
32 changes: 4 additions & 28 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@
require_once('../lib/config.php');
require_once('../lib/configsetup.inc.php');

// LOGIN
$username = $config['login_username'];
$hashed_password = $config['login_password'];
$error = false;

if (isset($_POST['submit'])) {
if (isset($_POST['username']) && $_POST['username'] == $username && isset($_POST['password']) && password_verify($_POST["password"], $hashed_password)) {
//IF USERNAME AND PASSWORD ARE CORRECT SET THE LOG-IN SESSION
$_SESSION['auth'] = true;
} else {
// DISPLAY FORM WITH ERROR
$error = true;
}
}
// END LOGIN

?>
<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -139,18 +123,10 @@
<span data-l10n="saveerror"></span>
</span>
</button>
<?php else: ?>
<form method='post' class="login">
<label for="username"><span data-l10n="login_username"></span></label>
<input type="text" name="username" id="username" autocomplete="on">
<label for="password"><span data-l10n="login_password"></span></label>
<input type="password" name="password" id="password" autocomplete="on">
<input type="submit" name="submit" value="submit">
<?php if ($error !== false) {
echo '<p style="color: red;"><span data-l10n="login_invalid"></span></p>';
} ?>
</form>
<?php endif; ?>
<?php else:
header("location: ../login.php");
exit;
endif; ?>
</div>
</div>

Expand Down
96 changes: 96 additions & 0 deletions login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
session_start();

require_once('lib/config.php');

// LOGIN
$username = $config['login_username'];
$hashed_password = $config['login_password'];
$error = false;

if (isset($_POST['submit'])) {
if (isset($_POST['username']) && $_POST['username'] == $username && isset($_POST['password']) && password_verify($_POST["password"], $hashed_password)) {
//IF USERNAME AND PASSWORD ARE CORRECT SET THE LOG-IN SESSION
$_SESSION['auth'] = true;
} else {
// DISPLAY FORM WITH ERROR
$error = true;
}
}
// END LOGIN


?>
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
<meta name="msapplication-TileColor" content="<?=$config['colors']['primary']?>">
<meta name="theme-color" content="<?=$config['colors']['primary']?>">

<title>Photobooth Login</title>

<!-- Favicon + Android/iPhone Icons -->
<link rel="apple-touch-icon" sizes="180x180" href="resources/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="resources/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="resources/img/favicon-16x16.png">
<link rel="manifest" href="resources/img/site.webmanifest">
<link rel="mask-icon" href="resources/img/safari-pinned-tab.svg" color="#5bbad5">

<!-- Fullscreen Mode on old iOS-Devices when starting photobooth from homescreen -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />

<link rel="stylesheet" href="node_modules/normalize.css/normalize.css" />
<link rel="stylesheet" href="node_modules/font-awesome/css/font-awesome.css" />
<link rel="stylesheet" href="node_modules/photoswipe/dist/photoswipe.css" />
<link rel="stylesheet" href="node_modules/photoswipe/dist/default-skin/default-skin.css" />
<link rel="stylesheet" href="resources/css/login.css" />
<?php if ($config['rounded_corners']): ?>
<link rel="stylesheet" href="resources/css/rounded.css" />
<?php endif; ?>
</head>

<body class="deselect">
<div id="wrapper">
<div class="login-panel">
<?php if( !$config['login_enabled'] || (isset($_SESSION['auth']) && $_SESSION['auth'] === true)):
header("location: ../admin/index.php");
exit;
else: ?>
<form method='post' class="login">
<label for="username"><span data-l10n="login_username"></span></label>
<input type="text" name="username" id="username" autocomplete="on" required>
<label for="password"><span data-l10n="login_password"></span></label>
</br>
<input type="password" name="password" id="password" autocomplete="on" required>
</br></br>
<input type="submit" name="submit" value="Login" class="btn btn--tiny btn--flex">
<?php if ($error !== false) {
echo '<p style="color: red;"><span data-l10n="login_invalid"></span></p>';
} ?>
</form>
<?php endif; ?>
</br>
<a class="btn btn--tiny btn--flex" href="login.php"><i class="fa fa-refresh"></i> <span data-l10n="reload"></span></a>
</div>


<div id="adminsettings">
<div style="position:absolute; bottom:0; right:0;">
<img src="resources/img/spacer.png" alt="adminsettings" ondblclick="adminsettings()" />
</div>
</div>

</div>

<script type="text/javascript" src="api/config.php"></script>
<script type="text/javascript" src="node_modules/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="resources/js/adminshortcut.js"></script>
<script type="text/javascript" src="resources/js/l10n.js"></script>
<script type="text/javascript" src="resources/js/theme.js"></script>
<script type="text/javascript" src="resources/lang/<?php echo $config['language']; ?>.js"></script>
</body>
</html>
34 changes: 34 additions & 0 deletions resources/sass/login.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@import "modules/theme";
@import "partials/fonts";
@import "partials/basic";
@import "partials/button";

#wrapper {
display: block;
position: relative;
overflow-y: auto;
background-color: $mainColor;
background-image: $adminBackground;
background-position: center center;
width: 100%;
height: 100%;
}

input[type="text"],
input[type="password"] {
background: #f8f9fc;
border: 1px solid #eff2f7;
border-radius: 4px;
width: 100%;
padding: 0 10px;
}

.login-panel {
width: 500px;
padding: 30px 30px 90px;
height: auto;
margin: 50px auto;
background: #fff;
position: relative;
max-width: 100%;
}
5 changes: 5 additions & 0 deletions resources/sass/rounded.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
}
}

.login-panel {
border: 0 none;
border-radius: 10px;
}

button {
border: 2px solid #eee;
border-radius: 10px;
Expand Down

0 comments on commit 42f2bf4

Please sign in to comment.