コード例 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Administrator();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Administrator'])) {
         $model->attributes = $_POST['Administrator'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->user_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
コード例 #2
0
 public function actionCreate_Admin()
 {
     echo "<script>console.log('actionCreate_Admin');</script>";
     $model = new User();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->pic_url = '/coplat/images/profileimages/avatarsmall.gif';
         $model->activation_chain = $this->genRandomString(10);
         $model->username = $model->fname . "_" . $this->genRandomString(10);
         $hasher = new PasswordHash(8, false);
         $plain_pwd = $this->genRandomString(10);
         $model->password = $hasher->HashPassword($plain_pwd);
         $model->isAdmin = 1;
         if ($model->save()) {
             $model->username = $model->fname . "_" . $model->id;
             $model->save(false);
             $admin = new Administrator();
             $admin->user_id = $model->id;
             $admin->save();
             User::sendNewAdministratorEmailNotification($model->email, $plain_pwd);
             $this->redirect(array('/user/admin', 'id' => $model->id));
         }
     }
     $error = '';
     $this->render('create_admin', array('model' => $model, 'error' => $error));
 }