/**
  * 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]);
 }
 /**
  * Save email settings
  *
  * @param Request $request
  * @param UserContract $userRepo
  * @return mixed
  */
 public function save(Request $request, UserContract $userRepo)
 {
     $this->validate($request, ['name' => 'required|min:3|max:15', 'email' => 'required|email|max:255', 'password' => 'required|min:6']);
     Artisan::call('migrate:refresh', ['--force' => true]);
     $user = $userRepo->create(['name' => $request->get('name'), 'email' => $request->get('email'), 'password' => bcrypt($request->get('password')), 'permission' => 'admin', 'status' => 1]);
     session(['install.done.admin' => true]);
     session(['install.admin.user' => $user->name]);
     return redirect()->route('finish');
 }
Exemplo n.º 3
0
 /**
  * @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;
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
 /**
  * Generate a unique name from an email address
  *
  * @param $email
  * @return mixed|string
  */
 function emailToName($email)
 {
     $email = mb_split('@', $email)[0];
     $name = preg_replace('/[^A-Za-z0-9]/', '', $email);
     do {
         if (!$this->user->findByName($name)) {
             break;
         }
         $nameRev = mb_strrev($name);
         $number = 1;
         if (preg_match('/([0-9]+)(.+)/us', $nameRev, $out)) {
             $name = mb_strrev($out[2]);
             $number = $out[1] + 1;
         }
         $name = $name . $number;
     } while (1);
     return $name;
 }
 /**
  * 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')]);
 }