git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

Commit 743c8440 authored by Zach Copley's avatar Zach Copley

Move all basic auth output and processing to base classes

parent f746993c
......@@ -46,27 +46,6 @@ require_once INSTALLDIR.'/lib/apibareauth.php';
class ApiAccountRateLimitStatusAction extends ApiBareAuthAction
{
/**
* Take arguments for running
*
* @param array $args $_REQUEST args
*
* @return boolean success flag
*
*/
function prepare($args)
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return false;
}
}
return true;
}
/**
* Handle the request
......
......@@ -47,27 +47,6 @@ require_once INSTALLDIR.'/lib/apiauth.php';
class ApiAccountVerifyCredentialsAction extends ApiAuthAction
{
/**
* Take arguments for running
*
* @param array $args $_REQUEST args
*
* @return boolean success flag
*
*/
function prepare($args)
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return false;
}
}
return true;
}
/**
* Handle the request
......
......@@ -63,12 +63,6 @@ class ApiBlockCreateAction extends ApiAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->user = $this->auth_user;
$this->other = $this->getTargetUser($this->arg('id'));
......
......@@ -62,12 +62,6 @@ class ApiBlockDestroyAction extends ApiAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->user = $this->auth_user;
$this->other = $this->getTargetUser($this->arg('id'));
......
......@@ -70,12 +70,6 @@ class ApiDirectMessageAction extends ApiAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->user = $this->auth_user;
if (empty($this->user)) {
......
......@@ -64,12 +64,6 @@ class ApiDirectMessageNewAction extends ApiAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->user = $this->auth_user;
if (empty($this->user)) {
......
......@@ -62,12 +62,6 @@ class ApiFavoriteCreateAction extends ApiAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->user = $this->auth_user;
$this->notice = Notice::staticGet($this->arg('id'));
......
......@@ -63,12 +63,6 @@ class ApiFavoriteDestroyAction extends ApiAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->user = $this->auth_user;
$this->notice = Notice::staticGet($this->arg('id'));
......
......@@ -63,12 +63,6 @@ class ApiFriendshipsCreateAction extends ApiAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->user = $this->auth_user;
$this->other = $this->getTargetUser($id);
......
......@@ -63,12 +63,6 @@ class ApiFriendshipsDestroyAction extends ApiAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->user = $this->auth_user;
$this->other = $this->getTargetUser($id);
......
......@@ -62,12 +62,6 @@ class ApiFriendshipsShowAction extends ApiBareAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$source_id = (int)$this->trimmed('source_id');
$source_screen_name = $this->trimmed('source_screen_name');
$target_id = (int)$this->trimmed('target_id');
......
......@@ -62,12 +62,6 @@ class ApiGroupIsMemberAction extends ApiBareAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->user = $this->getTargetUser(null);
$this->group = $this->getTargetGroup(null);
$this->format = $this->arg('format');
......
......@@ -62,12 +62,6 @@ class ApiGroupJoinAction extends ApiAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->user = $this->auth_user;
$this->group = $this->getTargetGroup($this->arg('id'));
......
......@@ -62,12 +62,6 @@ class ApiGroupLeaveAction extends ApiAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->user = $this->auth_user;
$this->group = $this->getTargetGroup($this->arg('id'));
......
......@@ -67,12 +67,6 @@ class ApiGroupListAction extends ApiBareAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->page = (int)$this->arg('page', 1);
$this->count = (int)$this->arg('count', 20);
$this->max_id = (int)$this->arg('max_id', 0);
......
......@@ -63,12 +63,6 @@ class ApiStatusesDestroyAction extends ApiAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return false;
}
}
$this->user = $this->auth_user;
$this->notice_id = (int)$this->trimmed('id');
......
......@@ -67,12 +67,6 @@ class ApiStatusesUpdateAction extends ApiAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return false;
}
}
$this->user = $this->auth_user;
if (empty($this->user)) {
......
......@@ -84,12 +84,6 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
$this->count = isset($this->ids_only) ?
5000 : (int)$this->arg('count', 100);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return false;
}
}
$this->user = $this->getTargetUser($this->arg('id'));
if (empty($this->user)) {
......
......@@ -69,12 +69,6 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
{
parent::prepare($args);
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->page = (int)$this->arg('page', 1);
$this->count = (int)$this->arg('count', 20);
$this->max_id = (int)$this->arg('max_id', 0);
......
......@@ -75,12 +75,6 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction
$this->since = $this->arg('since');
$this->format = $this->arg('format');
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->user = $this->getTargetUser($this->arg('id'));
if (empty($this->user)) {
......
......@@ -68,12 +68,6 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
$this->since_id = (int)$this->arg('since_id', 0);
$this->since = $this->arg('since');
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->user = $this->getTargetUser($this->arg('id'));
if (empty($this->user)) {
......
......@@ -70,12 +70,6 @@ class ApiTimelineUserAction extends ApiBareAuthAction
$this->since_id = (int)$this->arg('since_id', 0);
$this->since = $this->arg('since');
if ($this->requiresAuth()) {
if ($this->checkBasicAuthUser() == false) {
return;
}
}
$this->user = $this->getTargetUser($this->arg('id'));
if (empty($this->user)) {
......
......@@ -48,6 +48,26 @@ class ApiAuthAction extends ApiAction
var $auth_user = null;
/**
* Take arguments for running, and output basic auth header if needed
*
* @param array $args $_REQUEST args
*
* @return boolean success flag
*
*/
function prepare($args)
{
parent::prepare($args);
if ($this->requiresAuth()) {
$this->checkBasicAuthUser();
}
return true;
}
/**
* Does this API resource require authentication?
*
......@@ -76,7 +96,7 @@ class ApiAuthAction extends ApiAction
// show error if the user clicks 'cancel'
$this->showBasicAuthError();
return false;
exit;
} else {
$nickname = $this->auth_user;
......@@ -94,7 +114,7 @@ class ApiAuthAction extends ApiAction
"$nickname, proxy = $proxy, ip = $ip."
);
$this->showBasicAuthError();
return false;
exit;
}
}
return true;
......
......@@ -48,6 +48,22 @@ require_once INSTALLDIR.'/lib/apiauth.php';
class ApiBareAuthAction extends ApiAuthAction
{
/**
* Take arguments for running
*
* @param array $args $_REQUEST args
*
* @return boolean success flag
*
*/
function prepare($args)
{
parent::prepare($args);
return true;
}
/**
* Does this API resource require authentication?
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment