add user pending status

This commit is contained in:
Jean-Christian Denis 2025-01-11 18:31:37 +01:00
parent d6cf60fed3
commit 90ba71538d
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
7 changed files with 69 additions and 21 deletions

View file

@ -47,7 +47,7 @@
<input type="password" id="{{tpl:FrontendSessionID}}_page_password" name="{{tpl:FrontendSessionID}}_password" value="" /> <input type="password" id="{{tpl:FrontendSessionID}}_page_password" name="{{tpl:FrontendSessionID}}_password" value="" />
</p> </p>
<p> <p>
<input class="submit" type="submit" id="{{tpl:FrontendSessionID}}_page_submit" name="{{tpl:FrontendSessionID}}_submit" value="{{tpl:lang Start to share}}" /> <input class="submit" type="submit" id="{{tpl:FrontendSessionID}}_page_submit" name="{{tpl:FrontendSessionID}}_submit" value="{{tpl:lang Connect}}" />
</p> </p>
</form> </form>
</div> </div>

View file

@ -7,6 +7,7 @@ namespace Dotclear\Plugin\FrontendSession;
use ArrayObject; use ArrayObject;
use Dotclear\App; use Dotclear\App;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Core\Backend\Notices;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
Div, Div,
@ -16,6 +17,7 @@ use Dotclear\Helper\Html\Form\{
Textarea Textarea
}; };
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Dotclear\Helper\Network\Http;
use Dotclear\Interface\Core\BlogSettingsInterface; use Dotclear\Interface\Core\BlogSettingsInterface;
/** /**
@ -93,6 +95,23 @@ class Backend extends Process
$attr[2] = App::blog()->url() . App::url()->getURLFor(My::id()); $attr[2] = App::blog()->url() . App::url()->getURLFor(My::id());
} }
}, },
'adminUsersActions' => function (array $users, array $blogs, string $action, string $redir): void {
if ($action == My::id()) {
foreach ($users as $u) {
try {
$cur = App::auth()->openUserCursor();
$cur->user_status = My::USER_PENDING;
App::users()->updUser($u, $cur);
} catch (Exception $e) {
App::error()->add($e->getMessage());
}
}
if (!App::error()->flag()) {
Notices::addSuccessNotice(__('User has been successfully marked as pending.'));
Http::redirect($redir);
}
}
},
]); ]);
return true; return true;

View file

@ -93,30 +93,47 @@ class Frontend extends Process
// we check the user and its perm // we check the user and its perm
if (App::auth()->checkUser($user_id, $user_pwd, $user_key, false) === true if (App::auth()->checkUser($user_id, $user_pwd, $user_key, false) === true
&& App::auth()->check(My::id(), App::blog()->id()) === true && App::auth()->check(My::id(), App::blog()->id()) === true
//&& !App::status()->user()->isRestricted((int) App::auth()->getInfo('user_status'))
) { ) {
if ($user_key === null) { // check if user is pending activation
$cookie_console = Http::browserUID( if ((int) App::auth()->getInfo('user_status') == My::USER_PENDING) {
App::config()->masterKey() . self::resetCookie();
$user_id . Http::redirect(App::blog()->url() . App::url()->getURLFor(My::id()) . '/pending');
App::auth()->cryptLegacy($user_id) // check if user is not enabled
) . bin2hex(pack('a32', $user_id)); } elseif (App::status()->user()->isRestricted((int) App::auth()->getInfo('user_status'))) {
self::resetCookie();
Http::redirect(Http::getSelfURI());
} else { } else {
$cookie_console = $_COOKIE[My::id()]; if ($user_key === null) {
$cookie_console = Http::browserUID(
App::config()->masterKey() .
$user_id .
App::auth()->cryptLegacy($user_id)
) . bin2hex(pack('a32', $user_id));
} else {
$cookie_console = $_COOKIE[My::id()];
}
setcookie(My::id(), $cookie_console, strtotime('+20 hours'), '/', '', self::useSSL());
} }
setcookie(My::id(), $cookie_console, strtotime('+20 hours'), '/', '', self::useSSL());
} else { } else {
//App::frontend()->context()->form_error = __("Error: your password may be wrong or you haven't an account or you haven't ask for its activation."); self::resetCookie();
if (isset($_COOKIE[My::id()])) {
unset($_COOKIE[My::id()]);
setcookie(My::id(), '', time() - 3600, '/', '', self::useSSL());
}
// need to replay doAuthControl() to remove user information from Auth if it exists but have no permissions // need to replay doAuthControl() to remove user information from Auth if it exists but have no permissions
Http::redirect(Http::getSelfURI()); Http::redirect(Http::getSelfURI());
} }
} }
} }
/**
* Remove cookie
*/
public static function resetCookie(): void
{
if (isset($_COOKIE[My::id()])) {
unset($_COOKIE[My::id()]);
setcookie(My::id(), '', time() - 3600, '/', '', self::useSSL());
}
}
/** /**
* Check SSL. * Check SSL.
*/ */

