限制登录次数

时间:2016-10-13 13:32:20

标签: php login limit

我想根据设备的udid创建限制登录。例如,用户只能同时使用2个不同的设备登录。这就是我所做的,但在登录时无法锁定第三个用户

    // Get the email and password
$email       = CParam::paramPost('email');
$firstpassword    = CParam::paramPost('password');
$password    = md5(CParam::paramPost('password'));
$udid        = CParam::paramPost('udid');
$app_id      = CParam::paramPost('app_id');
$app_version = CParam::paramPost('app_version');

// Make sure we have a UDID
if (empty($udid)) {
    sendJsonError('UDID parameter is missing');
    return;
}

// Check if the user is entitled
$sql    = 'SELECT * FROM accounts WHERE email = :email AND password = :password';
$params = array('email' => $email, 'password' => $password);
$account   = $db->fetchOne($sql, $params);
if (!$account) {
    sendJsonError('We could not find your subscription.');
    return;
}

// The account was found, generate an successs token if not existing yet
if (empty($account['success_token'])) {
    $success_token = CGuid::create();
    $db->update(
        'accounts',
        array('success_token' => $success_token),
        'id = :id',
        array('id' => $account['id'])
    );
} else {
    $success_token = $account['success_token'];
}

// Register the device
$db->insertOrUpdate(
    'devices',
    array(
        'account_id'  => $account['id'],
        'udid'        => $udid,
        'app_id'      => $app_id,
        'app_version' => $app_version,
    )
);

由于

0 个答案:

没有答案
相关问题