Skip to content

Commit

Permalink
feat(User): always create change password link and go to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
mrflos committed Jul 31, 2024
1 parent 9d63a1d commit cd2d3e4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
43 changes: 26 additions & 17 deletions includes/services/UserManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace YesWiki\Core\Service;

use Exception;
Expand All @@ -17,6 +18,7 @@
use YesWiki\Core\Exception\UserNameAlreadyUsedException;
use YesWiki\Security\Controller\SecurityController;
use YesWiki\Wiki;

if (! function_exists('send_mail')) {
require_once 'includes/email.inc.php';
}
Expand Down Expand Up @@ -193,17 +195,7 @@ public function create($wikiNameOrUser, string $email = '', string $plainPasswor
* 5. The corresponding row is removed from triples table.
*/

/**
* Part of the Password recovery process: Handles the password recovery email process.
*
* Generates the password recovery key
* Stores the (name, vocabulary, key) triple in triples table
* Generates the recovery email
* Sends it
*
* @return bool True if OK or false if any problems
*/
public function sendPasswordRecoveryEmail(User $user, string $title): bool
protected function generateUserLink($user)
{
// Generate the password recovery key
$key = md5($user['name'] . '_' . $user['email'] . random_int(0, 10000) . date('Y-m-d H:i:s') . self::PW_SALT);
Expand All @@ -219,6 +211,21 @@ public function sendPasswordRecoveryEmail(User $user, string $title): bool
'email' => $key,
'u' => base64_encode($user['name'])
], false);
}

/**
* Part of the Password recovery process: Handles the password recovery email process.
*
* Generates the password recovery key
* Stores the (name, vocabulary, key) triple in triples table
* Generates the recovery email
* Sends it
*
* @return bool True if OK or false if any problems
*/
public function sendPasswordRecoveryEmail(User $user, string $title): bool
{
$this->generateUserLink($user);
$pieces = parse_url($this->params->get('base_url'));
$domain = isset($pieces['host']) ? $pieces['host'] : '';

Expand All @@ -233,13 +240,14 @@ public function sendPasswordRecoveryEmail(User $user, string $title): bool
// Send the email
return send_mail($this->params->get('BAZ_ADRESSE_MAIL_ADMIN'), $this->params->get('BAZ_ADRESSE_MAIL_ADMIN'), $user['email'], $subject, $message);
}

/**
* Assessor for userlink field
*
* @return string
*/
public function getUserLink(): string {
public function getUserLink(): string
{
return $this->userlink;
}

Expand All @@ -248,7 +256,8 @@ public function getUserLink(): string {
*
* @return string
*/
public function getLastUserLink(User $user): string {
public function getLastUserLink(User $user): string
{
$tripleStore = $this->wiki->services->get(TripleStore::class);
$key = $tripleStore->getOne($user['name'], self::KEY_VOCABULARY, '', '');
if ($key != null) {
Expand All @@ -258,11 +267,11 @@ public function getLastUserLink(User $user): string {
'u' => base64_encode($user['name'])
], false);
} else {
$this->userlink = '';
$this->generateUserLink($user);
}
return $this->userlink;
}

/**
* update user params
* for e-mail check is existing e-mail.
Expand Down Expand Up @@ -509,4 +518,4 @@ public function logout()
{
$this->wiki->services->get(AuthController::class)->logout();
}
}
}
3 changes: 2 additions & 1 deletion lang/yeswiki_fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
'ERROR_ACTION_TRAIL' => 'Erreur action {{trail ...}}',
'INDICATE_THE_PARAMETER_TOC' => 'Indiquez le nom de la page sommaire, paramètre "toc"',
// actions/usersettings.php
'USER_GOTOADMIN' => 'Gestion des utilisateurices',
'USER_SETTINGS' => 'Paramètres utilisateur',
'USER_SIGN_UP' => 'S\'inscrire',
'YOU_ARE_NOW_DISCONNECTED' => 'Vous êtes maintenant déconnecté',
Expand Down Expand Up @@ -628,4 +629,4 @@
'REACTION_TITLE_PARAM_NEEDED' => 'Le paramètre \'titre\' est obligatoire',
'REACTION_BAD_IMAGE_FORMAT' => 'Mauvais format d\'image : doit être un fichier, un icône utf8 ou une classe Fontawesome',
'REACTION_NO_IMAGE' => 'Image manquante',
];
];
5 changes: 3 additions & 2 deletions tools/login/templates/usersettings.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<h2>{{ _t('USER_SETTINGS') }}{{ adminIsActing ? '' ~ user.name : ''}}</h2>
{% if adminIsActing %} <a href="{{ url({tag: 'GererUtilisateurs'}) }}" class="btn btn-primary pull-right"><i class="fa fa-arrow-left"></i> {{ _t('USER_GOTOADMIN')}}</a>{% endif %}
<h2>{{ _t('USER_SETTINGS') }}{% if adminIsActing %} — {{user.name}}{% endif %}</h2>

{% if errorUpdate is not empty %}
<div class="alert alert-danger">{{ errorUpdate }}</div>
Expand Down Expand Up @@ -93,4 +94,4 @@
</div>
</div>
</form>
{% endif %}
{% endif %}

0 comments on commit cd2d3e4

Please sign in to comment.