assign trainers to user; add email to jwt token
This commit is contained in:
@@ -9,9 +9,10 @@ class UserCreate extends User{
|
||||
public $password_plain;
|
||||
public $password_repeat;
|
||||
public $selected_accounts = [];
|
||||
|
||||
public $selected_trainers = [];
|
||||
|
||||
public $role;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@@ -25,28 +26,34 @@ class UserCreate extends User{
|
||||
}
|
||||
}
|
||||
],
|
||||
['selected_trainers',function ($attribute, $params) {
|
||||
if (!is_array($this->$attribute)) {
|
||||
$this->addError($attribute, 'Invalid array');
|
||||
}
|
||||
}
|
||||
],
|
||||
['email' ,'email' ],
|
||||
['email' ,'unique' ],
|
||||
['username' ,'unique' ],
|
||||
[['password_plain' ,'password_repeat'] ,'string','min' =>6 ],
|
||||
[['password_repeat'] ,'validatePasswordRepeat' ],
|
||||
|
||||
|
||||
[['role'], 'required'],
|
||||
[['role'], 'string', 'max' => 20],
|
||||
['status', 'default', 'value' => self::STATUS_ACTIVE],
|
||||
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
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 [
|
||||
'status' => 'Státusz',
|
||||
@@ -55,10 +62,10 @@ class UserCreate extends User{
|
||||
'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 ){
|
||||
@@ -70,12 +77,12 @@ class UserCreate extends User{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function afterSave($insert, $changedAttributes){
|
||||
parent::afterSave($insert, $changedAttributes);
|
||||
parent::afterSave($insert, $changedAttributes);
|
||||
$am = Yii::$app->authManager;
|
||||
$role = $am->getRole($this->role);
|
||||
Yii::$app->authManager->assign($role, $this->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,9 +9,10 @@ class UserUpdate extends User {
|
||||
public $password_plain;
|
||||
public $password_repeat;
|
||||
public $selected_accounts = [];
|
||||
public $selected_trainers = [];
|
||||
|
||||
public $role;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @formatter:off
|
||||
@@ -21,25 +22,59 @@ class UserUpdate extends User {
|
||||
return [
|
||||
[['username','email'], 'required' ],
|
||||
['email' ,'email' ],
|
||||
['email' ,'unique' , 'targetClass' => User::className(), 'targetAttribute' => 'email'],
|
||||
['username' ,'unique', 'targetClass' => User::className(), 'targetAttribute' => 'username'],
|
||||
// ['email' ,'unique' , 'targetClass' => User::className(), 'targetAttribute' => 'email'],
|
||||
// ['username' ,'unique', 'targetClass' => User::className(), 'targetAttribute' => 'username'],
|
||||
[['password_plain' ,'password_repeat'] ,'string','min' =>6 ],
|
||||
[['password_repeat'] ,'validatePasswordRepeat' ],
|
||||
[['username'] ,'validateUsername' ],
|
||||
[['email'] ,'validateEmail' ],
|
||||
['selected_accounts',function ($attribute, $params) {
|
||||
if (!is_array($this->$attribute)) {
|
||||
$this->addError($attribute, 'Invalid array');
|
||||
}
|
||||
}
|
||||
],
|
||||
['selected_trainers',function ($attribute, $params) {
|
||||
if (!is_array($this->$attribute)) {
|
||||
$this->addError($attribute, 'Invalid array');
|
||||
}
|
||||
}
|
||||
],
|
||||
[['role'], 'required'],
|
||||
[['role'], 'string', 'max' => 20],
|
||||
|
||||
|
||||
['status', 'default', 'value' => self::STATUS_ACTIVE],
|
||||
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function validateEmail($attribute, $params){
|
||||
/** @var User $user */
|
||||
$user = User::find()
|
||||
->andWhere(['email' => $this->email])->one();
|
||||
|
||||
if (isset($user)){
|
||||
if ( $user->id != $this->id ){
|
||||
$this->addError($attribute,'Az email cím már használatban van!');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function validateUsername($attribute, $params){
|
||||
/** @var User $user */
|
||||
$user = User::find()
|
||||
->andWhere(['username' => $this->username])->one();
|
||||
|
||||
if (isset($user)){
|
||||
if ( $user->id != $this->id ){
|
||||
$this->addError($attribute,'A felhasználónév már használatban van!');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @formatter:on
|
||||
*/
|
||||
@@ -53,14 +88,14 @@ class UserUpdate extends User {
|
||||
}
|
||||
}
|
||||
public function attributeLabels() {
|
||||
return [
|
||||
|
||||
return [
|
||||
|
||||
'status' => 'Státusz',
|
||||
'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' )
|
||||
'password_repeat' => Yii::t ( 'app', 'Jelszó újra' )
|
||||
]
|
||||
;
|
||||
}
|
||||
@@ -78,7 +113,7 @@ class UserUpdate extends User {
|
||||
}
|
||||
}
|
||||
public function afterSave($insert, $changedAttributes){
|
||||
parent::afterSave($insert, $changedAttributes);
|
||||
parent::afterSave($insert, $changedAttributes);
|
||||
$am = Yii::$app->authManager;
|
||||
$am->revokeAll($this->id);
|
||||
$role = $am->getRole($this->role);
|
||||
|
||||
Reference in New Issue
Block a user