Exemple #1
0
 public function actionRegister()
 {
     $errors = null;
     $model = new UserForm();
     if (Yii::$app->request->isPost) {
         $model->setAttributes(Yii::$app->request->post());
         if ($model->validate()) {
             $user = new User();
             $user->setAttributes($model->getAttributes());
             $user->setPassword($model->password);
             $user->generateAuthKey();
             $save = $user->save();
             if ($save) {
                 $purse = new Purse();
                 $purse->user_id = $user->id;
                 $purse->active = 1;
                 $purse->balance = 0;
                 $purse->name = "Основной";
                 $purse->save();
                 $login = Yii::$app->user->login($user, 3600 * 24 * 14);
                 if ($login) {
                     return $this->goHome();
                 }
             }
         } else {
             $errors = $model->getErrors();
         }
     }
     return $this->renderPartial('register', ['errors' => $errors, 'model' => $model]);
 }