made a start

This commit is contained in:
flash 2016-02-05 13:26:31 +01:00
parent 264fe683d5
commit 01f162945c
11 changed files with 100 additions and 194 deletions

View file

@ -0,0 +1,24 @@
<?php
/**
* Holds the auth controllers.
*
* @package Sakura
*/
namespace Sakura\Controllers;
use Sakura\Template;
/**
* Authentication controllers.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class Auth
{
public static function login()
{
return Template::render('main/login');
}
}

View file

@ -62,23 +62,23 @@ class Urls
'/faq',
],
'SITE_LOGIN' => [
'/authenticate.php',
'/authenticate.php?ref=login',
'/login',
],
'SITE_LOGOUT' => [
'/authenticate.php',
'/authenticate.php?ref=logout',
'/logout',
],
'SITE_REGISTER' => [
'/authenticate.php',
'/authenticate.php?ref=register',
'/register',
],
'SITE_FORGOT_PASSWORD' => [
'/authenticate.php',
'/authenticate.php?ref=forgotpassword',
'/forgotpassword',
],
'SITE_ACTIVATE' => [
'/authenticate.php',
'/authenticate.php?ref=activate',
'/activate',
],
'INFO_PAGE' => [

View file

@ -1,75 +1,20 @@
# Set Error documents
ErrorDocument 404 /404.php
ErrorDocument 403 /404.php
ErrorDocument 401 /404.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
# Rewrite Stuff
RewriteEngine on
RewriteBase /
Options +FollowSymLinks -Indexes
RewriteEngine On
# Rewrite Rules
RewriteRule ^login/?$|^logout/?$|^activate/?$|^register/?$|^forgotpassword/?|^authenticate/?$ authenticate.php [L,QSA]
RewriteRule ^support/?$ support.php [L,QSA]
RewriteRule ^support/tracker/?$ support.php?tracker=true [L,QSA]
RewriteRule ^faq/?$ faq.php [L,QSA]
RewriteRule ^search/?$ search.php [L,QSA]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Info pages
RewriteRule ^p/([a-z]+)/?$ index.php?p=$1 [L,QSA]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# News
RewriteRule ^news/?$ news.php [L,QSA]
RewriteRule ^news/([0-9]+)/?$ news.php?id=$1 [L,QSA]
RewriteRule ^news/([a-z\-]+)/?$ news.php?cat=$1 [L,QSA]
RewriteRule ^news/([a-z\-]+)/([0-9]+)/?$ news.php?cat=$1&id=$2 [L,QSA]
RewriteRule ^news.xml$ news.php?xml [L,QSA]
# Settings
RewriteRule ^settings/?$ settings.php [L,QSA]
RewriteRule ^settings/([a-z]+)/?$ settings.php?cat=$1 [L,QSA]
RewriteRule ^settings/([a-z]+)/([a-z]+)/?$ settings.php?cat=$1&mode=$2 [L,QSA]
RewriteRule ^friends/?$ settings.php?friend-action=true [L,QSA]
RewriteRule ^notifications/?$ settings.php?request-notifications=true [L,QSA]
RewriteRule ^comments/?$ settings.php?comment-action=true [L,QSA]
# Members
RewriteRule ^members/?$ members.php [L,QSA]
RewriteRule ^members/([a-z]+)/?$ members.php?sort=$1 [L,QSA]
RewriteRule ^members/([0-9]+)/?$ members.php?rank=$1 [L,QSA]
RewriteRule ^members/([a-z]+)/([0-9]+)/?$ members.php?sort=$1&rank=$2 [L,QSA]
# Profiles
RewriteRule ^u/?$ profile.php [L,QSA]
RewriteRule ^u/([A-Za-z0-9\_\-\s\.]+)/?$ profile.php?u=$1 [L,QSA]
RewriteRule ^u/([A-Za-z0-9\_\-\s\.]+)/header/?$ imageserve.php?m=header&u=$1 [L,QSA]
RewriteRule ^u/([A-Za-z0-9\_\-\s\.]+)/comments/?$ profile.php?u=$1&view=comments [L,QSA]
RewriteRule ^u/([A-Za-z0-9\_\-\s\.]+)/groups/?$ profile.php?u=$1&view=groups [L,QSA]
RewriteRule ^u/([A-Za-z0-9\_\-\s\.]+)/friends/?$ profile.php?u=$1&view=friends [L,QSA]
RewriteRule ^u/([A-Za-z0-9\_\-\s\.]+)/threads/?$ profile.php?u=$1&view=threads [L,QSA]
RewriteRule ^u/([A-Za-z0-9\_\-\s\.]+)/posts/?$ profile.php?u=$1&view=posts [L,QSA]
RewriteRule ^u/([A-Za-z0-9\_\-\s\.]+)/report/?$ report.php?mode=user&id=$1 [L,QSA]
# Groups
RewriteRule ^g/?$ group.php [L,QSA]
RewriteRule ^g/([0-9]+)/?$ group.php?g=$1 [L,QSA]
# Serving Images
RewriteRule ^a/([0-9]+)$|a/([0-9]+).png$ imageserve.php?m=avatar&u=$1 [L,QSA]
RewriteRule ^bg/([0-9]+)$|bg/([0-9]+).png$ imageserve.php?m=background&u=$1 [L,QSA]
# Forum
RewriteRule ^forum/?$ index.php?forum=true [L,QSA]
RewriteRule ^forum/([0-9]+)/?$ viewforum.php?f=$1 [L,QSA]
RewriteRule ^forum/([0-9]+)/new/?$ posting.php?f=$1 [L,QSA]
RewriteRule ^forum/(thread|topic|[0-9+])/([0-9]+)/?$ viewtopic.php?t=$2 [L,QSA]
RewriteRule ^forum/(thread|topic|[0-9+])/([0-9]+)/reply/?$ posting.php?t=$2 [L,QSA]
RewriteRule ^forum/post/([0-9]+)/?$ viewtopic.php?p=$1 [L,QSA]
RewriteRule ^forum/post/([0-9]+)/edit/?$ posting.php?p=$1&edit=$1 [L,QSA]
RewriteRule ^forum/post/([0-9]+)/delete/?$ posting.php?p=$1&delete=$1 [L,QSA]
RewriteRule ^forum/post/([0-9]+)/(quote|reply)/?$ posting.php?p=$1&quote=$1 [L,QSA]
# Management
RewriteRule ^manage/?$ manage.php [L,QSA]
RewriteRule ^manage/([a-z\-]+)/?$ manage.php?cat=$1 [L,QSA]
RewriteRule ^manage/([a-z\-]+)/([a-z\-]+)/?$ manage.php?cat=$1&mode=$2 [L,QSA]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

View file

@ -1,5 +0,0 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ api.php [QSA,L]

View file

@ -1,74 +0,0 @@
<?php
/*
* Sakura API
*/
// Declare Namespace
namespace Sakura;
// Define that this page won't require templating
define('SAKURA_NO_TPL', true);
// Include components
require_once str_replace(basename(__DIR__), '../', dirname(__FILE__)) . 'sakura.php';
// Change to content type to text/plain and set the charset to UTF-8
header('Content-Type: text/plain; charset=utf-8');
// Trim leading slashes
$path = ltrim($_SERVER['REQUEST_URI'], '/');
// Explode the elements
$elems = explode('/', $path);
// Correct the path if mod_rewrite isn't used
if ($elems[0] == explode('/', ltrim($_SERVER['PHP_SELF'], '/'))[0]) {
// Remove the entry
unset($elems[0]);
// Resort the array
$elems = array_values($elems);
// Make sure there's at least one entry (even if empty)
if (!isset($elems[0])) {
$elems[] = "";
}
}
// Make sure the GET requests aren't present in the last entry
if (strpos($elems[max(array_keys($elems))], '?')) {
// If there are cut them all
$elems[max(array_keys($elems))] = strstr($elems[max(array_keys($elems))], '?', true);
}
// Predefine the return variable
$return = [];
// Select API version
switch (isset($elems[0]) ? $elems[0] : false) {
// API Version 1
case 'v1':
switch (isset($elems[1]) ? $elems[1] : false) {
// Authentication
case 'authenticate':
switch (isset($elems[2]) ? $elems[2] : false) {
case 'login':
$return = ['success' => 'LOGIN_PROCESS_HERE'];
break;
default:
$return = ['error' => ['NO_DATA_REQ']];
}
break;
default:
$return = ['error' => ['NO_DATA_REQ']];
}
break;
// Default fallback
default:
$return = ['error' => ['NO_API_VERSION']];
}
echo json_encode($return, (isset($_GET['pretty']) ? JSON_PRETTY_PRINT : 0));

