add user pending status
This commit is contained in:
parent
d6cf60fed3
commit
90ba71538d
7 changed files with 69 additions and 21 deletions
|
@ -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>
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -93,7 +93,17 @@ 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'))
|
||||||
) {
|
) {
|
||||||
|
// check if user is pending activation
|
||||||
|
if ((int) App::auth()->getInfo('user_status') == My::USER_PENDING) {
|
||||||
|
self::resetCookie();
|
||||||
|
Http::redirect(App::blog()->url() . App::url()->getURLFor(My::id()) . '/pending');
|
||||||
|
// check if user is not enabled
|
||||||
|
} elseif (App::status()->user()->isRestricted((int) App::auth()->getInfo('user_status'))) {
|
||||||
|
self::resetCookie();
|
||||||
|
Http::redirect(Http::getSelfURI());
|
||||||
|
} else {
|
||||||
if ($user_key === null) {
|
if ($user_key === null) {
|
||||||
$cookie_console = Http::browserUID(
|
$cookie_console = Http::browserUID(
|
||||||
App::config()->masterKey() .
|
App::config()->masterKey() .
|
||||||
|
@ -104,19 +114,26 @@ class Frontend extends Process
|
||||||
$cookie_console = $_COOKIE[My::id()];
|
$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 {
|
|
||||||
//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.");
|
|
||||||
|
|
||||||
if (isset($_COOKIE[My::id()])) {
|
|
||||||
unset($_COOKIE[My::id()]);
|
|
||||||
setcookie(My::id(), '', time() - 3600, '/', '', self::useSSL());
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
self::resetCookie();
|
||||||
// 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.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -18,5 +18,5 @@ use Dotclear\Module\MyPlugin;
|
||||||
*/
|
*/
|
||||||
class My extends MyPlugin
|
class My extends MyPlugin
|
||||||
{
|
{
|
||||||
// nothing special
|
public const USER_PENDING = -201;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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');
|
||||||
|
|
|
@ -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 />' .
|
||||||
|
|
Loading…
Reference in a new issue