Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions modules/authloginpass/controllers/passwordEdit.classic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* @author Laurent Jouanneau <laurent@jelix.org>
* @copyright 2007-2024 Laurent Jouanneau
*
* @link https://jelix.org
* @licence MIT
*/

use Jelix\Authentication\LoginPass\Config as LoginPassConfig;

class passwordEditCtrl extends jController
{
public $pluginParams = array(
'*' => array('auth.required' => true),
);

protected function checkLoginPassConfAllowEdit()
{
$loginPassConfig = new LoginPassConfig(\jApp::config());
if (!$loginPassConfig->isPasswordChangeEnabled()) {

throw new jHttp403ForbiddenException();
}
}

public function show()
{
$this->checkLoginPassConfAllowEdit();
$rep = $this->getResponse('html');
$form = jForms::get('password_edit');
if ($form == null) {
$form = jForms::create('password_edit');
}
$tpl = new jTpl();
$tpl->assign('form', $form);
$rep->body->assign('MAIN', $tpl->fetch('password_edit'));

return $rep;
}

public function save()
{
$this->checkLoginPassConfAllowEdit();
$form = jForms::fill('password_edit');
if ($form == null) {
return $this->redirect('passwordEdit:show');
}
if (!$form->check()) {
return $this->redirect('passwordEdit:show');
}
$currentPassword = $form->getData('current_password');
/** @var \loginpassIdentityProvider $idp */
$idp = jAuthentication::manager()->getIdpById('loginpass');
/** @var \Jelix\Authentication\LoginPass\Manager $lpManager */
$lpManager = $idp->getManager();
$login = jAuthentication::getCurrentUser()->getLogin();
$backEnd = $lpManager->getBackendHavingUser($login);
$isCurrentPassValid = $backEnd->verifyAuthentication($login, $currentPassword);

if (!$isCurrentPassValid) {
$form->setErrorOn('current_password', jLocale::get('password.form.create.error.badcurrentpwd'));

return $this->redirect('passwordEdit:show');
}
$backEnd->changePassword($login, $form->getData('new_password'));
return $this->getResponse('html');
}
}
5 changes: 5 additions & 0 deletions modules/authloginpass/events.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<events xmlns="http://jelix.org/ns/events/1.0">
<listener name="Jelix\Authentication\LoginPass\ProfileEventListener">
<event name="ProfileViewPageEvent" />
</listener>
</events>
18 changes: 18 additions & 0 deletions modules/authloginpass/forms/password_edit.form.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://jelix.org/ns/forms/1.1">


<secret ref="current_password" required="true" minlength="2" maxlength="120">
<label locale="authloginpass~password.form.change.current.password.label" />
</secret>
<secret ref="new_password" required="true" minlength="12" maxlength="120">
<label locale="authloginpass~password.form.change.password.label" />
<help locale="authloginpass~password.form.password.help" />
<confirm locale="authloginpass~password.form.password.confirm" />
</secret>

<submit ref="pchg_submit">
<label locale="authloginpass~password.form.change.submit" />
</submit>

</form>
34 changes: 34 additions & 0 deletions modules/authloginpass/lib/ProfileEventListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Jelix\Authentication\LoginPass;

use jAuthentication;
use jEventListener;
use jUrl;
use jLocale;
use Jelix\Authentication\Account\ProfileViewPageEvent;
use Jelix\Authentication\LoginPass\Config as LoginPassConfig;

class ProfileEventListener extends jEventListener
{
public function onProfileViewPageEvent(ProfileViewPageEvent $event)
{
$session = jAuthentication::session();
$idp = $session->getIdentityProviderId();
if($idp == 'loginpass') {
$loginPassConfig = new LoginPassConfig(\jApp::config());
// does login pass conf allow password change ?
if($loginPassConfig->isPasswordChangeEnabled()) {
/** @var \loginpassIdentityProvider $idp */
$idp = jAuthentication::manager()->getIdpById('loginpass');
/** @var \Jelix\Authentication\LoginPass\Manager $lpManager */
$lpManager = $idp->getManager();
$login = jAuthentication::getCurrentUser()->getLogin();
// check if the backend allow passwordChange
if($lpManager->canChangePassword($login)) {
$event->addContent('<a href="'. jUrl::get('authloginpass~passwordEdit:show').'" class="btn btn-primary">'.jLocale::get('authloginpass~password.btn.password.edit').'</a>', 6);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@ reset.cmdline.mail.undefined = User's email is not defined.
reset.cmdline.error = There was an error during the password resetting.
reset.cmdline.help.usage = usage: php cmdline.php jcommunity~reset_pass:reset login
reset.cmdline.help.description = Send an email with a password reset link to a user.
reset.cmdline.help.parameter.login = the user's login
reset.cmdline.help.parameter.login = the user's login

btn.password.edit=Modify your password
2 changes: 2 additions & 0 deletions modules/authloginpass/locales/fr_FR/password.UTF-8.properties
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ reset.cmdline.error = Une erreur a eu lieu pendant la réinitialisation du mot d
reset.cmdline.help.usage = usage: php cmdline.php jcommunity~reset_pass:reset login
reset.cmdline.help.description = Envoie un lien de réinitialisation de mot de passe par mail a un utilisateur.
reset.cmdline.help.parameter.login = le login de l'utilisateur

btn.password.edit=Modifier votre mot de passe
11 changes: 11 additions & 0 deletions modules/authloginpass/templates/password_edit.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div>
<h1>{@authloginpass~password.form.change.title@}</h1>

{@authloginpass~password.form.change.text.html@}

{formfull $form, 'authloginpass~passwordEdit:save', [], 'adminlte', array(
'plugins' => array(
'new_password' => 'passwordeditor_html'
))}

</div>
5 changes: 4 additions & 1 deletion modules/authloginpass/urls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
<url pathinfo="/signin/reset/code/:request_id/password" action="password_reset:resetpassword" />
<url pathinfo="/signin/reset/code/:request_id/save" action="password_reset:save" />
<url pathinfo="/signin/reset/changed" action="password_reset:changed" />
</suburls>

<url pathinfo="/password/reset/show" action="passwordEdit:show" />
<url pathinfo="/password/reset/save" action="passwordEdit:save" />
</suburls>
2 changes: 2 additions & 0 deletions test/testapp/app/system/mainconfig.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@
backends[]=inifile
after_login="adminui~default:index"
loginResponse=htmllogin
;set to false to deny password modification
;passwordChangeEnabled=false

[loginpass:common]
passwordHashAlgo=1
Expand Down