openrat-cms

OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs | README

commit f84af6f067e2efa3740e50c5751058cb40f190c8
parent 986683565ed51e9d852bae6777bcdeaf3fa023e2
Author: Jan Dankert <develop@jandankert.de>
Date:   Fri, 27 Nov 2020 20:11:28 +0100

New: Send mail to user after login and after the password has changed.

Diffstat:
Mmodules/cms/action/login/LoginLoginAction.class.php | 12++++++++++++
Mmodules/cms/action/profile/ProfilePwAction.class.php | 10++++++++++
Mmodules/language/Language_CN.class.php | 8++++++++
Mmodules/language/Language_DE.class.php | 8++++++++
Mmodules/language/Language_EN.class.php | 8++++++++
Mmodules/language/Language_ES.class.php | 8++++++++
Mmodules/language/Language_FR.class.php | 8++++++++
Mmodules/language/Language_IT.class.php | 8++++++++
Mmodules/language/Language_RU.class.php | 8++++++++
Mmodules/language/Messages.class.php | 4++++
Mmodules/language/language.yml | 22++++++++++++++++++++++
11 files changed, 104 insertions(+), 0 deletions(-)

diff --git a/modules/cms/action/login/LoginLoginAction.class.php b/modules/cms/action/login/LoginLoginAction.class.php @@ -16,6 +16,7 @@ use logger\Logger; use security\Password; use util\exception\ObjectNotFoundException; use util\exception\SecurityException; +use util\Mail; use util\Session; use util\text\TextMessage; @@ -207,6 +208,17 @@ class LoginLoginAction extends LoginAction implements Method { if ( Configuration::subset('security')->is('renew_session_login',false) ) $this->recreateSession(); + // Send mail to user to inform about the new login. + if ( $user->mail && Configuration::subset('security')->is('inform_user_about_new_login',true) ) { + $mail = new Mail( $user->mail, Messages::MAIL_NEW_LOGIN_SUBJECT, Messages::MAIL_NEW_LOGIN_TEXT ); + $browser = new \util\Browser(); + $mail->setVar( 'platform',$browser->platform ); + $mail->setVar( 'browser' ,$browser->name ); + $mail->setVar( 'username',$user->name ); + $mail->setVar( 'name' ,$user->getName() ); + $mail->send(); + } + $this->addNoticeFor( $user,Messages::LOGIN_OK, array('name' => $user->getName() )); // Setting the user-defined language diff --git a/modules/cms/action/profile/ProfilePwAction.class.php b/modules/cms/action/profile/ProfilePwAction.class.php @@ -5,6 +5,7 @@ use cms\action\ProfileAction; use cms\base\Configuration; use cms\model\User; use language\Messages; +use util\Mail; class ProfilePwAction extends ProfileAction implements Method { public function view() { @@ -22,6 +23,9 @@ class ProfilePwAction extends ProfileAction implements Method { public function post() { $pwMinLength = Configuration::subset(['security','password'])->get('min_length',10); + if ( $this->user->type != User::AUTH_TYPE_INTERNAL ) + throw new \LogicException('password change only possible for internal users.'); + if ( ! $this->user->checkPassword( $this->getRequestVar('act_password') ) ) { $this->addValidationError('act_password'); @@ -42,6 +46,12 @@ class ProfilePwAction extends ProfileAction implements Method { { $this->user->setPassword( $this->getRequestVar('password1') ); $this->addNoticeFor( $this->user,Messages::SAVED); + + // Send mail to user to inform about the new password. + if ( $this->user->mail ) { + $mail = new Mail( $this->user->mail,Messages::MAIL_PASSWORD_CHANGE_SUCCESS_SUBJECT,Messages::MAIL_PASSWORD_CHANGE_SUCCESS); + $mail->send(); + } } } } diff --git a/modules/language/Language_CN.class.php b/modules/language/Language_CN.class.php @@ -552,6 +552,14 @@ public function get() { return [ 'LOGO_REGISTER'=>'Registration', 'LOGO_REGISTER_TEXT'=>'If you do not have an user account, then feel free to register now. You need an E-Mail account, to which a registration code is sent.', 'MAIL_CODE'=>'Confirmation code', +'MAIL_PASSWORD_CHANGE_SUCCESS_SUBJECT'=>'Your password was successfully changed', +'MAIL_PASSWORD_CHANGE_SUCCESS'=>'Your password was successfully changed', +'MAIL_NEW_LOGIN_SUBJECT'=>'New login', +'MAIL_NEW_LOGIN_TEXT'=>'Hello ${name}, + +We want to inform you that you just logged in with your username ${username} on the device ${browser} (${platform}). + +If you did not do this, please change your password.', 'MAIL_SUBJECT_MAIL_CHANGE_CODE'=>'Change of your E-Mail adress', 'MAIL_SUBJECT_PASSWORD_COMMIT_CODE'=>'Password change request', 'MAIL_SUBJECT_PASSWORD_NEW'=>'New password', diff --git a/modules/language/Language_DE.class.php b/modules/language/Language_DE.class.php @@ -552,6 +552,14 @@ public function get() { return [ 'LOGO_REGISTER'=>'Registrierung', 'LOGO_REGISTER_TEXT'=>'Wenn sich noch nicht als Benutzer eingetragen sind, dann können Sie sich hier registrieren. Sie benötigen dazu ein gültigen E-Mail-Konto, an das ein Registrierungscode gesendet wird.', 'MAIL_CODE'=>'Bestätigungscode', +'MAIL_PASSWORD_CHANGE_SUCCESS_SUBJECT'=>'Kennwortänderung erfolgreich', +'MAIL_PASSWORD_CHANGE_SUCCESS'=>'Ihr Kennwort wurde erfolgreich geändert.', +'MAIL_NEW_LOGIN_SUBJECT'=>'Neues Login', +'MAIL_NEW_LOGIN_TEXT'=>'Guten Tag ${name}, + +Sie haben sich mit Ihrem Benutzernamen ${username} auf dem Gerät ${browser} (${platform}) neu angemeldet. Dies dient rein zu Ihrer Information. + +Sofern Sie dieses nicht waren, ändern Sie bitte umgehend Ihr Kennwort.', 'MAIL_SUBJECT_MAIL_CHANGE_CODE'=>'Änderung Ihrer E-Mail-Adresse', 'MAIL_SUBJECT_PASSWORD_COMMIT_CODE'=>'Bestaetigung fuer Kennwortänderung', 'MAIL_SUBJECT_PASSWORD_NEW'=>'Neues Kennwort', diff --git a/modules/language/Language_EN.class.php b/modules/language/Language_EN.class.php @@ -552,6 +552,14 @@ public function get() { return [ 'LOGO_REGISTER'=>'Registration', 'LOGO_REGISTER_TEXT'=>'If you do not have an user account, then feel free to register now. You need an E-Mail account, to which a registration code is sent.', 'MAIL_CODE'=>'Confirmation code', +'MAIL_PASSWORD_CHANGE_SUCCESS_SUBJECT'=>'Your password was successfully changed', +'MAIL_PASSWORD_CHANGE_SUCCESS'=>'Your password was successfully changed', +'MAIL_NEW_LOGIN_SUBJECT'=>'New login', +'MAIL_NEW_LOGIN_TEXT'=>'Hello ${name}, + +We want to inform you that you just logged in with your username ${username} on the device ${browser} (${platform}). + +If you did not do this, please change your password.', 'MAIL_SUBJECT_MAIL_CHANGE_CODE'=>'Change of your E-Mail adress', 'MAIL_SUBJECT_PASSWORD_COMMIT_CODE'=>'Password change request', 'MAIL_SUBJECT_PASSWORD_NEW'=>'New password', diff --git a/modules/language/Language_ES.class.php b/modules/language/Language_ES.class.php @@ -552,6 +552,14 @@ public function get() { return [ 'LOGO_REGISTER'=>'Enregistrement', 'LOGO_REGISTER_TEXT'=>'Si vous n\'avez pas un compte d\'utilisateur, alors se sentir libre pour s\'enregistrer maintenant. Vous avez besoin d\'un compte d\'E-mail, auquel un code d\'enregistrement est envoyé.', 'MAIL_CODE'=>'Confirmation code', +'MAIL_PASSWORD_CHANGE_SUCCESS_SUBJECT'=>'Your password was successfully changed', +'MAIL_PASSWORD_CHANGE_SUCCESS'=>'Your password was successfully changed', +'MAIL_NEW_LOGIN_SUBJECT'=>'New login', +'MAIL_NEW_LOGIN_TEXT'=>'Hello ${name}, + +We want to inform you that you just logged in with your username ${username} on the device ${browser} (${platform}). + +If you did not do this, please change your password.', 'MAIL_SUBJECT_MAIL_CHANGE_CODE'=>'Change of your E-Mail adress', 'MAIL_SUBJECT_PASSWORD_COMMIT_CODE'=>'Demande de changement de mot de passe', 'MAIL_SUBJECT_PASSWORD_NEW'=>'Nouveau mot de passe', diff --git a/modules/language/Language_FR.class.php b/modules/language/Language_FR.class.php @@ -552,6 +552,14 @@ public function get() { return [ 'LOGO_REGISTER'=>'Enregistrement', 'LOGO_REGISTER_TEXT'=>'Si vous n\'avez pas un compte d\'utilisateur, alors se sentir libre pour s\'enregistrer maintenant. Vous avez besoin d\'un compte d\'E-mail, auquel un code d\'enregistrement est envoyé.', 'MAIL_CODE'=>'Confirmation code', +'MAIL_PASSWORD_CHANGE_SUCCESS_SUBJECT'=>'Your password was successfully changed', +'MAIL_PASSWORD_CHANGE_SUCCESS'=>'Your password was successfully changed', +'MAIL_NEW_LOGIN_SUBJECT'=>'New login', +'MAIL_NEW_LOGIN_TEXT'=>'Hello ${name}, + +We want to inform you that you just logged in with your username ${username} on the device ${browser} (${platform}). + +If you did not do this, please change your password.', 'MAIL_SUBJECT_MAIL_CHANGE_CODE'=>'Change of your E-Mail adress', 'MAIL_SUBJECT_PASSWORD_COMMIT_CODE'=>'Demande de changement de mot de passe', 'MAIL_SUBJECT_PASSWORD_NEW'=>'Nouveau mot de passe', diff --git a/modules/language/Language_IT.class.php b/modules/language/Language_IT.class.php @@ -552,6 +552,14 @@ public function get() { return [ 'LOGO_REGISTER'=>'El registro', 'LOGO_REGISTER_TEXT'=>'si no tienes una cuenta del usuario, entonces se siente libre ahora colocarse. Necesitas una cuenta del E-mail, a la cual se envía un código del registro.', 'MAIL_CODE'=>'Confirmation code', +'MAIL_PASSWORD_CHANGE_SUCCESS_SUBJECT'=>'Your password was successfully changed', +'MAIL_PASSWORD_CHANGE_SUCCESS'=>'Your password was successfully changed', +'MAIL_NEW_LOGIN_SUBJECT'=>'New login', +'MAIL_NEW_LOGIN_TEXT'=>'Hello ${name}, + +We want to inform you that you just logged in with your username ${username} on the device ${browser} (${platform}). + +If you did not do this, please change your password.', 'MAIL_SUBJECT_MAIL_CHANGE_CODE'=>'Change of your E-Mail adress', 'MAIL_SUBJECT_PASSWORD_COMMIT_CODE'=>'Contraseña de la petición del cambio de la contraseña nueva', 'MAIL_SUBJECT_PASSWORD_NEW'=>'New password', diff --git a/modules/language/Language_RU.class.php b/modules/language/Language_RU.class.php @@ -552,6 +552,14 @@ public function get() { return [ 'LOGO_REGISTER'=>'Registration', 'LOGO_REGISTER_TEXT'=>'Если у вас нет учетной записи Затем стесняйтесь регистрироваться сейчас. Вам нужно E-Mail записи к которому регистрационный код, который будут направляться запросы.', 'MAIL_CODE'=>'Confirmation code', +'MAIL_PASSWORD_CHANGE_SUCCESS_SUBJECT'=>'Your password was successfully changed', +'MAIL_PASSWORD_CHANGE_SUCCESS'=>'Your password was successfully changed', +'MAIL_NEW_LOGIN_SUBJECT'=>'New login', +'MAIL_NEW_LOGIN_TEXT'=>'Hello ${name}, + +We want to inform you that you just logged in with your username ${username} on the device ${browser} (${platform}). + +If you did not do this, please change your password.', 'MAIL_SUBJECT_MAIL_CHANGE_CODE'=>'Change of your E-Mail adress', 'MAIL_SUBJECT_PASSWORD_COMMIT_CODE'=>'Запрос на изменение пароля', 'MAIL_SUBJECT_PASSWORD_NEW'=>'Новый пароль', diff --git a/modules/language/Messages.class.php b/modules/language/Messages.class.php @@ -552,6 +552,10 @@ class Messages { const LOGO_REGISTER = 'LOGO_REGISTER'; const LOGO_REGISTER_TEXT = 'LOGO_REGISTER_TEXT'; const MAIL_CODE = 'MAIL_CODE'; + const MAIL_PASSWORD_CHANGE_SUCCESS_SUBJECT = 'MAIL_PASSWORD_CHANGE_SUCCESS_SUBJECT'; + const MAIL_PASSWORD_CHANGE_SUCCESS = 'MAIL_PASSWORD_CHANGE_SUCCESS'; + const MAIL_NEW_LOGIN_SUBJECT = 'MAIL_NEW_LOGIN_SUBJECT'; + const MAIL_NEW_LOGIN_TEXT = 'MAIL_NEW_LOGIN_TEXT'; const MAIL_SUBJECT_MAIL_CHANGE_CODE = 'MAIL_SUBJECT_MAIL_CHANGE_CODE'; const MAIL_SUBJECT_PASSWORD_COMMIT_CODE = 'MAIL_SUBJECT_PASSWORD_COMMIT_CODE'; const MAIL_SUBJECT_PASSWORD_NEW = 'MAIL_SUBJECT_PASSWORD_NEW'; diff --git a/modules/language/language.yml b/modules/language/language.yml @@ -2824,6 +2824,28 @@ LOGO_REGISTER_TEXT: MAIL_CODE: de: Bestätigungscode en: Confirmation code +MAIL_PASSWORD_CHANGE_SUCCESS_SUBJECT: + de: Kennwortänderung erfolgreich + en: Your password was successfully changed +MAIL_PASSWORD_CHANGE_SUCCESS: + de: Ihr Kennwort wurde erfolgreich geändert. + en: Your password was successfully changed +MAIL_NEW_LOGIN_SUBJECT: + de: Neues Login + en: New login +MAIL_NEW_LOGIN_TEXT: + de: | + Guten Tag ${name}, + + Sie haben sich mit Ihrem Benutzernamen ${username} auf dem Gerät ${browser} (${platform}) neu angemeldet. Dies dient rein zu Ihrer Information. + + Sofern Sie dieses nicht waren, ändern Sie bitte umgehend Ihr Kennwort. + en: | + Hello ${name}, + + We want to inform you that you just logged in with your username ${username} on the device ${browser} (${platform}). + + If you did not do this, please change your password. MAIL_SUBJECT_MAIL_CHANGE_CODE: de: Änderung Ihrer E-Mail-Adresse en: Change of your E-Mail adress