/** * Autneticat * * @param $provider * @return bool */ public function authenticate($provider) { $socialUser = $this->social->with($provider)->stateless()->user(); if (!$socialUser) { return false; } $identity = $this->oauth->findByProviderNameAndId($socialUser->id, $provider); if ($identity) { $this->oauth->update($identity, ['token' => $socialUser->token]); $this->auth->loginUsingId($identity->user_id, true); return true; } $user = $this->user->findByEmail($socialUser->email); if (!is_null($user)) { $this->oauth->create(['provider_id' => $socialUser->id, 'provider' => $provider, 'user_id' => $user->id, 'token' => $socialUser->token]); $this->user->update($user, ['status' => 1]); $this->auth->login($user, true); return true; } if (!setting('registration', true)) { return false; } // Just create the user $newUser = $this->user->create(['name' => $this->emailToName($socialUser->email), 'email' => $socialUser->email, 'password' => '', 'status' => 1, 'avatar' => $socialUser->avatar]); event(new UserCreatedThroughOAuth($newUser)); $this->oauth->create(['provider_id' => $socialUser->id, 'provider' => $provider, 'user_id' => $newUser->id, 'token' => $socialUser->token]); $this->auth->login($newUser, true); return true; }
/** * Handle the event. * * @param PostWasUnvoted $event * @return void */ public function handle(PostWasUnvoted $event) { $eventName = $event->value == 1 ? 'post.vote.like' : 'post.vote.dislike'; $this->activity->deleteByComposite($event->user, $event->post, $eventName); $likes = $this->activity->countActivities($event->user, 'post.vote.like'); $dislikes = $this->activity->countActivities($event->user, 'post.vote.dislike'); $this->user->update($event->user, ['likes' => $likes, 'dislikes' => $dislikes]); }
/** * @param $id * @return User */ public function toggleBlock($id) { $user = $this->userRepo->findById($id); if (!$user || $user->permission == 'admin') { return false; } $toggle = !(bool) $user->blocked; $user = $this->userRepo->update($user, ['blocked' => $toggle]); $event = !$toggle ? new UserWasBlocked($user) : new UserWasUnblocked($user); event($event); return true; }
/** * Delete post by its id * * @param $id * @return bool */ public function deleteById($id) { $post = $this->post->findById($id); if (!$post) { return false; } $this->user->update($post->user, ['posts' => $post->user->posts - 1]); $this->imageUploadService->remove($post->featured); if ($post->type == 'image' || $post->type == 'gif') { $this->imageUploadService->remove($post->thumbnail); $this->imageUploadService->remove($post->media); } $this->post->delete($post); event(new PostWasDeleted($post)); return true; }
/** * Handle the event. * * @param CommentWasCreated $event * @return void */ public function handle(CommentWasCreated $event) { $this->activity->create($event->user, $event->post, 'post.comment'); $comments = $this->activity->countActivities($event->user, 'post.comment'); $this->user->update($event->user, ['comments' => $comments]); }
/** * Handle the event. * * @param PostWasCreated $event * @return void */ public function handle(PostWasCreated $event) { $this->activity->create($event->user, $event->post, 'post.create'); $this->user->update($event->user, ['posts' => $this->activity->countActivities($event->user, 'post.create')]); }