diff options
| author | Neku <neku@pomf.se> | 2013-12-15 10:17:54 +0100 |
|---|---|---|
| committer | Neku <neku@pomf.se> | 2013-12-15 10:17:54 +0100 |
| commit | ca784b878869279c95deaaadb754f17646e172dc (patch) | |
| tree | cc3194868d76c968203924d4d3a7bcbd07ceac78 /moe/includes | |
| parent | a0544a9b609e0fa96d11ddbbe46c8e22d56ca1cc (diff) | |
some changes
Diffstat (limited to 'moe/includes')
| -rw-r--r-- | moe/includes/api.php | 23 | ||||
| -rw-r--r-- | moe/includes/core.php | 36 |
2 files changed, 59 insertions, 0 deletions
diff --git a/moe/includes/api.php b/moe/includes/api.php new file mode 100644 index 0000000..da0d652 --- /dev/null +++ b/moe/includes/api.php @@ -0,0 +1,23 @@ +<?php +// This file will act as a APIish thing +// Include core file +require_once('core.php'); + +if(isset($_GET['do'])){ + + $butt = $_GET['do']; + + switch($butt){ + + case "login": + login($_POST['email'], $_POST['pass']); + break; + + case "register": + register($_POST['email'], $_POST['pass']); + break; + + default: echo "We could call this a 404 not found... Or what are you doing here?"; + } +} +?>
\ No newline at end of file diff --git a/moe/includes/core.php b/moe/includes/core.php new file mode 100644 index 0000000..59d6d4e --- /dev/null +++ b/moe/includes/core.php @@ -0,0 +1,36 @@ +<?php +// This file will handle all functions used by Pomf's Moe Panel +$db = new PDO('mysql:host=127.0.0.1;port=3307;dbname=pomf', 'xxx', 'xxx', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'")); + +function register ($email, $pass) { + global $db; + $do = $db->prepare("SELECT email FROM accounts WHERE email = (:email)"); + $do->bindParam(':email', $email); + $do->execute(); + $result = $do->fetch(); + if($result['email'] === $email){ + header('Location: ../register/index.html#fail'); + }else{ + $do = $db->prepare("INSERT INTO accounts (email, pass) VALUES (:email, :pass)"); + $do->bindParam(':email', $email); + $hash = password_hash($pass, PASSWORD_DEFAULT); + $do->bindParam(':pass', $hash); + $do->execute(); + header('Location: api.php?do=cp'); + } +} + +function login ($email, $pass) { + global $db; + $do = $db->prepare("SELECT pass FROM accounts WHERE email = (:email)"); + $do->bindParam(':email', $email); + $do->execute(); + $result = $do->fetch(PDO::FETCH_ASSOC); + + if (password_verify($pass, $result['pass'])) { + header('Location: api.php?do=cp'); + }else{ + header('Location: ../login/index.html#fail'); + } +} +?>
\ No newline at end of file |
