-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
client html side of user password change #152
base: master
Are you sure you want to change the base?
Changes from all commits
05f00b4
079280d
8b6fb55
824ed10
3f60921
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ client/html/tests/tmp | |
*.junit.xml | ||
*.log | ||
*.ser | ||
|
||
.idea | ||
vendor |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,264 @@ | ||
<?php | ||
|
||
namespace Aimeos\Client\Html\Account\Profile\Account; | ||
|
||
use Illuminate\Support\Facades\Validator; | ||
use Laravel\Fortify\Rules\Password; | ||
use Laravel\Jetstream\Jetstream; | ||
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No Laravel specific code is possible |
||
|
||
/** | ||
* Default implementation of acount profile account HTML client. | ||
* | ||
* @package Client | ||
* @subpackage Html | ||
*/ | ||
class Standard | ||
extends \Aimeos\Client\Html\Common\Client\Summary\Base | ||
implements \Aimeos\Client\Html\Common\Client\Factory\Iface | ||
{ | ||
|
||
/** client/html/account/profile/account/subparts | ||
* List of HTML sub-clients rendered within the account profile account section | ||
* | ||
* The output of the frontend is composed of the code generated by the HTML | ||
* clients. Each HTML client can consist of serveral (or none) sub-clients | ||
* that are responsible for rendering certain sub-parts of the output. The | ||
* sub-clients can contain HTML clients themselves and therefore a | ||
* hierarchical tree of HTML clients is composed. Each HTML client creates | ||
* the output that is placed inside the container of its parent. | ||
* | ||
* At first, always the HTML code generated by the parent is printed, then | ||
* the HTML code of its sub-clients. The account of the HTML sub-clients | ||
* determines the account of the output of these sub-clients inside the parent | ||
* container. If the configured list of clients is | ||
* | ||
* array( "subclient1", "subclient2" ) | ||
* | ||
* you can easily change the account of the output by readdressing the subparts: | ||
* | ||
* client/html/<clients>/subparts = array( "subclient1", "subclient2" ) | ||
* | ||
* You can also remove one or more parts if they shouldn't be rendered: | ||
* | ||
* client/html/<clients>/subparts = array( "subclient1" ) | ||
* | ||
* As the clients only generates structural HTML, the layout defined via CSS | ||
* should support adding, removing or readdressing content by a fluid like | ||
* design. | ||
* | ||
* @param array List of sub-client names | ||
* @since 2019.07 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update |
||
* @category Developer | ||
*/ | ||
private $subPartPath = 'client/html/account/profile/account/subparts'; | ||
private $subPartNames = []; | ||
|
||
/** | ||
* Returns the list of sub-client names configured for the client. | ||
* | ||
* @return array List of HTML client names | ||
*/ | ||
protected function getSubClientNames() : array | ||
{ | ||
return $this->getContext()->getConfig()->get( $this->subPartPath, $this->subPartNames ); | ||
} | ||
|
||
/** | ||
* Returns the sub-client given by its name. | ||
* | ||
* @param string $type Name of the client type | ||
* @param string|null $name Name of the sub-client (Default if null) | ||
* @return \Aimeos\Client\Html\Iface Sub-client object | ||
* @throws \Aimeos\Client\Html\Exception | ||
*/ | ||
public function getSubClient( string $type, string $name = null ) : \Aimeos\Client\Html\Iface | ||
{ | ||
/** client/html/account/profile/account/decorators/excludes | ||
* Excludes decorators added by the "common" option from the account profile account html client | ||
* | ||
* Decorators extend the functionality of a class by adding new aspects | ||
* (e.g. log what is currently done), executing the methods of the underlying | ||
* class only in certain conditions (e.g. only for logged in users) or | ||
* modify what is returned to the caller. | ||
* | ||
* This option allows you to remove a decorator added via | ||
* "client/html/common/decorators/default" before they are wrapped | ||
* around the html client. | ||
* | ||
* client/html/account/profile/account/decorators/excludes = array( 'decorator1' ) | ||
* | ||
* This would remove the decorator named "decorator1" from the list of | ||
* common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via | ||
* "client/html/common/decorators/default" to the html client. | ||
* | ||
* @param array List of decorator names | ||
* @since 2019.07 | ||
* @category Developer | ||
* @see client/html/common/decorators/default | ||
* @see client/html/account/profile/account/decorators/global | ||
* @see client/html/account/profile/account/decorators/local | ||
*/ | ||
|
||
/** client/html/account/profile/account/decorators/global | ||
* Adds a list of globally available decorators only to the account profile account html client | ||
* | ||
* Decorators extend the functionality of a class by adding new aspects | ||
* (e.g. log what is currently done), executing the methods of the underlying | ||
* class only in certain conditions (e.g. only for logged in users) or | ||
* modify what is returned to the caller. | ||
* | ||
* This option allows you to wrap global decorators | ||
* ("\Aimeos\Client\Html\Common\Decorator\*") around the html client. | ||
* | ||
* client/html/account/profile/account/decorators/global = array( 'decorator1' ) | ||
* | ||
* This would add the decorator named "decorator1" defined by | ||
* "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client. | ||
* | ||
* @param array List of decorator names | ||
* @since 2019.07 | ||
* @category Developer | ||
* @see client/html/common/decorators/default | ||
* @see client/html/account/profile/account/decorators/excludes | ||
* @see client/html/account/profile/account/decorators/local | ||
*/ | ||
|
||
/** client/html/account/profile/account/decorators/local | ||
* Adds a list of local decorators only to the account profile account html client | ||
* | ||
* Decorators extend the functionality of a class by adding new aspects | ||
* (e.g. log what is currently done), executing the methods of the underlying | ||
* class only in certain conditions (e.g. only for logged in users) or | ||
* modify what is returned to the caller. | ||
* | ||
* This option allows you to wrap local decorators | ||
* ("\Aimeos\Client\Html\Account\Decorator\*") around the html client. | ||
* | ||
* client/html/account/profile/account/decorators/local = array( 'decorator2' ) | ||
* | ||
* This would add the decorator named "decorator2" defined by | ||
* "\Aimeos\Client\Html\Account\Decorator\Decorator2" only to the html client. | ||
* | ||
* @param array List of decorator names | ||
* @since 2019.07 | ||
* @category Developer | ||
* @see client/html/common/decorators/default | ||
* @see client/html/account/profile/account/decorators/excludes | ||
* @see client/html/account/profile/account/decorators/global | ||
*/ | ||
|
||
return $this->createSubClient( 'account/profile/account/' . $type, $name ); | ||
} | ||
|
||
/** | ||
* Returns the HTML code for insertion into the body. | ||
* | ||
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page | ||
* @return string HTML code | ||
* @throws \Aimeos\MW\View\Exception|\Aimeos\Client\Html\Exception | ||
*/ | ||
public function getBody(string $uid = ''): string | ||
{ | ||
$view = $this->getView(); | ||
|
||
$html = ''; | ||
foreach( $this->getSubClients() as $subclient ) { | ||
$html .= $subclient->setView( $view )->getBody( $uid ); | ||
} | ||
$view->accountBody = $html; | ||
|
||
/** client/html/account/profile/account/template-body | ||
* Relative path to the HTML body template of the account profile account client. | ||
* | ||
* The template file contains the HTML code and processing instructions | ||
* to generate the result shown in the body of the frontend. The | ||
* configuration string is the path to the template file relative | ||
* to the templates directory (usually in client/html/templates). | ||
* | ||
* You can overwrite the template file configuration in extensions and | ||
* provide alternative templates. These alternative templates should be | ||
* named like the default one but with the string "standard" replaced by | ||
* an unique name. You may use the name of your project for this. If | ||
* you've implemented an alternative client class as well, "standard" | ||
* should be replaced by the name of the new class. | ||
* | ||
* @param string Relative path to the template creating code for the HTML page body | ||
* @since 2019.07 | ||
* @category Developer | ||
* @see client/html/account/profile/account/template-header | ||
*/ | ||
$tplconf = 'client/html/account/profile/account/template-body'; | ||
$default = 'account/profile/account-body-standard'; | ||
|
||
return $view->render( $view->config( $tplconf, $default ) ); | ||
} | ||
|
||
/** | ||
* Processes the input, e.g. store given values. | ||
* | ||
* A view must be available and this method doesn't generate any output | ||
* besides setting view variables if necessary. | ||
* @throws \Aimeos\Client\Html\Exception|\Aimeos\Controller\Frontend\Exception | ||
*/ | ||
public function process() | ||
{ | ||
$view = $this->getView(); | ||
|
||
if( !$view->param( 'account/save' , false) ) { | ||
parent::process(); | ||
return; | ||
} | ||
|
||
/** @var \Aimeos\Controller\Frontend\Customer\Standard $cntl */ | ||
$cntl = \Aimeos\Controller\Frontend::create( $this->getContext(), 'customer' ); | ||
$oldPassword = $cntl->get()->getPassword(); | ||
$values = $view->param('account', []); | ||
|
||
$isNew = $values['customer.newpassword'] !== $values['customer.oldpassword']; | ||
$confirmed = $values['customer.newpassword'] === $values['customer.confirmnewpassword']; | ||
|
||
$errors = []; | ||
|
||
$isValid = true; | ||
try { | ||
Validator::make([ | ||
'password' => $values['customer.newpassword'], | ||
'password_confirmation' => $values['customer.confirmnewpassword'] | ||
], [ | ||
'password' => ['required', 'string', new Password, 'confirmed'] | ||
])->validate(); | ||
Comment on lines
+224
to
+229
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't use Laravel specific code in HTML clients. This won't work in other integrations. |
||
} catch (\Exception $ex) { | ||
$isValid = false; | ||
$errors['passwordRules'] = "The password does not meet the password requirements!"; | ||
} | ||
|
||
if ($isValid) { | ||
/** is the password realy new? */ | ||
if (!$isNew) { | ||
$errors['isNew'] = "The given password is not new!"; | ||
} | ||
Comment on lines
+236
to
+239
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a password isn't new doesn't matter for the customer so we could remove that |
||
|
||
/** does the confirm password is the same? */ | ||
if (!$confirmed) { | ||
$errors["confirm"] = "New passwords doesnt match!"; | ||
} | ||
|
||
$cntl = $cntl->add($values); | ||
|
||
} | ||
/** if the pasword is new and confirmed, but is not changed, the given old password must be wrong */ | ||
if ($isValid && $isNew && $confirmed && $oldPassword === $cntl->get()->getPassword() ) { | ||
$errors['oldPassword'] = "Wrong password!"; | ||
} | ||
|
||
$view->passwordChanged = count(array_keys($errors)) === 0; | ||
|
||
if (count(array_keys($errors)) > 0) { | ||
$view->passwordErrors = $errors; | ||
} else { | ||
$cntl->store(); | ||
} | ||
|
||
parent::process(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change that to
Aimeos\Client\Html\Account\Profile\Password
instead?