Skip to content
Snippets Groups Projects
Commit 77ecfb5f authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

adjust password reset links expiration to 1 week and include expiration info...

adjust password reset links expiration to 1 week and include expiration info in sent mails, fixes #1647

Closes #1647

Merge request studip/studip!1061
parent 6a16eee0
No related branches found
No related tags found
No related merge requests found
......@@ -679,7 +679,14 @@ class UserManagement
setTempLanguage($user->user_id);
// always generate a token, so root, admin and all other users profit from the abuse protection
$id = Token::create(24 * 60 * 60, $user->id);
if ($new) {
$expiration_in_hours = 24;
$spoken_expiration = _('24 Stunden');
} else {
$expiration_in_hours = 7 * 24;
$spoken_expiration = _('eine Woche');
}
$token = Token::create($expiration_in_hours * 60 * 60, $user->id, true);
// new users alawys receive a link to generate a password
if ($new) {
......@@ -690,20 +697,23 @@ class UserManagement
$mailbody = sprintf(
_("Dies ist eine Bestätigungsmail des Stud.IP-Systems\n"
."(Studienbegleitender Internetsupport von Präsenzlehre)\n- %s -\n\n"
."(Studienbegleitender Internetsupport von Präsenzlehre)\n- %1\$s -\n\n"
."Es wurde für sie ein Zugang zum System erstellt, Ihr Nutzername lautet:\n\n"
."%s\n\n"
."%2\$s\n\n"
."Um den Zugang nutzen zu können, müssen sie ein Passwort setzen.\n"
."Öffnen Sie dafür bitte folgenden Link\n\n"
."%s\n\n"
."%3\$s\n\n"
."in Ihrem Browser.\n\n"
."Der Link ist %4\$s (bis %5\$s) gültig.\n\n"
."Wahrscheinlich unterstützt Ihr E-Mail-Programm ein einfaches Anklicken des Links.\n"
."Ansonsten müssen Sie Ihren Browser öffnen und den Link komplett in die Zeile\n"
."\"Location\" oder \"URL\" kopieren.\n\n"
),
Config::get()->UNI_NAME_CLEAN,
$user->username,
$GLOBALS['ABSOLUTE_URI_STUDIP'] . 'dispatch.php/new_password/set/'. $id .'?cancel_login=1'
$GLOBALS['ABSOLUTE_URI_STUDIP'] . 'dispatch.php/new_password/set/'. $token->token .'?cancel_login=1',
$spoken_expiration,
strftime('%x %X', $token->expiration)
);
} else
......@@ -738,14 +748,15 @@ class UserManagement
$mailbody = sprintf(
_("Dies ist eine Bestätigungsmail des Stud.IP-Systems\n"
."(Studienbegleitender Internetsupport von Präsenzlehre)\n- %s -\n\n"
."(Studienbegleitender Internetsupport von Präsenzlehre)\n- %1\$s -\n\n"
."Sie haben um die Zurücksetzung Ihres Passwortes gebeten.\n\n"
."Diese E-Mail wurde Ihnen zugesandt um sicherzustellen,\n"
."dass die angegebene E-Mail-Adresse tatsächlich Ihnen gehört.\n\n"
."Wenn Sie um die Zurücksetzung Ihres Passwortes gebeten haben,\n"
."dann öffnen Sie bitte folgenden Link\n\n"
."%s\n\n"
."%2\$s\n\n"
."in Ihrem Browser. Auf der Seite können Sie ein neues Passwort setzen.\n\n"
."Der Link ist %3\$s (bis %4\$s) gültig.\n\n"
."Wahrscheinlich unterstützt Ihr E-Mail-Programm ein einfaches Anklicken des Links.\n"
."Ansonsten müssen Sie Ihren Browser öffnen und den Link komplett in die Zeile\n"
."\"Location\" oder \"URL\" kopieren.\n\n"
......@@ -756,7 +767,9 @@ class UserManagement
."Änderungen an Ihren Zugangsdaten vorgenommen.\n\n"
),
Config::get()->UNI_NAME_CLEAN,
$GLOBALS['ABSOLUTE_URI_STUDIP'] . 'dispatch.php/new_password/set/'. $id .'?cancel_login=1'
$GLOBALS['ABSOLUTE_URI_STUDIP'] . 'dispatch.php/new_password/set/'. $token->token .'?cancel_login=1',
$spoken_expiration,
strftime('%x %X', $token->expiration)
);
}
......
......@@ -5,6 +5,13 @@
* @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
* @author Marco Diedrich <mdiedric@uos.de>
* @license GPL2 or any later version
*
* @property string $id
* @property string $token
* @property string $user_id
* @property int $expiration
* @property int $mkdate
* @property User $user
*/
class Token extends SimpleORMap
{
......@@ -46,16 +53,17 @@ class Token extends SimpleORMap
*
* @param integer $duration Lifetime of the token
* @param mixed $user_id Optional id of the user (defaults to current user)
* @return string the token
* @param bool $return_object Return the actual token object if true, only the token otherwise (default)
* @return string|Token the token
*/
public static function create($duration = 30, $user_id = null)
public static function create($duration = 30, $user_id = null, bool $return_object = false)
{
$token = new self();
$token->user_id = $user_id ?? $GLOBALS['user']->id;
$token->expiration = strtotime("+{$duration} seconds");
$token->store();
return $token->token;
return $return_object ? $token : $token->token;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment