blessing-skin-server/ajax.php
2016-01-17 00:19:10 +08:00

60 lines
1.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @Author: printempw
* @Date: 2016-01-16 23:01:33
* @Last Modified by: prpr
* @Last Modified time: 2016-01-17 00:17:39
*
* All ajax requests will be handled here
*/
header('Access-Control-Allow-Origin*');
session_start();
function __autoload($classname) {
$filename = "./includes/". $classname .".class.php";
include_once($filename);
}
$user = new user($_POST['uname']);
$action = $_GET['action'];
$json = null;
function checkPost() {
global $json;
if (!$_POST['uname']) {
$json['errno'] = 1;
$json['msg'] = 'Empty username!';
return false;
} else if (!$_POST['passwd']) {
$json['errno'] = 1;
$json['msg'] = "Empty password!";
return false;
}
return true;
}
if ($action == "login") {
if (checkPost()) {
if (!$user -> is_registered) {
$json['errno'] = 1;
$json['msg'] = "Non-existent user.";
} else {
if ($user -> checkPasswd($_POST['passwd'])) {
$json['errno'] = 0;
$json['msg'] = 'Logging in succeed!';
$json['token'] = $user -> getToken();
} else {
$json['errno'] = 1;
$json['msg'] = "Incorrect usename or password.";
}
}
}
} elseif ($action == "register") {
} elseif ($action == "register") {
}
echo json_encode($json);