Merge branch 'changepassword_bugfix' into 'boutique-sable'
update changepassword method for crmclient version See merge request service-web-lab/boutique-cnc-sable!8
This commit is contained in:
commit
06e43fccf8
5 changed files with 185 additions and 13 deletions
|
|
@ -3,8 +3,10 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\CustomerRegisterRequest;
|
||||
use App\Http\Requests\CustomerUpdatePassword;
|
||||
use App\Http\Requests\LoginRequest;
|
||||
use App\Http\Requests\UpdateInfosRequest;
|
||||
use App\Lib\Utils;
|
||||
use App\Mail\PasswordResetMail;
|
||||
use App\Mail\RegisterConfirmMail;
|
||||
use App\Models\Customers;
|
||||
|
|
@ -400,23 +402,44 @@ class CustomerController extends Controller
|
|||
/**
|
||||
* changement de mot de passe depuis le profil
|
||||
*
|
||||
* @param Request $request
|
||||
* @param CustomerUpdatePassword $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function changePasswordWhenAuthenticated(Request $request)
|
||||
public function changePasswordWhenAuthenticated(CustomerUpdatePassword $request)
|
||||
{
|
||||
$request->validate([
|
||||
'password' => 'required|min:8|confirmed|max:255'
|
||||
]);
|
||||
/** @var \App\Models\Customers */
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
$crm = app('crmApi');
|
||||
$customer = $crm->changePwdCustomer(Auth::guard('customer')->user()->crm_id, $request->password);
|
||||
/** @var \LDC\LDCCRM\CrmApiV2 */
|
||||
$crm = app('crmAPI');
|
||||
|
||||
if ($customer->status === "OK") {
|
||||
return back()->with('success', __("Modifications enregistrés !"));
|
||||
} else {
|
||||
return back()->withErrors(__("Une erreur est survenue, merci de réessayer ultérieurement."));
|
||||
}
|
||||
// Test old password.
|
||||
try {
|
||||
// Ne devrait pas survenir, $crm->login throws ApiError::authFailed().
|
||||
if (!$crm->login($customer->email, $request->password_old)) {
|
||||
// Mauvais identifiants.
|
||||
return back()->withErrors('L\'ancien mot de passe ne correspond pas.');
|
||||
}
|
||||
|
||||
$crmCustomer = $crm->getCustomer($customer->hashcode);
|
||||
|
||||
$crmCustomer->password = $request->password;
|
||||
$crmCustomer->save();
|
||||
} catch (ApiErrorException $e) {
|
||||
if ($e->getApiError()->equals(ApiError::authFailed())) {
|
||||
return back()->withErrors('L\'ancien mot de passe ne correspond pas.');
|
||||
}
|
||||
Utils::sendEmailErrorManually($e);
|
||||
// Une erreur critique est survenue avec la CRM.
|
||||
return back()->withErrors('Une erreur est survenue, merci de réessayer ultérieurement.');
|
||||
} catch (\TypeError | CrmException $e) {
|
||||
Utils::sendEmailErrorManually($e);
|
||||
// Une erreur critique est survenue avec la CRM.
|
||||
return back()->withErrors('Une erreur est survenue, merci de réessayer ultérieurement.');
|
||||
} catch (ValidationException $e) {
|
||||
return back()->withErrors(sprintf('Nouveau mot de passe : %s', $e->getMessage()));
|
||||
} //end try
|
||||
return back()->with('success', __("Modifications enregistrés !"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
40
app/Http/Requests/CustomerUpdatePassword.php
Normal file
40
app/Http/Requests/CustomerUpdatePassword.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class CustomerUpdatePassword extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return \auth('customer')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'password_old' => 'required',
|
||||
'password' => [
|
||||
'required', 'confirmed', 'min:8', 'max:255',
|
||||
Password::min(8)
|
||||
->mixedCase()
|
||||
->letters()
|
||||
->numbers()
|
||||
->symbols()
|
||||
->uncompromised()
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace App\Lib;
|
||||
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Throwable;
|
||||
|
||||
class Utils
|
||||
{
|
||||
/**
|
||||
|
|
@ -22,4 +25,100 @@ class Utils
|
|||
}
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually send an exception to team instead of going trough the error handler
|
||||
* (requires package kwaadpepper/exception-handler)
|
||||
*
|
||||
* @param Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
public static function sendEmailErrorManually(Throwable $e)
|
||||
{
|
||||
Mail::send([
|
||||
'html' => 'exception-handler::emails.exception',
|
||||
'text' => 'exception-handler::emails.exception-plain'
|
||||
], [
|
||||
'appName' => config('app.name'),
|
||||
'code' => $e->getCode(),
|
||||
'line' => $e->getLine(),
|
||||
'ename' => \get_class($e),
|
||||
'emessage' => self::getAnonymizedMessage($e->getMessage()),
|
||||
'file' => str_replace(\realpath(\sprintf('%s/../', \app_path())), '', $e->getFile()),
|
||||
'stackTrace' => self::getAnonymizedStackTrace($e),
|
||||
'uri' => app()->runningInConsole() ?
|
||||
'CONSOLE' : (
|
||||
(request() and request()->fullUrl()) ?
|
||||
request()->fullUrl() : 'none')
|
||||
], function ($m) {
|
||||
/** @var \Illuminate\Mail\Message $m */
|
||||
$m->to(
|
||||
config('mail.contactsList.serviceweb'),
|
||||
sprintf('%s Exception Handler', config('app.name'))
|
||||
)->subject('Need help !, an error occured in your application, please check Logs ASAP');
|
||||
});
|
||||
Log::alert(sprintf('Envoie d\'une erreur par mail : %s', json_encode($e)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Anonymize at least Sql queries
|
||||
*
|
||||
* @param string $message
|
||||
* @return string
|
||||
*/
|
||||
private static function getAnonymizedMessage(string $message): string
|
||||
{
|
||||
$message = \preg_replace('/^(.*)( \(SQL:.*\))$/', '$1', $message) ?? $message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Anonymize stack trace
|
||||
*
|
||||
* @param Throwable $e
|
||||
* @return string
|
||||
*/
|
||||
private static function getAnonymizedStackTrace(Throwable $e): string
|
||||
{
|
||||
$projectPath = \realpath(\sprintf('%s/../', \app_path()));
|
||||
$traceStack = $e->getTrace();
|
||||
$traceStr = '';
|
||||
$maxStackStage = 0;
|
||||
foreach ($traceStack as $stackStage => $stack) {
|
||||
$maxStackStage = $stackStage;
|
||||
$traceStr .= \sprintf(
|
||||
'#%s %s(%d): ',
|
||||
$stackStage,
|
||||
str_replace($projectPath, '', $stack['file']),
|
||||
$stack['line']
|
||||
);
|
||||
$traceStr .= "{$stack['class']}->{$stack['function']}(";
|
||||
$traceArgs = '';
|
||||
if (isset($stack['args'])) {
|
||||
$argsCount = count($stack['args']);
|
||||
for ($i = 0; $i < $argsCount; $i++) {
|
||||
$type = \gettype($stack['args'][$i]);
|
||||
switch ($type) {
|
||||
case 'object':
|
||||
$traceArgs .= sprintf('Object(%s)', \get_class($stack['args'][$i]));
|
||||
break;
|
||||
case 'array':
|
||||
$traceArgs .= sprintf('Array(%d)', \count($stack['args'][$i]));
|
||||
break;
|
||||
case 'string':
|
||||
$traceArgs .= sprintf('String(%d)', \strlen($stack['args'][$i]));
|
||||
break;
|
||||
default:
|
||||
$traceArgs .= \gettype($stack['args'][$i]);
|
||||
}
|
||||
$traceArgs .= ($i !== ($argsCount - 1) ? ',' : '');
|
||||
}
|
||||
$traceStr .= $traceArgs;
|
||||
} //end if
|
||||
$traceStr .= ")\n";
|
||||
} //end foreach
|
||||
$maxStackStage++;
|
||||
$traceStr .= "#$maxStackStage {main}";
|
||||
return $traceStr;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,6 +135,15 @@
|
|||
<form method="post" action="{{ route('account.change-password') }}" class="mx-auto">
|
||||
@csrf
|
||||
<div class="row">
|
||||
<div class="col d-flex justify-content-center align-items-center text-center p-0">
|
||||
<input class="w-50 form-control rounded-4 border-dark"
|
||||
type="password"
|
||||
name="password_old"
|
||||
placeholder="Ancien mot de passe"
|
||||
value="{{ old('password_old') }}" required/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-2">
|
||||
<div class="col d-flex justify-content-center align-items-center text-center p-0">
|
||||
<input class="w-50 form-control rounded-4 border-dark"
|
||||
type="password"
|
||||
|
|
|
|||
|
|
@ -148,7 +148,8 @@ img {
|
|||
.auth {
|
||||
&-login {
|
||||
form {
|
||||
width: 25rem;
|
||||
width:100%
|
||||
max-width: 25rem;
|
||||
|
||||
.form-control {
|
||||
width: 20rem;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue