예제 #1
0
function testLogin($arr)
{
    $email = $arr["username"];
    $password = $arr["password"];
    $testformat = new testFormat();
    if ($testformat->testLogin($email, $password)) {
        $user = UserAction::login($email, $password);
        if (!($user === UserAction::$LOGIN_FAIL)) {
            $_SESSION['user'] = $user;
            $result = new Response(true, "");
            return $result;
        } else {
            $result = new Response(false, "错误的账号/密码");
            return $result;
        }
    } else {
        $result = new Response(false, "错误的格式,请按照相应格式输入");
        return $result;
    }
}
예제 #2
0
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/7/16
 * Time: 11:29
 */
header("Content-Type: text/html; charset=utf-8");
require_once "../entity/User.php";
require_once "../config.php";
require_once "../provider/Database.php";
require_once "../action/UserAction.php";
require_once "../provider/testFormat.php";
require_once "response/LoginResponse.php";
session_start();
$arr = $_POST;
$email = $arr["username"];
$password = $arr["password"];
$format = new testFormat();
$result = NULL;
if ($format->testLogin($email, $password)) {
    $user = UserAction::login($email, $password);
    if ($user instanceof User) {
        $_SESSION['user'] = $user;
        $result = new LoginResponse(true, "", $user->userId, $user->username, $user->nickname);
    } else {
        $result = new LoginResponse(false, "用户名密码不匹配");
    }
} else {
    $result = new LoginResponse(false, "输入格式有误");
}
echo json_encode($result);