first pass at actions for initializing a network

This commit is contained in:
Evan Prodromou 2011-06-07 12:06:02 -04:00
parent 1b0bafc6cc
commit 59c980cea8
3 changed files with 255 additions and 0 deletions

View File

@ -196,6 +196,23 @@ class DomainStatusNetworkPlugin extends Plugin
return true;
}
static function userExists($email)
{
$domain = self::toDomain($email);
$sn = self::siteForDomain($domain);
if (empty($sn)) {
return false;
}
StatusNet::switchSite($sn->nickname);
$user = User::staticGet('email', $email);
return !empty($user);
}
static function registerEmail($email, $sendWelcome, $template)
{
$domain = self::toDomain($email);
@ -221,6 +238,50 @@ class DomainStatusNetworkPlugin extends Plugin
return $confirm;
}
static function login($email, $password)
{
$domain = self::toDomain($email);
$sn = self::siteForDomain($domain);
if (empty($sn)) {
throw new ClientException(_("No such site."));
}
StatusNet::switchSite($sn->nickname);
$user = common_check_user($email, $password);
if (empty($user)) {
// TRANS: Form validation error displayed when trying to log in with incorrect credentials.
throw new ClientException(_('Incorrect username or password.'));
}
$loginToken = Login_token::makeNew($user);
if (empty($loginToken)) {
throw new ServerException(_('Cannot log in.'));
}
$url = common_local_url('otp', array('user_id' => $loginToken->user_id,
'token' => $loginToken->token));
return $url;
}
static function recoverPassword($email)
{
$domain = self::toDomain($email);
$sn = self::siteForDomain($domain);
if (empty($sn)) {
throw new NoSuchUserException(array('email' => $email));
}
StatusNet::switchSite($sn->nickname);
}
// The way addPlugin() works, this global variable gets disappeared.

View File

@ -0,0 +1,76 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* Log into a site globally
*
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category DomainStatusNetwork
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
/**
* Class comment
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
class GlobalLoginAction extends Action
{
/**
* For initializing members of the class.
*
* @param array $argarray misc. arguments
*
* @return boolean true
*/
function prepare($argarray)
{
parent::prepare($argarray);
return true;
}
/**
* Handler method
*
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void
*/
function handle($argarray=null)
{
return;
}
}

View File

@ -0,0 +1,118 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* Register a user to a site by their email address
*
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category DomainStatusNetwork
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
/**
* Class comment
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
class GlobalRegisterAction extends Action
{
/**
* For initializing members of the class.
*
* @param array $argarray misc. arguments
*
* @return boolean true
*/
function prepare($argarray)
{
parent::prepare($argarray);
return true;
}
/**
* Handler method
*
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void
*/
function handle($argarray=null)
{
return;
}
/**
* Return true if read only.
*
* MAY override
*
* @param array $args other arguments
*
* @return boolean is read only action?
*/
function isReadOnly($args)
{
return false;
}
/**
* Return last modified, if applicable.
*
* MAY override
*
* @return string last modified http header
*/
function lastModified()
{
// For comparison with If-Last-Modified
// If not applicable, return null
return null;
}
/**
* Return etag, if applicable.
*
* MAY override
*
* @return string etag http header
*/
function etag()
{
return null;
}
}