Archived
1
0
Disbranĉigi 0

Added login... sort of?

This commit is contained in:
Jenga Phoenix 2019-02-20 08:04:55 -06:00
parent 0e219485ab
commit 7001dee230
26 changed files with 483 additions and 248 deletions

View File

@ -8,30 +8,39 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. */
$depth = "";
$depth = "../";
$title = "";
$mark = "post";
include "res/lib/load.php";
$mark = "p_index";
include "../res/lib/load.php";
// -------------------------------------
$id = $_GET['id'] ?? post_name_to_id($_GET['name']);
$id = $_GET['id'] ?? post_title_to_id($_GET['name']);
$name = post_title($id);
// -------------------------------------
if (empty($_GET['id']) && empty($_GET['name'])) {
root_redirect('p/list/');
} else if (!is_post_id($_GET['id']) && !is_post_title($_GET['name'])) {
general_error("We can't find that post! :(");
}
// --------------------------------------
$text = markdown(post_text($id));
$date = post_date($id);
$data = post_data($id);
$post_text = markdown(post_text($id));
$post_date = post_date($id);
$post_data = post_data($id);
$user_id = post_author($id);
$username = user_name($user_id);
$full_name = user_full_name($user_id);
$local_exports = array('id' => $id, 'text' => $text, 'username' => $username,
'user_id' => $user_id, 'full_name' => $full_name,
'data' => $data, 'title' => $name,
'date' => $date);
$local_exports = array('post_id' => $id, 'post_text' => $post_text,
'post_author' => $user_id,
'post_data' => $post_data, 'post_title' => $name,
'post_date' => $date);
// -------------------------------------

20
p/list/index.php Normal file
View File

@ -0,0 +1,20 @@
<?php
/* This file is free software: you can redistribute it and/or modify
it under the terms of version 3 of the GNU Affero General Public
License as published by the Free Software Foundation.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. */
$depth = "../../";
$title = "";
$mark = "p_list_index";
include "../../res/lib/load.php";
// -------------------------------------
display_page($mark, $depth, $title);
?>

View File

@ -9,7 +9,7 @@
GNU Affero General Public License for more details. */
$title = "New Post";
$mark = "new_post_index";
$mark = "p_new_index";
$depth = "../../";
include "../../res/lib/load.php";

View File

