summaryrefslogtreecommitdiff
path: root/moe
diff options
context:
space:
mode:
authorNeku <neku@pomf.se>2013-12-15 04:02:11 +0100
committerNeku <neku@pomf.se>2013-12-15 04:02:11 +0100
commita0544a9b609e0fa96d11ddbbe46c8e22d56ca1cc (patch)
treeeb266a7ba7fcccf5d487b11b98d3d685e388a159 /moe
parentb5fbd3e749fff7621ca2e0d7472a8f2627c2f32e (diff)
start of login/admin panel
Diffstat (limited to 'moe')
-rw-r--r--moe/api.php28
-rw-r--r--moe/core.php71
-rw-r--r--moe/settings.php22
3 files changed, 121 insertions, 0 deletions
diff --git a/moe/api.php b/moe/api.php
new file mode 100644
index 0000000..f9313f5
--- /dev/null
+++ b/moe/api.php
@@ -0,0 +1,28 @@
+<?php
+// This file will act as a APIish thing
+
+// Include core file
+require_once('core.php');
+
+// Decode incoming json
+$in = json_decode($_POST['in']);
+
+// Perform wanted function
+if($in['action']['0']=='register'){
+
+ // Check if reg is open
+ if(reg=='1'){
+
+ // Perform register function with data from json string
+ register($in['info']['0'], $in['info']['1'], $in['info']['2']);
+
+ }else{
+ // Re-direct to closed-reg info page?
+ $return = array('action' => 'closedreg');
+ json_encode($return);
+ }
+
+}elseif ($in['action']['0']=='login') {
+ login($in['info']['0'], $in['info']['1']);
+}
+?> \ No newline at end of file
diff --git a/moe/core.php b/moe/core.php
new file mode 100644
index 0000000..c2a5c67
--- /dev/null
+++ b/moe/core.php
@@ -0,0 +1,71 @@
+<?php
+// This file will handle all functions used by Pomf's Moe Panel
+
+// Include the settings file
+include_once('settings.php');
+
+// Setup new PDO connection
+$db = new PDO(db_conn, db_name, db_user, db_pass);
+
+// Login Function
+function login ($username, $password) {
+ global $db;
+
+ // Generate password hash
+ $hash = password_hash($password, PASSWORD_BCRYPT, bsettings)."\n";
+
+ // Check username and password
+ $do = $db->prepare("SELECT password FROM users WHERE username = (:user)");
+ $do->bindParam(':user', $username);
+ $do->execute();
+ $pass = $do->fetch();
+
+ // Check if hash is the same as the one in DB
+ if($pass['0']===$password){
+ // Return good result
+ $return = array('action' => 'cp', 'info' => 'Logged in.');
+ }else{
+ // Return bad result
+ $return = array('info' => 'Wrong username or password, try again.');
+ }
+ // Return result with JSON
+ json_encode($return);
+)
+
+// Registration function
+function register ($username, $password, $email) {
+ global $db;
+
+ // Check if username, email, etc exists
+ $do = $db->prepare("SELECT user,email FROM users WHERE username = (:user) OR email = (:email)");
+ $do->bindParam(':user', $username);
+ $do->bindParam(':email', $email);
+ $do->exeute();
+ $count = $do->rowCount();
+
+ // If already exists display mess, otherwise continue
+ if(!$count==='0'){
+ // Return result
+ $return = array('info' => 'User already exists.');
+ }else{
+ // Generate password hash
+ $hash = password_hash($password, PASSWORD_BCRYPT, bsettings)."\n";
+ // Register new user
+ $do = $db->prepare("INSERT INTO users (username, password, email, date) VALUES (:user, :pass, :email, :date)");
+ $do->bindParam(':user', $username);
+ $do->bindParam(':pass', $hash);
+ $do->bindParam(':email', $email);
+ $do->bindValue(':date', date('Y-m-d'));
+ $do->exeute();
+ // Return that user has been made and goto login
+ $return = array('action' => 'login', 'info' => 'User has been made, login.');
+ }
+ // Return JSON
+ json_encode($return);
+}
+
+function delete ($id, $delid) {
+ global $db;
+
+}
+?> \ No newline at end of file
diff --git a/moe/settings.php b/moe/settings.php
new file mode 100644
index 0000000..4c4277f
--- /dev/null
+++ b/moe/settings.php
@@ -0,0 +1,22 @@
+<?php
+//This file will include all settings
+
+// PDO connection
+define('db_conn', 'mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=');
+// PDO Database
+define('db_name', 'pomf')
+// PDO user
+define('db_user', 'xxx');
+// PDO password
+define('db_pass', 'xxx');
+
+// Install (if making an installer sometime?)
+//define('install', '0');
+// Maintenance
+define('maintenance', '0');
+// Registration open/closed
+define('reg', '1');
+
+// Bcrypt hash settings
+define('bsettings', array('cost' => 11));
+?> \ No newline at end of file