3 * FusionForge authentication management
5 * Copyright 2011, Roland Mas
6 * Copyright 2014-2015, Franck Villaume - TrivialDev
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * Default authentication mechanism based on DB user's password storage
29 class AuthBuiltinPlugin extends ForgeAuthPlugin {
31 function __construct() {
32 parent::__construct();
34 $this->name = 'authbuiltin';
35 $this->text = _('Built-in authentication');
37 $this->_addHook('check_auth_session');
38 $this->_addHook('fetch_authenticated_user');
39 $this->_addHook('display_auth_form');
40 // display_create_user_form - display a form to create a user from external auth
41 // sync_account_info - sync identity from external source (realname, email, etc.)
42 // get_extra_roles - add new roles not necessarily stored in the database
43 // restrict_roles - filter out unwanted roles
44 $this->_addHook('close_auth_session');
45 $this->_addHook("refresh_auth_session");
47 $this->declareConfigVars();
51 * Display a form to input credentials : default login dialog ('display_auth_form' hook)
52 * @param unknown_type $params
55 function displayAuthForm(&$params) {
57 if (!$this->isRequired() && !$this->isSufficient()) {
60 $return_to = $params['return_to'];
62 if (isset($params['attempts']) && $params['attempts'] >= 1) {
63 $loginname = $params['previousLogin'];
68 $result .= html_e('p', array(), _('Cookies must be enabled past this point.'), false);
69 $result .= $HTML->openForm(array('action' => '/plugins/'.$this->name.'/post-login.php', 'method' => 'post'), true);
70 $result .= html_e('input', array('type' => 'hidden', 'name' => 'form_key', 'value' => form_generate_key()));
71 $result .= html_e('input', array('type' => 'hidden', 'name' => 'return_to', 'value' => $return_to));
72 $result .= html_ao('p');
73 if (forge_get_config('require_unique_email')) {
74 $result .= _('Login name or email address')._(':');
76 $result .= _('Login Name')._(':');
78 $result .= html_e('br').html_e('input', array('type' => 'text', 'name' => 'form_loginname', 'value' => htmlspecialchars(stripslashes($loginname)), 'required' => 'required'));
79 $result .= html_ac(html_ap() -1);
80 $result .= html_ao('p')._('Password')._(':');
81 $result .= html_e('br').html_e('input', array('type' => 'password', 'name' => 'form_pw', 'required' => 'required'));
82 $result .= html_ac(html_ap() -1);
83 if (isset($params['attempts'])) {
84 $result .= html_e('input', array('type' => 'hidden', 'name' => 'attempts', 'value' => $params['attempts']));
85 if (isset($params['previousLogin'])) {
86 $result .= html_e('input', array('type' => 'hidden', 'name' => 'previous_login', 'value' => $params['previousLogin']));
88 if ($params['attempts'] > 3) {
89 plugin_hook_by_reference('captcha_form', $result);
92 $result .= html_e('p', array(), html_e('input', array('type' => 'submit', 'name' => 'login', 'value' => _('Login'))), false);
93 $result .= $HTML->closeForm();
94 $result .= html_e('p', array(), util_make_link('/account/lostpw.php', _('[Lost your password?]')));
95 // hide "new account" item if restricted to admin
96 if (!forge_get_config ('user_registration_restricted')) {
97 $result .= html_e('p', array(), util_make_link('/account/register.php', _('New Account')));
99 $result .= html_e('p', array(), util_make_link('/account/pending-resend.php', _('Resend confirmation email to a pending account')));
101 $params['html_snippets'][$this->name] = $result;
107 // c-file-style: "bsd"