View file

@ -18,5 +18,5 @@ use Dotclear\Module\MyPlugin;
*/ */
class My extends MyPlugin class My extends MyPlugin
{ {
// nothing special public const USER_PENDING = -201;
} }

View file

@ -5,9 +5,8 @@ declare(strict_types=1);
namespace Dotclear\Plugin\FrontendSession; namespace Dotclear\Plugin\FrontendSession;
use Dotclear\App; use Dotclear\App;
use Dotclear\Core\PostType;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Database\MetaRecord; use Dotclear\Helper\Stack\Status;
/** /**
* @brief FrontendSession module prepend. * @brief FrontendSession module prepend.
@ -29,13 +28,13 @@ class Prepend extends Process
return false; return false;
} }
// contributor permission // Add frontend permission (required to login in frontend)
App::auth()->setPermissionType( App::auth()->setPermissionType(
My::id(), My::id(),
My::name() My::name()
); );
// add session login URL // Add session login URL
App::url()->register( App::url()->register(
My::id(), My::id(),
'session/login', 'session/login',
@ -43,6 +42,15 @@ class Prepend extends Process
[UrlHandler::class, 'sessionLogin'] [UrlHandler::class, 'sessionLogin']
); );
// Add user status
App::status()->user()->set((new Status(
My::USER_PENDING ,
My::id(),
'Pending registration',
'pending registration (>1)',
My::fileURL('icon.svg'))
));
return true; return true;
} }
} }

View file

@ -49,6 +49,10 @@ class UrlHandler extends Url
App::blog()->triggerBlog(); App::blog()->triggerBlog();
Http::redirect(App::blog()->url()); Http::redirect(App::blog()->url());
// user pending activation
} elseif (is_array($args) && $args[0] == 'pending' && App::auth()->userID() == '') {
App::frontend()->context()->form_error = __("Error: your account is not yet activated.");
self::serveTemplate(My::id() . '.html');
// no loggin session, go to login page // no loggin session, go to login page
} elseif (App::auth()->userID() == '') { } elseif (App::auth()->userID() == '') {
self::serveTemplate(My::id() . '.html'); self::serveTemplate(My::id() . '.html');

View file

@ -59,7 +59,7 @@ class Widgets
} else { } else {
$res .= '<form method="post" name="' . My::id() . '_form" id="' . My::id() . '_widget_form" action="">'; $res .= '<form method="post" name="' . My::id() . '_form" id="' . My::id() . '_widget_form" action="">';
if (App::frontend()->context()->form_error !== null) { if (App::frontend()->context()->form_error !== null) {
$res .= '<p class="erreur">' . Html::escapeHTML(App::frontend()->context()->form_error) . '</p>'; //$res .= '<p class="erreur">' . Html::escapeHTML(App::frontend()->context()->form_error) . '</p>';
} }
$res .= '<p>' . $res .= '<p>' .
'<label for="' . My::id() . '_login" class="required">' . __('Login:') . '</label><br />' . '<label for="' . My::id() . '_login" class="required">' . __('Login:') . '</label><br />' .