add user CRUD
This commit is contained in:
67
backend/models/UserCreate.php
Normal file
67
backend/models/UserCreate.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
use common\models\User;
|
||||
|
||||
class UserCreate extends User{
|
||||
|
||||
public $password_plain;
|
||||
public $password_repeat;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['username','email','password_plain','password_repeat'], 'required' ],
|
||||
['email' ,'email' ],
|
||||
['email' ,'unique' ],
|
||||
['username' ,'unique' ],
|
||||
[['password_plain' ,'password_repeat'] ,'string','min' =>6 ],
|
||||
[['password_repeat'] ,'validatePasswordRepeat' ]
|
||||
];
|
||||
}
|
||||
|
||||
public function validatePasswordRepeat($attribute,$params){
|
||||
|
||||
if ( !$this->hasErrors()){
|
||||
if ( $this->password_plain != $this->password_repeat ){
|
||||
$this->addError($attribute, Yii::t('app', 'Jelszó és jelszó újra nem egyezik!') );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function attributeLabels(){
|
||||
return [
|
||||
|
||||
'email' =>'E-mail',
|
||||
'username' =>'Felhasználónév',
|
||||
'created_at' =>'Létrehozás dátuma',
|
||||
'password_plain' => Yii::t('app','Jelszó'),
|
||||
'password_repeat' => Yii::t('app','Jelszó újra'),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public function beforeSave($insert){
|
||||
if ( parent::beforeSave($insert)){
|
||||
if ( $insert ){
|
||||
$this->setPassword($this->password_plain);
|
||||
$this->generateAuthKey();
|
||||
return true;
|
||||
}
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function afterSave($insert, $changedAttributes){
|
||||
parent::afterSave($insert, $changedAttributes);
|
||||
// $am = Yii::$app->authManager;
|
||||
// $role = $am->getRole('admin');
|
||||
// Yii::$app->authManager->assign($role, $this->id);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user