public function amIClient($uid = null) { $isLogged = false; if (is_null($uid)) { if (!Yii::$app->user->isGuest) { $uid = Yii::$app->getUser()->id; } } if (!is_null($uid)) { if (($client_id = (int) User::getClientIdByUid($uid)) > 0) { $this->client_id = $client_id; $isLogged = true; } } return $isLogged; }
public function actionRespond($id = null, $hash = null) { $model = null; $userModel = new \frontend\models\User(); if ($id) { $model = Razz::findOne($id); } elseif ($hash) { $model = Razz::findOne(['hash' => $hash]); } if (Yii::$app->getUser()->id === $model->uid) { //throw new HttpException(404, 'You are not allowed to respond to your own challenge!'); return $this->render('error', ['model' => $model, 'message' => 'You are not allowed to respond to your own challenge!', 'userModel' => $userModel]); } if (!$model) { throw new HttpException(404, 'Razzd not found'); } $model->scenario = 'respond'; if ($model->responder_stream) { throw new HttpException(403, 'Razzd already responded.'); } if (!Yii::$app->user->isGuest && $id && $model->hash && Yii::$app->user->id != $model->responder_uid) { // throw new HttpException(403, 'This razzd for other user.'); } elseif (Yii::$app->user->isGuest && $model->responder_uid) { $this->redirect(['/login']); } if (!Yii::$app->user->isGuest && $id && $model->hash) { if (!is_null($model->facebook_id)) { $client_id = User::getClientIdByUid(Yii::$app->user->id); if ((int) $client_id != (int) $model->facebook_id) { throw new HttpException(403, 'This razzd for other user!'); } } elseif (!is_null($model->responder_uid)) { if (Yii::$app->user->id != $model->responder_uid) { throw new HttpException(403, 'This razzd for other user...'); } } } if ($model->load(Yii::$app->request->post()) && $model->save()) { $this->redirect('/razz/' . $model->id); } else { // print_r($model->getErrors()); //exit(); } return $this->render('respond', ['model' => $model, 'userModel' => $userModel]); }