Example #1
0
 public function actionInvite($invite_id, $accept)
 {
     $invite = GroupInvite::model()->findByPk($invite_id);
     if (!$invite) {
         throw new CHttpException(404);
     }
     $invite->setAttribute('status', $accept == 1 ? GroupInvite::INVITE_ACCEPT : GroupInvite::INVITE_CANCELED);
     if ($accept == 1) {
         $group_member = new GroupMember();
         $group_member->setAttributes(['group_id' => $invite->group_id, 'user_id' => Yii::app()->user->getId()]);
         $group_member->save();
     }
     if ($invite->save()) {
         Yii::app()->user->setFlash('success', 'Приглашение ' . ($accept == 1 ? 'принято' : 'отклонено'));
     } else {
         Yii::app()->user->setFlash('error', 'Произошла ошибка');
     }
     $this->redirect(['notifications']);
 }
Example #2
0
 public function actionInvite($hash, $type = 1)
 {
     if (!in_array($type, [1, 2])) {
         throw new CHttpException(404, 'Данный тип не существует');
     }
     if ($type == 1) {
         $invite = GroupInvite::model()->with('group')->findByAttributes(['status' => GroupInvite::INVITE_CREATE, 'hash' => $hash]);
     } elseif ($type == 2) {
         $invite = Invite::model()->findByAttributes(['status' => Invite::INVITE_ACCEPT, 'hash' => $hash]);
     }
     if (!isset($invite)) {
         throw new CHttpException(404, 'Данное приглашение не найдено или было отменено');
     }
     $model = new Users();
     if (Yii::app()->request->isPostRequest) {
         $user = Yii::app()->request->getParam('Users');
         $model->setAttributes($user);
         $model->setAttributes(['email' => $invite->email, 'password' => md5($user['password'])]);
         if ($model->save()) {
             Yii::app()->authManager->assign('user', $model->id);
             $user_identity = new UserIdentity($model->username, $model->password);
             $user_identity->authenticate();
             Yii::app()->user->login($user_identity, 60 * 60 * 24 * 7);
             switch ($type) {
                 case 1:
                     $invite->setAttribute('status', GroupInvite::INVITE_ACCEPT);
                     $invite->save();
                     $group_member = new GroupMember();
                     $group_member->setAttributes(['group_id' => $invite->group_id, 'user_id' => $model->id]);
                     $group_member->save();
                     break;
                 case 2:
                     $invite->setAttribute('status', Invite::INVITE_USED);
                     $invite->save(false);
                     $group = new Group();
                     $group->setAttributes(['number' => $invite->group_number, 'owner_id' => $model->id]);
                     $group->save();
             }
             $this->redirect(['site/dashboard']);
         }
     }
     $this->render('invite', ['model' => $model]);
 }