/**
* Creates a new Staff model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
if (Yii::$app->user->can('admin')) {
$model = new Staff();
if (Yii::$app->request->isAjax && $model->load($_POST)) {
Yii::$app->response->format = 'json';
return \yii\widgets\ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post())) {
$user = new Users();
$user->usertype = 'Staff';
$user->password = strtolower($model->apellido1 . substr($model->rut, 5, -2));
$user->email = $model->correo;
$model->save();
$user->id_orig = $model->id;
$user->username = $model->nombre . " " . $model->apellido1;
$user->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
} else {
throw new ForbiddenHttpException();
}
}