Backend\Core\Engine\Api::getAPIKey PHP Method

getAPIKey() public static method

Get the API-key for a user.
public static getAPIKey ( string $email, string $password ) : array
$email string The emailaddress for the user.
$password string The password for the user.
return array
    public static function getAPIKey($email, $password)
    {
        trigger_error('The api is deprecated and will be removed in version 5', E_USER_DEPRECATED);
        $email = (string) $email;
        $password = (string) $password;
        // validate
        if ($email == '') {
            BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'No email-parameter provided.'));
        }
        if ($password == '') {
            BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'No password-parameter provided.'));
        }
        // load user
        try {
            $user = new User(null, $email);
        } catch (Exception $e) {
            BaseAPI::output(BaseAPI::FORBIDDEN, array('message' => 'Can\'t authenticate you.'));
        }
        // validate password
        if (!Authentication::loginUser($email, $password)) {
            BaseAPI::output(BaseAPI::FORBIDDEN, array('message' => 'Can\'t authenticate you.'));
        } else {
            // does the user have access?
            if ($user->getSetting('api_access', false) == false) {
                BaseAPI::output(BaseAPI::FORBIDDEN, array('message' => 'Your account isn\'t allowed to use the API. Contact an administrator.'));
            } else {
                // create the key if needed
                if ($user->getSetting('api_key', null) == null) {
                    $user->setSetting('api_key', uniqid('', true));
                }
                // return the key
                return array('api_key' => $user->getSetting('api_key'));
            }
        }
    }