if ($addon_auth['authenticated'] && !empty($addon_auth['user_record'])) {
$record = $addon_auth['user_record'];
} else {
- $user_id = User::authenticate(trim($user), trim($password), true);
- if ($user_id !== false) {
+ try {
+ $user_id = User::getIdFromPasswordAuthentication(trim($user), trim($password), true);
$record = DBA::selectFirst('user', [], ['uid' => $user_id]);
+ } catch (Exception $ex) {
+ $record = [];
}
}
if (!DBA::isResult($record)) {
Logger::debug(API_LOG_PREFIX . 'failed', ['module' => 'api', 'action' => 'login', 'parameters' => $_SERVER]);
header('WWW-Authenticate: Basic realm="Friendica"');
- //header('HTTP/1.0 401 Unauthorized');
- //die('This api requires login');
throw new UnauthorizedException("This API requires login");
}
Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call', 'query' => DI::args()->getQueryString()]);
throw new NotFoundException();
} catch (HTTPException $e) {
- header("HTTP/1.1 {$e->getCode()} {$e->httpdesc}");
+ header("HTTP/1.1 {$e->getCode()} {$e->getDescription()}");
return api_error($type, $e, $args);
}
}
*/
function api_error($type, $e, App\Arguments $args)
{
- $error = ($e->getMessage() !== "" ? $e->getMessage() : $e->httpdesc);
+ $error = ($e->getMessage() !== "" ? $e->getMessage() : $e->getDescription());
/// @TODO: https://dev.twitter.com/overview/api/response-codes
$error = ["error" => $error,
- "code" => $e->getCode() . " " . $e->httpdesc,
+ "code" => $e->getCode() . " " . $e->getDescription(),
"request" => $args->getQueryString()];
$return = api_format_data('status', $type, ['status' => $error]);
// check max length of images on server
$max_length = DI::config()->get('system', 'max_image_length');
- if (!$max_length) {
- $max_length = MAX_IMAGE_LENGTH;
- }
if ($max_length > 0) {
$Image->scaleDown($max_length);
logger::info("File upload: Scaling picture to new size " . $max_length);
}
// delete group
- $ret = Group::removeByName($uid, $name);
+ $gid = Group::getIdByName($uid, $name);
+ if (empty($gid)) {
+ throw new BadRequestException('other API error');
+ }
+
+ $ret = Group::remove($gid);
+
if ($ret) {
// return success
$success = ['success' => $ret, 'gid' => $gid, 'name' => $name, 'status' => 'deleted', 'wrong users' => []];
$found = ($user['cid'] == $cid ? true : false);
}
if (!isset($found) || !$found) {
- Group::removeMemberByName($uid, $name, $cid);
+ $gid = Group::getIdByName($uid, $name);
+ Group::removeMember($gid, $cid);
}
}