/**
  * Creates a new Users model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Users();
     $model->setScenario('register');
     $post = Yii::$app->request->post();
     $formName = basename($model->className());
     if ($model->load($post)) {
         // Default value
         $model->is_super_admin = isset($post[$formName]['is_super_admin']) ? $post[$formName]['is_super_admin'] : 0;
         $model->role = $model->is_super_admin ? Identity::ROLE_SUPERADMIN : 30;
         $model->fecha_conexion = isset($post[$formName]['fecha_conexion']) ? $post[$formName]['fecha_conexion'] : Yii::$app->fn->GetDate('none');
         $model->fecha_modif = isset($post[$formName]['fecha_modif']) ? $post[$formName]['fecha_modif'] : Yii::$app->fn->GetDate('none');
         $model->fecha_registro = isset($post[$formName]['fecha_registro']) ? $post[$formName]['fecha_registro'] : Yii::$app->fn->GetDate();
         $model->id_estado = isset($post[$formName]['id_estado']) ? $post[$formName]['id_estado'] : 1;
         if ($model->validate()) {
             $model->setPassword();
             $model->generateAuthKey();
             if ($model->save()) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         }
     }
     // Load empty/error form
     return $this->render('create', ['model' => $model]);
 }
 public function actionRegister()
 {
     $model = new Users();
     $model->load(Yii::$app->request->post());
     if ($model->validate()) {
         $model->save();
         return $this->render('confirm', ['model' => $model]);
     }
     return $this->render('register', ['model' => $model]);
 }
Example #3
0
 public function actionIndex()
 {
     $model = new app\models\Users();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             // form inputs are valid, do something here
             return;
         }
     }
     return $this->render('form1', ['model' => $model]);
 }
 public function actionRegister()
 {
     $model = new Users();
     $result = ['model' => $model];
     if (\Yii::$app->request->isPost) {
         $post = \Yii::$app->request->post();
         if ($model->load($post) && $model->validate()) {
             echo '注册成功';
         }
     }
     return $this->render('register', $result);
 }
 /**
  * Creates a new Users model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Users();
     if ($model->load(Yii::$app->request->post())) {
         $model->username = $model->id;
         $model->password = '******';
         if ($model->validate()) {
             $model->save();
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #6
0
 public function actionAdd($status = 3)
 {
     $user = new Users();
     print $eng = Yii::$app->params['status_user_eng'][$status];
     if ($status == '3') {
         $users = Users::find()->select(['id', 'username'])->orderBy('username')->where(['status' => '2'])->all();
         $items = ArrayHelper::map($users, 'id', 'username');
     }
     if (Yii::$app->request->post('Users')) {
         $user->attributes = Yii::$app->request->post('Users');
         if ($user->validate() && $user->save()) {
             return $this->render($eng, ['model' => $user, 'items' => $items, 'status' => Yii::$app->params['status_user'][$status], 'ok' => 1]);
         }
     }
     return $this->render($eng, ['model' => $user, 'items' => $items, 'status' => Yii::$app->params['status_user'][$status]]);
 }