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

Commit 14b46e21 authored by Jeffery To's avatar Jeffery To

Added configuration option to only allow OpenID logins.

If $config['site']['openidonly'] is set to true:
* the Login/Register pages will be removed from the navigation;
* directly accesses to the Login/Register pages will redirect to the
  OpenID login page;
* most links to the Login/Register pages will link to the OpenID login
  page instead.

The user will still need to set a password to access the API and RSS
feeds.
parent c1b19929
...@@ -940,6 +940,8 @@ closed: If set to 'true', will disallow registration on your site. ...@@ -940,6 +940,8 @@ closed: If set to 'true', will disallow registration on your site.
the service, *then* set this variable to 'true'. the service, *then* set this variable to 'true'.
inviteonly: If set to 'true', will only allow registration if the user inviteonly: If set to 'true', will only allow registration if the user
was invited by an existing user. was invited by an existing user.
openidonly: If set to 'true', will only allow registrations and logins
through OpenID.
private: If set to 'true', anonymous users will be redirected to the private: If set to 'true', anonymous users will be redirected to the
'login' page. Also, API methods that normally require no 'login' page. Also, API methods that normally require no
authentication will require it. Note that this does not turn authentication will require it. Note that this does not turn
......
...@@ -88,7 +88,9 @@ class AllAction extends ProfileAction ...@@ -88,7 +88,9 @@ class AllAction extends ProfileAction
} }
} }
else { else {
$message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to his or her attention.'), $this->user->nickname); $message .= sprintf(_('Why not [register an account](%%%%action.%s%%%%) and then nudge %s or post a notice to his or her attention.'),
(!common_config('site','openidonly')) ? 'register' : 'openidlogin',
$this->user->nickname);
} }
$this->elementStart('div', 'guide'); $this->elementStart('div', 'guide');
......
...@@ -67,7 +67,11 @@ class ConfirmaddressAction extends Action ...@@ -67,7 +67,11 @@ class ConfirmaddressAction extends Action
parent::handle($args); parent::handle($args);
if (!common_logged_in()) { if (!common_logged_in()) {
common_set_returnto($this->selfUrl()); common_set_returnto($this->selfUrl());
common_redirect(common_local_url('login')); if (!common_config('site', 'openidonly')) {
common_redirect(common_local_url('login'));
} else {
common_redirect(common_local_url('openidlogin'));
}
return; return;
} }
$code = $this->trimmed('code'); $code = $this->trimmed('code');
......
...@@ -153,7 +153,8 @@ class FavoritedAction extends Action ...@@ -153,7 +153,8 @@ class FavoritedAction extends Action
$message .= _('Be the first to add a notice to your favorites by clicking the fave button next to any notice you like.'); $message .= _('Be the first to add a notice to your favorites by clicking the fave button next to any notice you like.');
} }
else { else {
$message .= _('Why not [register an account](%%action.register%%) and be the first to add a notice to your favorites!'); $message .= sprintf(_('Why not [register an account](%%%%action.%s%%%%) and be the first to add a notice to your favorites!'),
(!common_config('site','openidonly')) ? 'register' : 'openidlogin');
} }
$this->elementStart('div', 'guide'); $this->elementStart('div', 'guide');
......
...@@ -82,7 +82,8 @@ class GroupsearchAction extends SearchAction ...@@ -82,7 +82,8 @@ class GroupsearchAction extends SearchAction
$message = _('If you can\'t find the group you\'re looking for, you can [create it](%%action.newgroup%%) yourself.'); $message = _('If you can\'t find the group you\'re looking for, you can [create it](%%action.newgroup%%) yourself.');
} }
else { else {
$message = _('Why not [register an account](%%action.register%%) and [create the group](%%action.newgroup%%) yourself!'); $message = sprintf(_('Why not [register an account](%%%%action.%s%%%%) and [create the group](%%%%action.newgroup%%%%) yourself!'),
(!common_config('site','openidonly')) ? 'register' : 'openidlogin');
} }
$this->elementStart('div', 'guide'); $this->elementStart('div', 'guide');
$this->raw(common_markup_to_html($message)); $this->raw(common_markup_to_html($message));
......
...@@ -235,7 +235,7 @@ class InviteAction extends CurrentUserDesignAction ...@@ -235,7 +235,7 @@ class InviteAction extends CurrentUserDesignAction
common_root_url(), common_root_url(),
$personal, $personal,
common_local_url('showstream', array('nickname' => $user->nickname)), common_local_url('showstream', array('nickname' => $user->nickname)),
common_local_url('register', array('code' => $invite->code))); common_local_url((!common_config('site', 'openidonly')) ? 'register' : 'openidlogin', array('code' => $invite->code)));
mail_send($recipients, $headers, $body); mail_send($recipients, $headers, $body);
} }
......
...@@ -65,6 +65,8 @@ class LoginAction extends Action ...@@ -65,6 +65,8 @@ class LoginAction extends Action
* *
* Switches on request method; either shows the form or handles its input. * Switches on request method; either shows the form or handles its input.
* *
* Checks if only OpenID is allowed and redirects to openidlogin if so.
*
* @param array $args $_REQUEST data * @param array $args $_REQUEST data
* *
* @return void * @return void
...@@ -73,7 +75,9 @@ class LoginAction extends Action ...@@ -73,7 +75,9 @@ class LoginAction extends Action
function handle($args) function handle($args)
{ {
parent::handle($args); parent::handle($args);
if (common_is_real_login()) { if (common_config('site', 'openidonly')) {
common_redirect(common_local_url('openidlogin'));
} else if (common_is_real_login()) {
$this->clientError(_('Already logged in.')); $this->clientError(_('Already logged in.'));
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') { } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->checkLogin(); $this->checkLogin();
......
...@@ -121,7 +121,9 @@ class NoticesearchAction extends SearchAction ...@@ -121,7 +121,9 @@ class NoticesearchAction extends SearchAction
$message = sprintf(_('Be the first to [post on this topic](%%%%action.newnotice%%%%?status_textarea=%s)!'), urlencode($q)); $message = sprintf(_('Be the first to [post on this topic](%%%%action.newnotice%%%%?status_textarea=%s)!'), urlencode($q));
} }
else { else {
$message = sprintf(_('Why not [register an account](%%%%action.register%%%%) and be the first to [post on this topic](%%%%action.newnotice%%%%?status_textarea=%s)!'), urlencode($q)); $message = sprintf(_('Why not [register an account](%%%%action.%s%%%%) and be the first to [post on this topic](%%%%action.newnotice%%%%?status_textarea=%s)!'),
(!common_config('site','openidonly')) ? 'register' : 'openidlogin',
urlencode($q));
} }
$this->elementStart('div', 'guide'); $this->elementStart('div', 'guide');
......
...@@ -183,7 +183,8 @@ class PublicAction extends Action ...@@ -183,7 +183,8 @@ class PublicAction extends Action
} }
else { else {
if (! (common_config('site','closed') || common_config('site','inviteonly'))) { if (! (common_config('site','closed') || common_config('site','inviteonly'))) {
$message .= _('Why not [register an account](%%action.register%%) and be the first to post!'); $message .= sprintf(_('Why not [register an account](%%%%action.%s%%%%) and be the first to post!'),
(!common_config('site','openidonly')) ? 'register' : 'openidlogin');
} }
} }
...@@ -238,9 +239,11 @@ class PublicAction extends Action ...@@ -238,9 +239,11 @@ class PublicAction extends Action
function showAnonymousMessage() function showAnonymousMessage()
{ {
if (! (common_config('site','closed') || common_config('site','inviteonly'))) { if (! (common_config('site','closed') || common_config('site','inviteonly'))) {
$m = _('This is %%site.name%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' . $m = sprintf(_('This is %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
'based on the Free Software [Laconica](http://laconi.ca/) tool. ' . 'based on the Free Software [Laconica](http://laconi.ca/) tool. ' .
'[Join now](%%action.register%%) to share notices about yourself with friends, family, and colleagues! ([Read more](%%doc.help%%))'); '[Join now](%%%%action.%s%%%%) to share notices about yourself with friends, family, and colleagues! ' .
'([Read more](%%%%doc.help%%%%))'),
(!common_config('site','openidonly')) ? 'register' : 'openidlogin');
} else { } else {
$m = _('This is %%site.name%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' . $m = _('This is %%site.name%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
'based on the Free Software [Laconica](http://laconi.ca/) tool.'); 'based on the Free Software [Laconica](http://laconi.ca/) tool.');
......
...@@ -72,7 +72,8 @@ class PublictagcloudAction extends Action ...@@ -72,7 +72,8 @@ class PublictagcloudAction extends Action
$message .= _('Be the first to post one!'); $message .= _('Be the first to post one!');
} }
else { else {
$message .= _('Why not [register an account](%%action.register%%) and be the first to post one!'); $message .= sprintf(_('Why not [register an account](%%%%action.%s%%%%) and be the first to post one!'),
(!common_config('site','openidonly')) ? 'register' : 'openidlogin');
} }
$this->elementStart('div', 'guide'); $this->elementStart('div', 'guide');
......
...@@ -116,6 +116,8 @@ class RegisterAction extends Action ...@@ -116,6 +116,8 @@ class RegisterAction extends Action
* *
* Checks if registration is closed and shows an error if so. * Checks if registration is closed and shows an error if so.
* *
* Checks if only OpenID is allowed and redirects to openidlogin if so.
*
* @param array $args $_REQUEST data * @param array $args $_REQUEST data
* *
* @return void * @return void
...@@ -127,6 +129,8 @@ class RegisterAction extends Action ...@@ -127,6 +129,8 @@ class RegisterAction extends Action
if (common_config('site', 'closed')) { if (common_config('site', 'closed')) {
$this->clientError(_('Registration not allowed.')); $this->clientError(_('Registration not allowed.'));
} else if (common_config('site', 'openidonly')) {
common_redirect(common_local_url('openidlogin'));
} else if (common_logged_in()) { } else if (common_logged_in()) {
$this->clientError(_('Already logged in.')); $this->clientError(_('Already logged in.'));
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') { } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
......
...@@ -71,11 +71,13 @@ class RemotesubscribeAction extends Action ...@@ -71,11 +71,13 @@ class RemotesubscribeAction extends Action
if ($this->err) { if ($this->err) {
$this->element('div', 'error', $this->err); $this->element('div', 'error', $this->err);
} else { } else {
$inst = _('To subscribe, you can [login](%%action.login%%),' . $inst = sprintf(_('To subscribe, you can [login](%%%%action.%s%%%%),' .
' or [register](%%action.register%%) a new ' . ' or [register](%%%%action.%s%%%%) a new ' .
' account. If you already have an account ' . ' account. If you already have an account ' .
' on a [compatible microblogging site](%%doc.openmublog%%), ' . ' on a [compatible microblogging site](%%doc.openmublog%%), ' .
' enter your profile URL below.'); ' enter your profile URL below.'),
(!common_config('site','openidonly')) ? 'login' : 'openidlogin',
(!common_config('site','openidonly')) ? 'register' : 'openidlogin');
$output = common_markup_to_html($inst); $output = common_markup_to_html($inst);
$this->elementStart('div', 'instructions'); $this->elementStart('div', 'instructions');
$this->raw($output); $this->raw($output);
......
...@@ -187,7 +187,9 @@ class RepliesAction extends OwnerDesignAction ...@@ -187,7 +187,9 @@ class RepliesAction extends OwnerDesignAction
} }
} }
else { else {
$message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to his or her attention.'), $this->user->nickname); $message .= sprintf(_('Why not [register an account](%%%%action.%s%%%%) and then nudge %s or post a notice to his or her attention.'),
(!common_config('site','openidonly')) ? 'register' : 'openidlogin',
$this->user->nickname);
} }
$this->elementStart('div', 'guide'); $this->elementStart('div', 'guide');
......
...@@ -173,7 +173,9 @@ class ShowfavoritesAction extends OwnerDesignAction ...@@ -173,7 +173,9 @@ class ShowfavoritesAction extends OwnerDesignAction
} }
} }
else { else {
$message = sprintf(_('%s hasn\'t added any notices to his favorites yet. Why not [register an account](%%%%action.register%%%%) and then post something interesting they would add to their favorites :)'), $this->user->nickname); $message = sprintf(_('%s hasn\'t added any notices to his favorites yet. Why not [register an account](%%%%action.%s%%%%) and then post something interesting they would add to their favorites :)'),
$this->user->nickname,
(!common_config('site','openidonly')) ? 'register' : 'openidlogin');
} }
$this->elementStart('div', 'guide'); $this->elementStart('div', 'guide');
......
...@@ -440,8 +440,9 @@ class ShowgroupAction extends GroupDesignAction ...@@ -440,8 +440,9 @@ class ShowgroupAction extends GroupDesignAction
$m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' . $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' . 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
'short messages about their life and interests. '. 'short messages about their life and interests. '.
'[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'), '[Join now](%%%%action.%s%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
$this->group->nickname); $this->group->nickname,
(!common_config('site','openidonly')) ? 'register' : 'openidlogin');
} else { } else {
$m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' . $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' . 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
......
...@@ -358,7 +358,9 @@ class ShowstreamAction extends ProfileAction ...@@ -358,7 +358,9 @@ class ShowstreamAction extends ProfileAction
} }
} }
else { else {
$message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to his or her attention.'), $this->user->nickname); $message .= sprintf(_('Why not [register an account](%%%%action.%s%%%%) and then nudge %s or post a notice to his or her attention.'),
(!common_config('site','openidonly')) ? 'register' : 'openidlogin',
$this->user->nickname);
} }
$this->elementStart('div', 'guide'); $this->elementStart('div', 'guide');
...@@ -387,8 +389,10 @@ class ShowstreamAction extends ProfileAction ...@@ -387,8 +389,10 @@ class ShowstreamAction extends ProfileAction
if (!(common_config('site','closed') || common_config('site','inviteonly'))) { if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
$m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' . $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
'based on the Free Software [Laconica](http://laconi.ca/) tool. ' . 'based on the Free Software [Laconica](http://laconi.ca/) tool. ' .
'[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'), '[Join now](%%%%action.%s%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
$this->user->nickname, $this->user->nickname); $this->user->nickname,
(!common_config('site','openidonly')) ? 'register' : 'openidlogin',
$this->user->nickname);
} else { } else {
$m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' . $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
'based on the Free Software [Laconica](http://laconi.ca/) tool. '), 'based on the Free Software [Laconica](http://laconi.ca/) tool. '),
......
...@@ -111,7 +111,9 @@ class SubscribersAction extends GalleryAction ...@@ -111,7 +111,9 @@ class SubscribersAction extends GalleryAction
} }
} }
else { else {
$message = sprintf(_('%s has no subscribers. Why not [register an account](%%%%action.register%%%%) and be the first?'), $this->user->nickname); $message = sprintf(_('%s has no subscribers. Why not [register an account](%%%%action.%s%%%%) and be the first?'),
$this->user->nickname,
(!common_config('site','openidonly')) ? 'register' : 'openidlogin');
} }
$this->elementStart('div', 'guide'); $this->elementStart('div', 'guide');
......
...@@ -47,7 +47,11 @@ class UserauthorizationAction extends Action ...@@ -47,7 +47,11 @@ class UserauthorizationAction extends Action
# Go log in, and then come back # Go log in, and then come back
common_set_returnto($_SERVER['REQUEST_URI']); common_set_returnto($_SERVER['REQUEST_URI']);
common_redirect(common_local_url('login')); if (!common_config('site', 'openidonly')) {
common_redirect(common_local_url('login'));
} else {
common_redirect(common_local_url('openidlogin'));
}
return; return;
} }
......
...@@ -38,6 +38,8 @@ $config['site']['path'] = 'laconica'; ...@@ -38,6 +38,8 @@ $config['site']['path'] = 'laconica';
// $config['site']['closed'] = true; // $config['site']['closed'] = true;
// Only allow registration for people invited by another user // Only allow registration for people invited by another user
// $config['site']['inviteonly'] = true; // $config['site']['inviteonly'] = true;
// Only allow registrations and logins through OpenID
// $config['site']['openidonly'] = true;
// Make the site invisible to non-logged-in users // Make the site invisible to non-logged-in users
// $config['site']['private'] = true; // $config['site']['private'] = true;
......
...@@ -182,12 +182,20 @@ function main() ...@@ -182,12 +182,20 @@ function main()
// If the site is private, and they're not on one of the "public" // If the site is private, and they're not on one of the "public"
// parts of the site, redirect to login // parts of the site, redirect to login
if (!$user && common_config('site', 'private') && if (!$user && common_config('site', 'private')) {
!in_array($action, array('login', 'openidlogin', 'finishopenidlogin', $public_actions = array('openidlogin', 'finishopenidlogin',
'recoverpassword', 'api', 'doc', 'register')) && 'recoverpassword', 'api', 'doc');
!preg_match('/rss$/', $action)) { $login_action = 'openidlogin';
common_redirect(common_local_url('login')); if (!common_config('site', 'openidonly')) {
return; $public_actions[] = 'login';
$public_actions[] = 'register';
$login_action = 'login';
}
if (!in_array($action, $public_actions) &&
!preg_match('/rss$/', $action)) {
common_redirect(common_local_url($login_action));
return;
}
} }
$action_class = ucfirst($action).'Action'; $action_class = ucfirst($action).'Action';
......
...@@ -436,12 +436,17 @@ class Action extends HTMLOutputter // lawsuit ...@@ -436,12 +436,17 @@ class Action extends HTMLOutputter // lawsuit
_('Logout'), _('Logout from the site'), false, 'nav_logout'); _('Logout'), _('Logout from the site'), false, 'nav_logout');
} }
else { else {
if (!common_config('site', 'closed')) { if (!common_config('site', 'openidonly')) {
$this->menuItem(common_local_url('register'), if (!common_config('site', 'closed')) {
_('Register'), _('Create an account'), false, 'nav_register'); $this->menuItem(common_local_url('register'),
_('Register'), _('Create an account'), false, 'nav_register');
}
$this->menuItem(common_local_url('login'),
_('Login'), _('Login to the site'), false, 'nav_login');
} else {
$this->menuItem(common_local_url('openidlogin'),
_('OpenID'), _('Login with OpenID'), false, 'nav_openid');
} }
$this->menuItem(common_local_url('login'),
_('Login'), _('Login to the site'), false, 'nav_login');
} }
$this->menuItem(common_local_url('doc', array('title' => 'help')), $this->menuItem(common_local_url('doc', array('title' => 'help')),
_('Help'), _('Help me!'), false, 'nav_help'); _('Help'), _('Help me!'), false, 'nav_help');
......
...@@ -109,6 +109,7 @@ $config = ...@@ -109,6 +109,7 @@ $config =
'broughtbyurl' => null, 'broughtbyurl' => null,
'closed' => false, 'closed' => false,
'inviteonly' => false, 'inviteonly' => false,
'openidonly' => false,
'private' => false, 'private' => false,
'ssl' => 'never', 'ssl' => 'never',
'sslserver' => null, 'sslserver' => null,
......
...@@ -256,8 +256,13 @@ class FacebookAction extends Action ...@@ -256,8 +256,13 @@ class FacebookAction extends Action
$this->elementStart('dd'); $this->elementStart('dd');
$this->elementStart('p'); $this->elementStart('p');
$this->text(sprintf($loginmsg_part1, common_config('site', 'name'))); $this->text(sprintf($loginmsg_part1, common_config('site', 'name')));
$this->element('a', if (!common_config('site', 'openidonly')) {
array('href' => common_local_url('register')), _('Register')); $this->element('a',
array('href' => common_local_url('register')), _('Register'));
} else {
$this->element('a',
array('href' => common_local_url('openidlogin')), _('Register'));
}
$this->text($loginmsg_part2); $this->text($loginmsg_part2);
$this->elementEnd('p'); $this->elementEnd('p');
$this->elementEnd('dd'); $this->elementEnd('dd');
......
...@@ -72,11 +72,13 @@ class LoginGroupNav extends Widget ...@@ -72,11 +72,13 @@ class LoginGroupNav extends Widget
// action => array('prompt', 'title') // action => array('prompt', 'title')
$menu = array(); $menu = array();
$menu['login'] = array(_('Login'), if (!common_config('site','openidonly')) {
_('Login with a username and password')); $menu['login'] = array(_('Login'),
if (!(common_config('site','closed') || common_config('site','inviteonly'))) { _('Login with a username and password'));
$menu['register'] = array(_('Register'), if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
_('Sign up for a new account')); $menu['register'] = array(_('Register'),
_('Sign up for a new account'));
}
} }
$menu['openidlogin'] = array(_('OpenID'), $menu['openidlogin'] = array(_('OpenID'),
_('Login or register with OpenID')); _('Login or register with OpenID'));
......
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