Move all basic auth output and processing to base classes

This commit is contained in:
Zach Copley 2009-10-09 16:57:22 -07:00
parent f746993c2b
commit 743c844084
24 changed files with 38 additions and 164 deletions

View File

@ -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

View File

@ -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

View File

@ -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'));

View File

@ -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'));

View File

@ -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)) {

View File

@ -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)) {

View File

@ -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'));

View File

@ -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'));

View File

@ -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);

View File

@ -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);

View File

@ -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');

View File

@ -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');

View File

@ -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'));

View File

@ -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'));

View File

@ -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);

View File

@ -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');

View File

@ -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)) {

View File

@ -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)) {

View File

@ -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);

View File

@ -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)) {

View File

@ -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)) {

View File

@ -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)) {

View File

@ -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;

View File

@ -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?
*