Преглед на файлове

Pouvoir modifier son mot de passe dans le profil

master
keun преди 7 години
родител
ревизия
712a8f5203
променени са 3 файла, в които са добавени 84 реда и са изтрити 10 реда
  1. +54
    -2
      common/models/User.php
  2. +21
    -3
      frontend/controllers/UserController.php
  3. +9
    -5
      frontend/views/user/update.php

+ 54
- 2
common/models/User.php Целия файл

@@ -30,6 +30,10 @@ class User extends ActiveRecord implements IdentityInterface
const STATUS_BOULANGER = 11;
const STATUS_ADMIN = 13;

var $password_old ;
var $password_new ;
var $password_new_confirm ;
/**
* @inheritdoc
*/
@@ -54,7 +58,7 @@ class User extends ActiveRecord implements IdentityInterface
public function rules()
{
return [
['confiance','default','value'=>0],
['confiance','default','value'=>1],
[['no_mail','mail_prod_lundi','mail_prod_mardi','mail_prod_mercredi','mail_prod_jeudi','mail_prod_vendredi','mail_prod_samedi','mail_prod_dimanche'],'boolean'],
[['nom','prenom','telephone','adresse'], 'string'],
[['nom','prenom'],'required','message'=> 'Ce champs ne peut être vide'],
@@ -62,10 +66,55 @@ class User extends ActiveRecord implements IdentityInterface
['email','verifyEmail'],
['status', 'default', 'value' => self::STATUS_ACTIVE],
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED, self::STATUS_ADMIN,self::STATUS_BOULANGER ]],
[['date_derniere_connexion'],'safe'],
['password_old','verifyPasswordOld'],
['password_new','verifyPasswordNew'],
['password_new_confirm','verifyPasswordNewConfirm'],
[['date_derniere_connexion','password_old','password_new','password_new_confirm','password_hash'],'safe'],
];
}
public function verifyPasswordOld($attribute,$params)
{
if(strlen($this->password_old))
{
if(!$this->validatePassword($this->password_old))
{
$this->addError($attribute, 'Mot de passe invalide.') ;
}
}
if(!strlen($this->password_old) && (strlen($this->password_new) || strlen($this->password_new_confirm)))
{
$this->addError($attribute, 'Ce champs ne peut être vide') ;
}
if(!strlen($this->password_new) && (strlen($this->password_old) || strlen($this->password_new_confirm)))
{
$this->addError('password_new', 'Ce champs ne peut être vide') ;
}
if(!strlen($this->password_new_confirm) && (strlen($this->password_old) || strlen($this->password_new)))
{
$this->addError('password_new_confirm', 'Ce champs ne peut être vide') ;
}
}

public function verifyPasswordNew($attribute,$params)
{
if(strlen($this->password_new) < 6)
{
$this->addError($attribute, 'Votre mot de passe doit comporter au moins 6 caractères.') ;
}
}
public function verifyPasswordNewConfirm($attribute,$params)
{
if($this->password_new != $this->password_new_confirm)
{
$this->addError($attribute, 'Les deux mots de passe doivent être identiques') ;
}
}
public function verifyEmail($attribute,$params) {
$user = User::find()->where("email LIKE :email AND id != :id")->params(array(':email'=>'%'.$this->email.'%', ':id'=>$this->id))->one() ;
@@ -253,6 +302,9 @@ class User extends ActiveRecord implements IdentityInterface
'mail_prod_vendredi' => 'Vendredi',
'mail_prod_samedi' => 'Samedi',
'mail_prod_dimanche' => 'Dimanche',
'password_old' => 'Ancien mot de passe',
'password_new' => 'Nouveau mot de passe',
'password_new_confirm' => 'Confirmation du nouveau mot de passe',
];
}

+ 21
- 3
frontend/controllers/UserController.php Целия файл

@@ -49,24 +49,42 @@ class UserController extends Controller
{
$model = $this->findModel(Yii::$app->user->identity->id);

if ($model->load(Yii::$app->request->post())) {
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
// l'utilisateur ne peut pas changer d'adresse email
$old_model = $this->findModel(Yii::$app->user->identity->id) ;
$model->email = $old_model->email ;
// modification du mot de passe
if(strlen($model->password_new))
{
//$model->setPassword($model->password_new) ;
$model->password_hash = Yii::$app->security->generatePasswordHash($model->password_new);
$model->password_old = '' ;
$model->password_new = '' ;
$model->password_new_confirm = '' ;
}
$model->save() ;
Yii::$app->session->setFlash('success','Votre profil a bien été modifié.') ;
return $this->render('update', [
'model' => $model,
'edit_ok' => true
]);
} else {
if(!$model->validate())
{
Yii::$app->session->setFlash('error','Le formulaire comporte des erreurs.') ;
}
return $this->render('update', [
'model' => $model,
]);
}
}

public function actionCredit()

+ 9
- 5
frontend/views/user/update.php Целия файл

@@ -12,23 +12,27 @@ $this->title = 'Mon profil' ;
<div id="profil-user" class="user-update">

<h1 class="title-systeme-commande"><span class="glyphicon glyphicon-user"></span> Mon profil</h1>
<?php if(isset($edit_ok)): ?>
<div class="alert alert-success">
Votre profil a bien été modifié.
</div>
<?php endif; ?>
<div class="user-form">

<?php $form = ActiveForm::begin([
'enableClientScript' => false
]); ?>
<h2>Informations</h2>
<?= $form->field($model, 'nom')->textInput() ?>
<?= $form->field($model, 'prenom')->textInput() ?>
<?= $form->field($model, 'telephone')->textInput() ?>
<?= $form->field($model, 'email')->textInput(['readonly' => true]); ?>
<?= $form->field($model, 'adresse')->textarea() ?>
<h2>Mot de passe</h2>
<p>Renseignez les champs ci-dessous si vous souhaitez modifier votre mot de passe.</p>
<?= $form->field($model, 'password_old')->passwordInput() ?>
<?= $form->field($model, 'password_new')->passwordInput() ?>
<?= $form->field($model, 'password_new_confirm')->passwordInput() ?>
<div class="clr"></div>
<div class="form-group">

Loading…
Отказ
Запис