/** * Display a listing of the resource. * * @param User $user * @param StickerRepository $stickerRepository * * @return Response */ public function index(User $user, StickerRepository $stickerRepository) { $tasks = $user->todoTasks; $stickers = $user->toDoStickers()->with('tasks')->get(); $stickersArray = []; foreach ($stickers as $sticker) { $stickersArray[$sticker->id] = $sticker->toArray(); $pm = new ProgressManager($this->user, $sticker); $stickersArray[$sticker->id]['progress'] = $pm->getTaskProgress(); } foreach ($tasks as $task) { if (empty($stickersArray[$task->stickerId])) { if ($sticker = $stickerRepository->find($task->stickerId)) { $stickersArray[$sticker->id] = $sticker->toArray(); } else { continue; } } if (!array_key_exists('todoTasks', $stickersArray[$task->stickerId])) { $stickersArray[$task->stickerId]['todoTasks'] = []; } $stickersArray[$task->stickerId]['todoTasks'][] = $task->toArray(); } return $this->response(['user' => $user, 'stickers' => array_values($stickersArray)]); }
/** * Give the user the sticker if they do not already have it. */ public function giveSticker() { if (!$this->user->hasSticker($this->sticker)) { $this->user->earntStickers()->attach($this->sticker); // attach() doesn't return anything, but we want the ID of the pivot, so go get it $earntId = $this->user->earntStickers()->wherePivot('stickerId', $this->sticker->id)->withPivot(['id'])->first()->pivot->id; event(new StickerEarnt($this->user, $this->sticker, $earntId)); return true; } return false; }
/** * Process the login form. * * @param Request $request * * @return $this|RedirectResponse */ public function postIndex(Request $request) { $this->validate($request, ['username' => 'required', 'password' => 'required']); $credentials = $request->only('username', 'password'); $errors = []; $ban = null; /** @var User $user */ $user = User::where('username', $credentials['username'])->first(); if (Auth::validate($credentials)) { if ($ban = $user->getBan()) { $errors['username'] = '******'; } elseif ($user->isAdmin()) { // Create a session to use for API requests $session = UserSession::getOrCreate($user, $request->getClientIp()); Session::put('token', $session->getToken()); Auth::login($user); // Successful login - go to admin panel return new RedirectResponse('/'); } else { $errors['username'] = '******'re not an admin.'; } } if ($user && empty($errors)) { $errors['password'] = '******'; } elseif (!$user) { $errors['username'] = '******'; } return redirect('/login')->withInput($request->only('username', 'remember'))->withErrors($errors); }
public function getIndex() { $pendingSubmissions = Submission::notApproved()->count(); $ordersNeedPrinting = Order::whereNull('printedAt')->count(); $ordersNeedShipping = Order::whereNull('shippedAt')->count(); $newMembers = User::where('createdAt', '>=', date('Y-m-d 00:00:00'))->count(); $newPosts = Post::where('createdAt', '>=', date('Y-m-d 00:00:00'))->count(); $newPosts += Comment::where('createdAt', '>=', date('Y-m-d 00:00:00'))->count(); return $this->view('admin::dashboard', ['pendingSubmissions' => $pendingSubmissions, 'ordersNeedPrinting' => $ordersNeedPrinting, 'ordersNeedShipping' => $ordersNeedShipping, 'newMembers' => $newMembers, 'newPosts' => $newPosts]); }
/** * Execute the console command. * * @return mixed */ public function handle() { /** @var User[] $users */ $users = User::whereNull('imageId')->get(); foreach ($users as $user) { $this->info($user->id . "\t" . $user->username); if ($image = $user->ensureHasAvatar()) { $this->info('Created image ' . $image->id); } else { $this->error('Unable to create avatar'); } $user->save(); } }
/** * @api {post} /sessions Create A Session (Login) * @apiGroup User Sessions * @apiDescription Validates login credentials and returns a new session if valid. * @apiParam {string} username Username to login as. * @apiParam {string} password The user's password. * * @return \Response * @throws BannedUserException */ public function store() { $this->validate($this->request, ['username' => 'required', 'password' => 'required']); $credentials = $this->request->only('username', 'password'); /** @var User $user */ $user = User::where('username', $credentials['username'])->first(); if (!$user) { throw new InputException(404, ['username' => ["Couldn't find a user with that username."]]); } if (Auth::validate($credentials)) { if ($ban = $user->getBan()) { throw new BannedUserException($ban); } $session = UserSession::getOrCreate($user, $this->request->getClientIp()); return $this->response(['sessionToken' => $session->getToken(), 'session' => $session]); } else { throw new InputException(401, ['password' => ["That password is not correct."]]); } }
protected function getSearchableList() { return User::query(); }
/** * @api {get} /users/:username/posts Get User's Posts * @apiGroup Users * @apiDescription Get the stickers a user has earnt. * * @param Request $request * @param User $user * * @return \Illuminate\Http\JsonResponse */ public function posts(Request $request, User $user) { $this->validate($request, ['type' => 'in:submission,question,tip']); $posts = $user->posts(); if ($request->has('type')) { $posts->where('type', $request->input('type')); $posts->with('submission'); } $posts->with('task')->orderBy('id', 'DESC'); $paginator = $posts->paginate($this->getResultsPerPage()); return $this->paginatorToArray($paginator, 'posts'); }
/** * @param User $user * * @return bool * @throws Exception */ public function userLikes(User $user) { return $user->likes()->where('joinId', $this->objectOrId)->count() > 0; }
/** * @param User $user * * @return bool */ public function userLikes(User $user) { $postId = $this->objectOrId instanceof Post ? $this->objectOrId->id : $this->objectOrId; return $user->likes()->where('postId', $postId)->count() > 0; }
/** * @param User $user * * @return bool * @throws Exception */ public function userLikes(User $user) { $toDoId = $this->objectOrId instanceof ToDo ? $this->objectOrId->id : $this->objectOrId; return $user->likes()->where('toDoId', $toDoId)->count() > 0; }