From 3b38696c0ae126301f2a8c359bf5ed23df91439c Mon Sep 17 00:00:00 2001 From: flashwave Date: Sat, 18 Apr 2015 11:35:16 +0000 Subject: [PATCH] Sock Chat auth file --- _developer_data/Sakura.php | 83 +++++++++++++++++-- _sakura/sakura.php | 5 +- _sakura/templates/yuuno/global/header.tpl | 12 +-- _sakura/templates/yuuno/main/index.tpl | 19 ++++- .../yuuno/main/legacypasswordchange.tpl | 29 +++++++ content/.htaccess | 78 ++++++++--------- content/data/yuuno/css/yuuno.css | 20 +++-- content/index.php | 2 - main/authenticate.php | 9 ++ 9 files changed, 195 insertions(+), 62 deletions(-) create mode 100644 _sakura/templates/yuuno/main/legacypasswordchange.tpl delete mode 100644 content/index.php diff --git a/_developer_data/Sakura.php b/_developer_data/Sakura.php index e0f8869..4b2d411 100644 --- a/_developer_data/Sakura.php +++ b/_developer_data/Sakura.php @@ -13,14 +13,16 @@ $sockSakuraPath = ''; // Filesystem path to the _sakura folder WITHOUT an ending require_once $sockSakuraPath .'/sakura.php'; use sockchat\Auth; +use Sakura\Session; +use Sakura\Users; if(Auth::getPageType() == AUTH_FETCH) { // Check if user is logged into the Sakura backend if not deny - if(/* Login check */) { + if(Users::checkLogin()) { // If so append the required arguments and accept - Auth::AppendArguments([/* User ID */, /* Session ID */]); + Auth::AppendArguments([Session::$userId, Session::$sessionId]); Auth::Accept(); } else @@ -28,15 +30,84 @@ if(Auth::getPageType() == AUTH_FETCH) { } else { + // Get arguments + $uid = $_GET['arg1']; + $sid = $_GET['arg2']; + // Check if session is active else deny - if(/* Check if session is active */) { + if(Session::checkSession($uid, $sid)) { + + // Get user and rank data + $user = Users::getUser($uid); + $rank = Users::getRank($user['rank_main']); + + // Deny group and user id 0 + if($user['id'] == 0 || $rank['id'] == 0) { + + Auth::Deny(); + Auth::Serve(); + exit; + + } Auth::SetUserData( - /* User ID */, - /* Username */, - /* User colour */ + $user['id'], + $user['username'], + $rank['colour'] ); + switch($rank['id']) { + + default: // Fallback + case 2: // Regular User + Auth::SetCommonPermissions( + 0, + USER_NORMAL, + LOGS_DISABLED, + NICK_DISABLED, + CHANNEL_CREATE_DISABLED + ); + break; + + case 6: // Bot + case 8: // Tenshi + case 9: // Alumni + Auth::SetCommonPermissions( + 1, + USER_NORMAL, + LOGS_ENABLED, + NICK_ENABLED, + CHANNEL_CREATE_TEMP + ); + break; + + case 3: // Site Moderator + case 5: // Developer + case 6: // Chat Moderator + Auth::SetCommonPermissions( + ($rank['id'] == 2 ? 3 : 2), // Site moderators are 3, rest is 2 + USER_MODERATOR, + LOGS_ENABLED, + NICK_ENABLED, + CHANNEL_CREATE_TEMP + ); + break; + + case 4: // Administrator + Auth::SetCommonPermissions( + 4, + USER_MODERATOR, + LOGS_ENABLED, + NICK_ENABLED, + CHANNEL_CREATE_PERM + ); + break; + + + } + + Auth::Accept(); + } else Auth::Deny(); diff --git a/_sakura/sakura.php b/_sakura/sakura.php index 70ba4ae..993e8ec 100644 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -63,6 +63,9 @@ $renderData = array( 'time' => \time() ], 'user' => [ - 'checklogin' => Users::checkLogin() + 'checklogin' => Users::checkLogin(), + 'session' => Session::$sessionId, + 'data' => ($_init_udata = Users::getUser(Session::$userId)), + 'rank' => Users::getRank($_init_udata['rank_main']) ] ); diff --git a/_sakura/templates/yuuno/global/header.tpl b/_sakura/templates/yuuno/global/header.tpl index 064d67d..86105aa 100644 --- a/_sakura/templates/yuuno/global/header.tpl +++ b/_sakura/templates/yuuno/global/header.tpl @@ -50,16 +50,18 @@