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 | |
| parent | a0544a9b609e0fa96d11ddbbe46c8e22d56ca1cc (diff) | |
some changes
| -rw-r--r-- | moe/api.php | 28 | ||||
| -rw-r--r-- | moe/core.php | 71 | ||||
| -rw-r--r-- | moe/css/style.css | 179 | ||||
| -rw-r--r-- | moe/includes/api.php | 23 | ||||
| -rw-r--r-- | moe/includes/core.php | 36 | ||||
| -rw-r--r-- | moe/login/index.html | 48 | ||||
| -rw-r--r-- | moe/register/index.html | 45 | ||||
| -rw-r--r-- | moe/settings.php | 22 |
8 files changed, 331 insertions, 121 deletions
diff --git a/moe/api.php b/moe/api.php deleted file mode 100644 index f9313f5..0000000 --- a/moe/api.php +++ /dev/null @@ -1,28 +0,0 @@ -<?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 deleted file mode 100644 index c2a5c67..0000000 --- a/moe/core.php +++ /dev/null @@ -1,71 +0,0 @@ -<?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/css/style.css b/moe/css/style.css new file mode 100644 index 0000000..2ee2921 --- /dev/null +++ b/moe/css/style.css @@ -0,0 +1,179 @@ +@charset "utf-8"; +/* CSS Document */ + +/* ---------- GENERAL ---------- */ + +body { + background: #eaeaea; + color: #999; + font: 100%/1.5em sans-serif; + margin: 0; +} + +h3 { margin: 0; } + +a { + color: #999; + text-decoration: none; +} + +a:hover { color: #1dabb8; } + +fieldset { + border: none; + margin: 0; +} + +input { + border: none; + font-family: inherit; + font-size: inherit; + margin: 0; + -webkit-appearance: none; +} + +input:focus { + outline: none; +} + +input[type="submit"] { cursor: pointer; } + +.clearfix { *zoom: 1; } +.clearfix:before, .clearfix:after { + content: ""; + display: table; +} +.clearfix:after { clear: both; } + +/* ---------- LOGIN-FORM ---------- */ + +#login-form { + margin: 50px auto; + width: 300px; +} + +#login-form h3 { + background-color: #282830; + border-radius: 5px 5px 0 0; + color: #fff; + font-size: 14px; + padding: 20px; + text-align: center; + text-transform: uppercase; +} + +#login-form fieldset { + background: #fff; + border-radius: 0 0 5px 5px; + padding: 20px; + position: relative; +} + +#login-form fieldset:before { + background-color: #fff; + content: ""; + height: 8px; + left: 50%; + margin: -4px 0 0 -4px; + position: absolute; + top: 0; + -webkit-transform: rotate(45deg); + -moz-transform: rotate(45deg); + -ms-transform: rotate(45deg); + -o-transform: rotate(45deg); + transform: rotate(45deg); + width: 8px; +} + +#login-form input { + font-size: 14px; +} + +#login-form input[type="email"], +#login-form input[type="password"] { + border: 1px solid #dcdcdc; + padding: 12px 10px; + width: 238px; +} + +#login-form input[type="email"] { + border-radius: 3px 3px 0 0; +} + +#login-form input[type="password"] { + border-top: none; + border-radius: 0px 0px 3px 3px; +} + +#login-form input[type="submit"] { + background: #1dabb8; + border-radius: 3px; + color: #fff; + float: right; + font-weight: bold; + margin-top: 20px; + padding: 12px 20px; +} + +#login-form input[type="submit"]:hover { background: #198d98; } + +#login-form footer { + font-size: 12px; + margin-top: 16px; +} + +.info { + background: #e5e5e5; + border-radius: 50%; + display: inline-block; + height: 20px; + line-height: 20px; + margin: 0 10px 0 0; + text-align: center; + width: 20px; +} + +#fail { +display: none; +} +#fail:target { +display: block; +} + +#fail:target { + margin: 50px auto; + width: 300px; +} + +#fail:target h3 { + background-color: #282830; + border-radius: 5px 5px 0 0; + color: #fff; + font-size: 14px; + padding: 20px; + text-align: center; + text-transform: uppercase; +} + +#fail:target fieldset { + background: #fff; + border-radius: 0 0 5px 5px; + padding: 20px; + position: relative; +} + +#fail:target fieldset:before { + background-color: #fff; + content: ""; + height: 8px; + left: 50%; + margin: -4px 0 0 -4px; + position: absolute; + top: 0; + -webkit-transform: rotate(45deg); + -moz-transform: rotate(45deg); + -ms-transform: rotate(45deg); + -o-transform: rotate(45deg); + transform: rotate(45deg); + width: 8px; +}
\ No newline at end of file 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 diff --git a/moe/login/index.html b/moe/login/index.html new file mode 100644 index 0000000..fc3f767 --- /dev/null +++ b/moe/login/index.html @@ -0,0 +1,48 @@ + <html lang="en-US"> +<head> + <link rel="stylesheet" type="text/css" href="../css/style.css" media="screen" /> + <meta charset="utf-8"> + + <title>Moe Login</title> + + <!--[if lt IE 9]> + <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> + <![endif]--> + +</head> + +<body> + + <div id="login-form"> + + <h3>Login</h3> + + <fieldset> + + <form action="../includes/api.php?do=login" method="post"> + + <input type="Email" name="email" required value="Email" onBlur="if(this.value=='')this.value='Email'" onFocus="if(this.value=='Email')this.value='' "> <!-- JS because of IE support; better: placeholder="Email" --> + <input type="password" name="pass" required value="pass" onBlur="if(this.value=='')this.value='pass'" onFocus="if(this.value=='pass')this.value='' "> <!-- JS because of IE support; better: placeholder="Password" --> + + <input type="submit" value="Login"> + + <footer class="clearfix"> + + <p><span class="info">?</span><a href="#">Forgot Password</a></p> + <p><span class="info">?</span><a href="../register">Register</a></p> + + </footer> + + </form> + + </fieldset> + + </div> <!-- end login-form --> +<div id="fail"> + <h3>Wrong email or password</h3> + <fieldset> + <p>You have entered the wrong email or password, or something else went wrong.</p> + </fieldset> + </div> +</body> +</html>
\ No newline at end of file diff --git a/moe/register/index.html b/moe/register/index.html new file mode 100644 index 0000000..6396878 --- /dev/null +++ b/moe/register/index.html @@ -0,0 +1,45 @@ + <html> +<head> + <link rel="stylesheet" type="text/css" href="../css/style.css" media="screen" /> + <meta charset="utf-8"> + + <title>Moe Register</title> + + <!--[if lt IE 9]> + <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> + <![endif]--> + +</head> + +<body> + + <div id="login-form"> + + <h3>Register</h3> + + <fieldset> + + <form action="../includes/api.php?do=register" method="post"> + + <input type="Email" name="email" required value="Email" onBlur="if(this.value=='')this.value='Email'" onFocus="if(this.value=='Email')this.value='' "> <!-- JS because of IE support; better: placeholder="Email" --> + <input type="password" name="pass" required value="pass" onBlur="if(this.value=='')this.value='pass'" onFocus="if(this.value=='pass')this.value='' "> <!-- JS because of IE support; better: placeholder="Password" --> + + <input type="submit" value="Register"> + + <footer class="clearfix"> + <p><span class="info">?</span><a href="../login">Login</a></p> + </footer> + + </form> + + </fieldset> + + </div> <!-- end login-form --> +<div id="fail"> + <h3>Email in use</h3> + <fieldset> + <p>This email is already in use, choose another one or login to your existing account.</p> + </fieldset> + </div> +</body> +</html>
\ No newline at end of file diff --git a/moe/settings.php b/moe/settings.php deleted file mode 100644 index 4c4277f..0000000 --- a/moe/settings.php +++ /dev/null @@ -1,22 +0,0 @@ -<?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 |
