Verified Commit 364106ed authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(invitations) Added token generation, storage and check

We will need to get the token from GET most likely.

issue #5850
Showing with 31 additions and 3 deletions
+31 -3
...@@ -140,7 +140,9 @@ class invitation extends simplePlugin ...@@ -140,7 +140,9 @@ class invitation extends simplePlugin
if (empty($email)) { if (empty($email)) {
continue; continue;
} }
if (mail_utf8($email, FALSE, $this->from_mail, $this->fdInvitationEmailSubject, $this->fdInvitationEmailContent)) { $token = standAlonePage::generateRandomHash();
$body = sprintf($this->fdInvitationEmailContent, $token);
if (mail_utf8($email, FALSE, $this->from_mail, $this->fdInvitationEmailSubject, $body)) {
$tabObject = objects::create('registration'); $tabObject = objects::create('registration');
$baseObject = $tabObject->getBaseObject(); $baseObject = $tabObject->getBaseObject();
...@@ -149,6 +151,7 @@ class invitation extends simplePlugin ...@@ -149,6 +151,7 @@ class invitation extends simplePlugin
$baseObject->fdRegistrationState = 'sent'; $baseObject->fdRegistrationState = 'sent';
$baseObject->fdRegistrationLastChange = date('c').':'.$ui->dn; $baseObject->fdRegistrationLastChange = date('c').':'.$ui->dn;
$baseObject->fdRegistrationInvitationDN = $this->dn; $baseObject->fdRegistrationInvitationDN = $this->dn;
$baseObject->fdRegistrationToken = $token;
$messages = $tabObject->save(); $messages = $tabObject->save();
if (!empty($messages)) { if (!empty($messages)) {
......
...@@ -69,6 +69,7 @@ class registration extends simplePlugin ...@@ -69,6 +69,7 @@ class registration extends simplePlugin
_('User object'), _('User object created by this registration'), _('User object'), _('User object created by this registration'),
'fdRegistrationUserDN', FALSE 'fdRegistrationUserDN', FALSE
), ),
new HiddenAttribute('fdRegistrationToken'),
) )
), ),
); );
......
...@@ -69,6 +69,12 @@ attributetype ( 1.3.6.1.4.1.38414.69.11.5 NAME 'fdRegistrationUserDN' ...@@ -69,6 +69,12 @@ attributetype ( 1.3.6.1.4.1.38414.69.11.5 NAME 'fdRegistrationUserDN'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE ) SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.38414.69.11.6 NAME 'fdRegistrationToken'
DESC 'FusionDirectory - Token to identify this registration'
EQUALITY octetStringMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{128}
SINGLE-VALUE )
# Objectclasses # Objectclasses
objectclass ( 1.3.6.1.4.1.38414.69.2.1 NAME 'fdInvitation' objectclass ( 1.3.6.1.4.1.38414.69.2.1 NAME 'fdInvitation'
......
...@@ -23,6 +23,8 @@ class publicFormPage extends standAlonePage ...@@ -23,6 +23,8 @@ class publicFormPage extends standAlonePage
protected $form; protected $form;
protected $template; protected $template;
protected $done; protected $done;
// TODO fill this var by link/GET/LLNG
  • :information_source: Complete the task associated to this "TODO" comment. :blue_book:

Please register or sign in to reply
protected $registrationToken;
function readLdapConfig() function readLdapConfig()
{ {
...@@ -33,6 +35,8 @@ class publicFormPage extends standAlonePage ...@@ -33,6 +35,8 @@ class publicFormPage extends standAlonePage
function save_object() function save_object()
{ {
global $ui;
if (!$this->activated) { if (!$this->activated) {
return; return;
} }
...@@ -77,10 +81,24 @@ class publicFormPage extends standAlonePage ...@@ -77,10 +81,24 @@ class publicFormPage extends standAlonePage
$this->template->save_object(); $this->template->save_object();
if (isset($_POST['form_submit'])) { if (isset($_POST['form_submit'])) {
$tabobject = $this->template->apply(); $userTabObject = $this->template->apply();
$errors = $tabobject->save(); $errors = $userTabObject->save();
if (empty($errors)) { if (empty($errors)) {
$this->done = TRUE; $this->done = TRUE;
if (isset($this->registrationToken)) {
$registrations = objects::ls('registration', NULL, NULL, '(fdRegistrationToken='.$this->registrationToken.')');
if (count($registrations) == 1) {
$tabObject = objects::open(key($registrations), 'registration');
$baseObject = $tabObject->getBaseObject();
$baseObject->fdRegistrationUserDN = $userTabObject->dn;
$baseObject->fdRegistrationState = 'filled';
$baseObject->fdRegistrationLastChange = date('c').':'.$ui->dn;
$messages = $tabObject->save();
msg_dialog::displayChecks($messages);
}
}
} else { } else {
msg_dialog::displayChecks($errors); msg_dialog::displayChecks($errors);
// TODO - Find a way to refill previous values in the fields // TODO - Find a way to refill previous values in the fields
......
  • SonarQube analysis reported 2 issues

    • :arrow_down_small: 1 minor
    • :information_source: 1 info

    Watch the comments in this conversation to review them.

    1 extra issue

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. :arrow_down_small: Remove this method "__construct" to simply inherit it. :blue_book:
Supports Markdown
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