@ -16,6 +16,9 @@ function display_page($mark, $depth, $title, $local_exports=array()) {
echo $GLOBALS['twig']->render("head.twig.html",
make_exports($depth, $title, $mark,
$local_exports));
echo $GLOBALS['twig']->render("navbar.twig.html",
make_exports($depth, $title, $mark,
$local_exports));
echo $GLOBALS['twig']->render($mark . ".twig.html",
make_exports($depth, $title, $mark,
$local_exports));

View File

@ -41,6 +41,8 @@ $twig = new Twig_Environment($loader, ['cache' =>
// global variable declaration
global $users; $users = user_ids();
global $user; $user = array();
global $posts; $posts = post_ids_recent();
global $post; $post = array();
$push_user_data = function($user_id) {
$user_name = user_name($user_id);
@ -48,11 +50,14 @@ $push_user_data = function($user_id) {
$GLOBALS['user'][$user_name] = user_data($user_id);
};
array_map($push_user_data, $users);
$push_post_data = function($post_id) {
$post_title = post_title($post_id);
$GLOBALS['post'][$post_id] = post_data($post_id);
$GLOBALS['post'][$post_title] = post_data($post_id);
};
global $posts; $posts = post_ids_recent();
global $post; $post = array();
$post = array_map("post_data", $posts);
array_map($push_user_data, $users);
array_map($push_post_data, $posts);
// -----------------
@ -61,6 +66,7 @@ $twig_exports = array('theme' => $GLOBALS['theme'],
'users' => $GLOBALS['users'],
'user' => $GLOBALS['user'],
'posts' => $GLOBALS['posts'],
'post' => $GLOBALS['post']);
'post' => $GLOBALS['post'],
'instance_title' => $GLOBALS['instance_title']);
?>

View File

@ -47,8 +47,7 @@ function post_delete($id) {
// -------------------------------------
function post_name_to_id($name) {
function post_title_to_id($name) {
return db_get_cell("posts", "title", string_wrap($name), "id");
}

View File

@ -140,6 +140,26 @@ function is_user_id($id) {
}
}
// NUMBER --> BOOLEAN
// Return whether or not a number is a post ID
function is_post_id($id) {
if (post_title($id)) {
return true;
} else {
return false;
}
}
// NUMBER --> BOOLEAN
// Return whether or not a string is a post name
function is_post_title($title) {
if (post_title_to_id($title)) {
return true;
} else {
return false;
}
}
// -------------------------------------
// STRING --> BOOLEAN
@ -156,6 +176,21 @@ function is_free_user_id($id) {
return true; } else { return false; }
}
// STRING --> BOOLEAN
// Return whether or not a given string is a valid (unused) post title
function is_free_post_title($title) {
if (!is_post_title($title) && is_ne_string($title)) {
return true; } else { return false; }
}
// STRING --> BOOLEAN
// Return whether or not a given number is a valid (unused) psot ID
function is_free_post_id($id) {
if (!is_post_id($id) && is_int($id)) {
return true; } else { return false; }
}
// -------------------------------------
function bleep_word($word, $replacement) {
$word = str_replace("a", $replacement, $word);

View File

@ -142,6 +142,49 @@ function user_data($id) {
// -------------------------------------
// NUMBER --> NUMBER
// Generate a new login-token and associate it with the user's account.
// Returns the token number.
function user_token_create($id) {
$token = rand(0, 5000000);
db_set_cell("lusers", "id", $id, "token", rand(0, 5000000));
return $token;
}
// NUMBER NUMBER --> BOOLEAN
// Return whether or not a token is valid for a certain user account
function user_token_validate($id, $token) {
$valid_token = db_get_cell("lusers", "id", $id, "token");
if ($token == $valid_token) {
return true;
} else {
return false;
}
}
// -------------------------------------
// NUMBER --> NIL
// Log a user in-- create a token, then make a cookie with said token.
function user_log_in($id) {
$token = user_token_create($id);
setcookie("token", $token, 2628000);
setcookie("id", $id, 2628000);
}
function logged() {
if (user_token_validate($id, $_COOKIE['token'])) {
return $id;
} else {
return "no";
}
}
// -------------------------------------
// NUMBER STRING --> BOOLEAN
// Return whether or not a given password is valid.
function user_valid_password($id, $password) {

View File

@ -1,213 +1,74 @@
/*PEN STYLES*/
* {
box-sizing: border-box;
}
.postbox {
height: 500px;
}
/* The color-combo we're using:
* https://www.colorcombos.com/color-schemes/116/ColorCombo116.html */
body {
background: #f1f1f1;
margin: 2rem;
}
$color_white: #fff;
$color_prime: #5ad67d;
$color_grey: #e2e2e2;
$color_grey_dark: #a2a2a2;
.blog-card {
display: flex;
flex-direction: column;
margin: 1rem auto;
box-shadow: 0 3px 7px -1px rgba(#000, .1);
margin-bottom: 1.6%;
background: $color_white;
line-height: 1.4;
background-color: #CECFCE;
font-family: sans-serif;
border-radius: 5px;
overflow: hidden;
z-index: 0;
a {
color: inherit;
&:hover {
color: $color_prime;
}
}
&:hover {
.photo {
transform: scale(1.3) rotate(3deg);
}
}
.meta {
position: relative;
z-index: 0;
height: 200px;
}
.photo {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-size: cover;
background-position: center;
transition: transform .2s;
}
.details,
.details ul {
margin: auto;
padding: 0;
list-style: none;
}
.details {
position: absolute;
top: 0;
bottom: 0;
left: -100%;
margin: auto;
transition: left .2s;
background: rgba(#000, .6);
color: $color_white;
padding: 10px;
font-size: 17px;
color: #073642;
width: 100%;
font-size: .9rem;
a {
text-decoration: dotted underline
}
ul li {
display: inline-block;
}
.author:before {
font-family: FontAwesome;
margin-right: 10px;
content: "\f007";
}
.date:before {
font-family: FontAwesome;
margin-right: 10px;
content: "\f133";
}
.tags {
ul:before {
font-family: FontAwesome;
content: "\f02b";
margin-right: 10px;
}
li {
margin-right: 2px;
&:first-child {
margin-left: -4px;
}
}
}
}
.description {
padding: 1rem;
background: $color_white;
position: relative;
z-index: 1;
h1,
h2 {
font-family: Poppins, sans-serif;
}
h1 {
line-height: 1;
margin: 0;
font-size: 1.7rem;
}
h2 {
font-size: 1rem;
font-weight: 300;
text-transform: uppercase;
color: $color_grey_dark;
margin-top: 5px;
}
.read-more {
text-align: right;
a {
color: $color_prime;
display: inline-block;
position: relative;
&:after {
content: "\f061";
font-family: FontAwesome;
margin-left: -10px;
opacity: 0;
vertical-align: middle;
transition: margin .3s, opacity .3s;
}
&:hover:after {
margin-left: 5px;
opacity: 1;
}
}
}
}
p {
position: relative;
margin: 1rem 0 0;
&:first-of-type {
margin-top: 1.25rem;
&:before {
content: "";
position: absolute;
height: 5px;
background: $color_prime;
width: 35px;
top: -0.75rem;
border-radius: 3px;
}
}
}
&:hover {
.details {
left: 0%;
}
}
@media (min-width: 640px) {
flex-direction: row;
max-width: 700px;
.meta {
flex-basis: 40%;
height: auto;
}
.description {
flex-basis: 60%;
&:before {
transform: skewX(-3deg);
content: "";
background: #fff;
width: 30px;
position: absolute;
left: -10px;
top: 0;
bottom: 0;
z-index: -1;
}
}
&.alt {
flex-direction: row-reverse;
.description {
&:before {
left: inherit;
right: -10px;
transform: skew(3deg)
}
}
.details {
padding-left: 25px;
}
}
}
}
nav {
background-color: #84596B;
width: 100%;
margin: 0;
padding: 0;
}
nav ul {
background-color: #84596B;
overflow: hidden;
color: #FFFFFF;
}
nav li {
display: block;
margin-left: 20px;
margin-right: 20px;
background-color: #84596B;
float: left;
padding: 10px;
}
#star {
margin-left: 1px;
margin-right: 1px;
padding-left: 0px;
padding-right: 0px;
font-weight: bold;
color: #D86969;
}
#star:hover {
background-color: inherit;
}
nav li:hover {
background-color: #AFB170;
}
nav li a {
text-decoration: none;
color: #FFFFFF;
}
.right {
float: right;
}
p {
max-width: 700px;
padding-left: 10%;
}
.post_card {
height: 200px;
display: inline-block;
overflow: hidden;
max-width: 200px;
border-style: solid;
border-width: 2px;
border-color: #B58AA5;
border-radius: 5px;
}

View File

@ -1,12 +1,5 @@
{% for post_id in posts %}
{% set post_author = post[post_id]['author'] %}
{% set post_username = user[post_author]['name'] %}
{% set post_full_name = user[post_author]['full_name'] %}
{% set post_title = post[post_id]['title'] %}
{% set post_date = post[post_id]['date'] %}
{% set post_desc = post[post_id]['desc'] %}
{{ include('meta_post_card.html') }}
{% set post_id = post_id %}
{{ include('meta_post_card.twig.html') }}
{% endfor %}

View File

@ -0,0 +1,15 @@
<ul class="post_card">
<li>
<a href="{{ depth }}p/index.php?id={{ post_id }}">
{{ post[post_id]['title'] }}
</a>
</li>
{% set author = post[post_id]['author'] %}
<li>
<a href="{{ depth }}u/index.php?id={{ author }}">
{{ user[author]['full_name'] }}
</a>
</li>
<li>{{ post[post_id]['date'] }}</li>
<li><p>{{ post[post_id]['desc'] }}</p></li>
</ul>

View File

@ -0,0 +1,17 @@
<nav>
<ul>
<li id="star">&#9733;</li>
<li id="nav_instance">
<a href="{{ depth }}index.php">{{ instance_title }}</a>
</li>
<li id="nav_posts">
<a href="{{ depth }}p/">Posts</a>
</li>
<li id="nav_users">
<a href="{{ depth }}u/list/">Users</a>
</li>
<li class="right" id="nav_register">
<a href="{{ depth }}u/new/">Register</a>
</li>
</ul>
</nav>

View File

@ -0,0 +1,9 @@
<h1>{{ post_title }}</h1>
<h2>By
<a href="{{ depth }}u/index.php?name={{ user[post_author]['name'] }}">
{{ user[post_author]['full_name'] }}
</a>
</h2>
<h3>{{ post_date }}</h3>
<p>{{ post_text }}</p>

View File

@ -0,0 +1,19 @@
<table>
{% for id in posts %}
<tr>
<td>
<a href="{{ depth }}p/index.php?id={{ id }}">
{{ post[id]['title'] }}
</a>
</td>
<td>
<a href="{{ depth }}u/?id={{ post[id]['author'] }}">
{{ user[post[id]['author']]['full_name'] }}
</a>
</td>
<td>
{{ post[id]['date'] }}
</td>
</tr>
{% endfor %}
</table>

View File

@ -0,0 +1,28 @@
<section id="creation">
<form id="post_creation" action="private/post_create.php" method="post">
<section class="authentication">
<p><label>Username</label>
<input name="auth_user" type="text" />
</p>
<p><label>Password</label>
<input name="auth_pass" type="password">
</p>
</section>
<hr />
<section class="post_metadata">
<p><label>Title</label><input name="title" type="text" /></p>
<p><label>Desc</label><input name="desc" type="text" /></p>
</section>
<section class="post_data">
<p><label>Text</label><br />
<textarea name="text" rows="20" cols="80"></textarea>
</section>
<p><input type="submit" /></p>
</form>
</section>

View File

@ -0,0 +1,11 @@
<h1>{{ user_full_name }}</h1>
<h3>{{ user_website }} &lt;{{ user_email }}&gt;</h3>
<h3>({{ user_name }})</h3>
<p>{{ user_bio }}</p>
{% for post_id in user_posts %}
{% set post_id = post_id %}
{{ include ('meta_post_card.twig.html') }}
{% endfor %}
</ul>

View File

@ -0,0 +1,7 @@
<ul id="user_list">
{% for user_id in users %}
<a href="{{ depth }}u/index.php?id={{ user_id }}">
<li class="user_name">{{ user[user_id]['full_name'] }}</li>
</a>
{% endfor %}
</ul>

View File

@ -0,0 +1,15 @@
<form id="user_creation" action="private/user_create.php" method="post">
<p><label>Username</label><input name="name" type="text" /></p>
<p><label>Password</label> <input name="password" type="password" /></p>
<hr />
<p><label>Full Name</label><input name="full_name" type="text"/> </p>
<p><label>Biography</label><input name="bio" type="text" /> </p>
<p><label>E-mail</label><input name="email" type="email" /></p>
<p><label>Website</label><input name="url" type="url" /></p>
<hr />
<p><input type="submit" /></p>
</form>

View File

@ -0,0 +1,8 @@
<form id="user_authentication" action="private/user_login.php" method="post">
<p><label>Username</label><input name="name" type="text" /></p>
<p><label>Password</label> <input name="password" type="password" /></p>
<hr />
<p><input type="submit" /></p>
</form>

View File

@ -9,10 +9,10 @@
GNU Affero General Public License for more details. */
$depth = "";
$mark = "user";
$depth = "../";
$mark = "u_index";
$title = "Death";
include "res/lib/load.php";
include "../res/lib/load.php";
// -------------------------------------
@ -21,12 +21,11 @@ $name = user_name($id);
// -------------------------------------
if (!is_user_id($id)) {
if (empty($_GET['id']) && empty($_GET['name'])) {
root_redirect('u/list/');
} else if (!is_user_id($id) && empty($name)) {
general_error("It looks like that isn't a real user.");
}
if (empty($name)) {
general_error("It looks like that isn't a real user...");
}
// -------------------------------------
@ -45,11 +44,12 @@ array_map($push_post_data, $user_posts);
// -----------------
$local_exports = array('id' => $id, 'full_name' => unscrub(user_full_name($id)),
'name' => $name,
'bio' => unscrub(user_biography($id)),
'email' => user_email($id),
'website' => user_website($id),
$local_exports = array('user_id' => $id,
'user_full_name' => unscrub(user_full_name($id)),
'user_name' => $name,
'usr_bio' => unscrub(user_biography($id)),
'user_email' => user_email($id),
'user_website' => user_website($id),
'user_posts' => $user_posts,
'user_post' => $user_post);

23
u/list/index.php Normal file
View File

@ -0,0 +1,23 @@
<?php
/* This file is free software: you can redistribute it and/or modify
it under the terms of version 3 of the GNU Affero General Public
License as published by the Free Software Foundation.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. */
$depth = "../../";
$title = "";
$mark = "u_list_index";
include "../../res/lib/load.php";
// -------------------------------------
display_page($mark, $depth, $title);
echo $_COOKIE['id'];
?>

24
u/new/index.php Normal file
View File

@ -0,0 +1,24 @@
<?php
/* This file is free software: you can redistribute it and/or modify
it under the terms of version 3 of the GNU Affero General Public
License as published by the Free Software Foundation.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. */
$title = "Control Panel";
$depth = "../../";
$mark = "u_new_index";
include "../../res/lib/load.php";
// --------------------------------------
if ($GLOBALS['registration'] == true) {
display_page($mark, $depth, $title);
} else {
general_error("Sorry, registration's disabled on this server!");
}
?>

View File

@ -0,0 +1,39 @@
<?php
/* This file is free software: you can redistribute it and/or modify
it under the terms of version 3 of the GNU Affero General Public
License as published by the Free Software Foundation.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. */
$depth = "../../../";
include "../../../res/lib/load.php";
$name = scrub($_POST['name']);
$full = scrub($_POST['full_name']);
$bio = scrub($_POST['bio']);
$email = scrub($_POST['email']);
$url = scrub($_POST['url']);
$pass = scrub($_POST['password']);
// -------------------------------------
if ($GLOBALS['registration'] != true) {
general_error("Sorry, registration's disabled on this server!");
}
input_enforce(array($name, $full, $bio, $email, $url, $pass),
array("Username", "Full name", "Biography", "E-mail",
"URL", "Password"),
array("free_user_name", "string", "string",
"email", "url", "ne_string"));
// -------------------------------------
user_create($name, $pass, "contributor", $full, $email, $url, $bio);
root_redirect("u/index.php?name=" . $name);
?>

20
u/old/index.php Normal file
View File

@ -0,0 +1,20 @@
<?php
/* This file is free software: you can redistribute it and/or modify
it under the terms of version 3 of the GNU Affero General Public
License as published by the Free Software Foundation.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. */
$title = "Control Panel";
$depth = "../../";
$mark = "u_old_index";
include "../../res/lib/load.php";
// --------------------------------------
display_page($mark, $depth, $title);
?>

View File

@ -0,0 +1,31 @@
<?php
/* This file is free software: you can redistribute it and/or modify
it under the terms of version 3 of the GNU Affero General Public
License as published by the Free Software Foundation.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. */
$depth = "../../../";
include "../../../res/lib/load.php";
$user = scrub($_POST['name']);
$pass = scrub($_POST['password']);
// -------------------------------------
input_enforce(array($user, $pass),
array("Username", "Password"),
array("user_name", "string"));
// -------------------------------------
if (user_valid_password(user_name_to_id($user), $pass)) {
user_log_in(user_name_to_id($user));
}
root_redirect("u/index.php?name=" . $user);
?>