@@ 82-101 (lines=20) @@ | ||
79 | * |
|
80 | * @return \yii\web\Response|string redirect or render |
|
81 | */ |
|
82 | public function actionCreate() |
|
83 | { |
|
84 | $model = new UserLogin(); |
|
85 | ||
86 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
87 | if (!User::findIdentity($model->username)) { |
|
88 | if (($user = User::create($model->username, $model->password)) !== null) { |
|
89 | return $this->redirect(['view', 'id' => $user->getId()]); |
|
90 | } else { |
|
91 | $model->addError('username', Yii::t('app', 'User creation failed')); |
|
92 | } |
|
93 | } else { |
|
94 | $model->addError('username', Yii::t('app', 'This user is already registered')); |
|
95 | } |
|
96 | } |
|
97 | ||
98 | return $this->render('create', [ |
|
99 | 'model' => $model, |
|
100 | ]); |
|
101 | } |
|
102 | ||
103 | /** |
|
104 | * Import user from LDAP and save it. |
|
@@ 108-129 (lines=22) @@ | ||
105 | * |
|
106 | * @return \yii\web\Response|string redirect or render |
|
107 | */ |
|
108 | public function actionImport() |
|
109 | { |
|
110 | $model = new UserLogin(); |
|
111 | ||
112 | if ($model->load(Yii::$app->request->post()) && $model->validate(['username'])) { |
|
113 | if (!User::findOne($model->username)) { |
|
114 | if (($user = User::findInLdap($model->username)) !== null) { |
|
115 | $user->save(false); |
|
116 | ||
117 | return $this->redirect(['view', 'id' => $user->username]); |
|
118 | } else { |
|
119 | $model->addError('username', Yii::t('app', 'This user doesn\'t exist in LDAP')); |
|
120 | } |
|
121 | } else { |
|
122 | $model->addError('username', Yii::t('app', 'This user is already registered')); |
|
123 | } |
|
124 | } |
|
125 | ||
126 | return $this->render('import', [ |
|
127 | 'model' => $model, |
|
128 | ]); |
|
129 | } |
|
130 | ||
131 | /** |
|
132 | * Deletes an existing User model. |