Ejemplo n.º 1
0
 /**
  * Creates a new Account model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Account();
     if ($model->load(Yii::$app->request->post())) {
         $a = $model->acct_name;
         $connection = \Yii::$app->db;
         $sql = $connection->createCommand('SELECT  acct_name  FROM Account WHERE acct_name = "' . $a . '"')->queryAll();
         if ($sql != null) {
             echo "<SCRIPT LANGUAGE='JavaScript'>\n\t\t\t\t\t\twindow.alert('This Account has already existing')\n\t\t\t\t\t\twindow.location.href='index.php?r=project%2Findex';\n\t\t\t\t\t\t</SCRIPT>";
         } else {
             $model->save();
             return $this->redirect(['project/index']);
         }
     } else {
         return $this->renderAjax('create', ['model' => $model]);
     }
     //echo "<a href='index.php?r=project%2Findex'> Go Back</a>";
 }
Ejemplo n.º 2
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($this->sendEmail($user->auth_key)) {
             if ($user->save()) {
                 $account = new Account();
                 $account->user_id = $user->id;
                 if ($account->save()) {
                     return $user;
                 }
             }
         }
     }
     return null;
 }