View file

@ -257,7 +257,7 @@ a.default:active {
.viewforum .head,
.viewtopic .head,
.posting .head,
.loginPage > .loginCont .head,
.loginPage .head,
.messages .head {
margin: -1px -2px;
padding: 4px 5px 5px;
@ -269,8 +269,7 @@ a.default:active {
word-wrap: break-word;
}
.content-right .head,
.loginPage > .registerCont .head {
.content-right .head {
margin: -1px -2px -1px;
padding: 4px 5px 5px;
font-weight: 700;
@ -792,8 +791,7 @@ a.default:active {
max-width: 825px;
}
.loginPage > .registerCont > *,
.loginPage > .loginCont > * {
.loginPage > * {
text-align: center;
margin: 10px auto;
padding: 2px 3px;
@ -805,32 +803,9 @@ a.default:active {
}
@media (max-width: 430px) {
.loginPage > .registerCont > *,
.loginPage > .loginCont > * {
.loginPage > * {
width: 300px;
}
}
.loginPage > .loginCont {
float: left;
}
.loginPage > .registerCont {
float: right;
}
@media (max-width: 820px) {
.loginPage > .loginCont {
float: none;
}
.loginPage > .registerCont {
float: none;
}
}
.loginPage .head {

View file

@ -12,6 +12,9 @@ Router::get('/faq', 'Sakura\Controllers\Meta@faq', 'main.faq');
Router::get('/search', 'Sakura\Controllers\Meta@search', 'main.search');
Router::get('/p/{id}', 'Sakura\Controllers\Meta@infoPage', 'main.infopage');
// Auth
Router::get('/login', 'Sakura\Controllers\Auth@login', 'auth.login');
// News
Router::get('/news', 'Sakura\Controllers\Meta@news', 'news.index');
Router::get('/news/{category}', 'Sakura\Controllers\Meta@news', 'news.category');

View file

@ -59,6 +59,7 @@ require_once ROOT . 'libraries/Users.php';
require_once ROOT . 'libraries/Utils.php';
require_once ROOT . 'libraries/Whois.php';
require_once ROOT . 'libraries/Console/Application.php';
require_once ROOT . 'libraries/Controllers/Auth.php';
require_once ROOT . 'libraries/Controllers/Forums.php';
require_once ROOT . 'libraries/Controllers/Meta.php';
require_once ROOT . 'libraries/Controllers/User.php';

View file

@ -159,6 +159,7 @@
{% if sakura.lockAuth %}
<div class="menu-item fa-lock" style="padding-left: 10px; padding-right: 10px;" title="Authentication is locked"></div>
{% else %}
<a class="menu-item fa-magic" href="{{ urls.format('SITE_REGISTER') }}" title="Login"></a>
<a class="menu-item fa-sign-in" href="{{ urls.format('SITE_LOGIN') }}" title="Login"></a>
{% endif %}
{% endif %}

View file

@ -7,7 +7,6 @@
<h1 class="stylised" style="line-height: 1.8em; text-align: center;">Authentication is currently disallowed, try again later.</h1>
{% else %}
<div class="loginPage">
<div class="loginCont">
<div class="loginForm">
<div class="head">
Login to {{ sakura.siteName }}
@ -65,8 +64,6 @@
</div>
</form>
</div>
</div>
<div class="registerCont">
<div class="registerForm">
<div class="head">
Register on {{ sakura.siteName }}
@ -177,8 +174,6 @@
</form>
</div>
{% endif %}
</div>
<div class="clear"></div>
</div>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,41 @@
{% extends 'global/master.twig' %}
{% block title %}Authentication{% endblock %}
{% block content %}
{% if sakura.lockAuth %}
<h1 class="stylised" style="line-height: 1.8em; text-align: center;">Authentication is currently disallowed, try again later.</h1>
{% else %}
<div class="loginPage">
<div class="loginForm">
<div class="head">
Login to {{ sakura.siteName }}
</div>
<form method="post" action="{{ urls.format('AUTH_ACTION') }}" id="loginForm">
<input type="hidden" name="redirect" value="{{ auth.redirect }}" />
<input type="hidden" name="session" value="{{ php.sessionid }}" />
<input type="hidden" name="time" value="{{ php.time }}" />
<input type="hidden" name="mode" value="login" />
<div class="leftAlign">
<label for="loginUserName">Username:</label>
</div>
<div class="centreAlign">
<input class="inputStyling" type="text" id="loginUserName" name="username" autofocus="true" />
</div>
<div class="leftAlign">
<label for="loginPassword">Password:</label>
</div>
<div class="centreAlign">
<input class="inputStyling" type="password" id="loginPassword" name="password" />
</div>
<div class="subLinks centreAlign">
<input class="inputStyling" name="remember" type="checkbox" class="ignore-css" id="loginRemember" /><label for="loginRemember">Remember Me</a>
</div>
<div class="centreAlign">
<input class="inputStyling" type="submit" id="loginButton" name="submit" value="Login" />
</div>
</form>
</div>
</div>
{% endif %}
{% endblock %}