/** * @Route("/add", name="add_ban") */ public function addBan() { $ban = new Ban(); $user = null; if ($id = $this->request->get('id')) { if ($user = User::find($id)) { $ban->user = $user; $ban->ip = $user->ip; } } $form = $this->app->formType(new BanType(), $ban); $form->handleRequest($this->request); if ($form->isValid()) { $ban = $form->getData(); $ban->created = time(); $ban->author = $this->app->user(); $ban->save(); if (null !== $ban->user) { $this->app->server()->kill($ban->user->id); $log = $this->app->trans('User %user% was banned for %time%.', array('%user%' => $ban->user->name, '%time%' => $this->app->trans($ban->getHowLongString()))); if ($ban->reason != '') { $log .= ' ' . $this->app->trans('Reason: %reason%', array('%reason%' => $ban->reason)); } $this->app->server()->log($log, 'danger'); } return $this->app->redirect($this->app->url('moderator_bans')); } return $this->render('moderator/ban/add.twig', array('form' => $form->createView(), 'user' => $user)); }
public function onRequest(Request $request) { $session = $request->getSession(); list($id, $role) = $session->get('user', array(null, 'ROLE_ANONYMOUS')); if (null === $id && $request->cookies->has(Remember::REMEMBER_ME)) { if ($this->remember->check($request->cookies->get(Remember::REMEMBER_ME))) { list($id, $role) = $this->remember->getIt(); $session->set('user', array($id, $role)); } } $this->provider->setRole($role); if (!$this->provider->isAllowed($request->getPathInfo())) { throw new Exception\AccessDeniedException("Access denied to " . $request->getPathInfo()); } if (null !== $id) { // Ban check $clientIp = $request->getClientIp(); $ban = Ban::findActive($id, $clientIp); if (!empty($ban)) { throw new BannedException($ban[0], Response::HTTP_FORBIDDEN); } // User loading. $user = User::find($id); if (null !== $user) { $user->ip = $clientIp; $user->save(); $this->provider->setUser($user); $this->provider->setAuthenticated(true); } } }
protected function privateMessage(User $user, $forId, $data) { $message = new Message(); $message->user = $user; $message->for = User::find($forId); $message->datetime = new \DateTime(); $message->data = $data; $message->save(); $this->sendToUser($forId, Protocol::message($message)); return $message; }
/** * @Route("/delete/{id}", name="admin_users_delete") */ public function remove($id) { $user = User::find($id); if (!$user) { throw new NotFoundHttpException($this->app->trans('User not found')); } $form = $this->app->form()->add('delete', 'submit')->getForm(); $form->handleRequest($this->request); if ($form->isValid()) { if ($form->get('delete')->isClicked()) { $this->app->entityManager()->remove($user); $this->app->entityManager()->flush(); $message = $this->app->trans('User "%name%" was deleted.', array('%name%' => $user->name)); $this->app->session()->getFlashBag()->add('success', $message); return $this->app->redirect($this->app->url('admin_users')); } } return $this->render('admin/users/delete.twig', array('user' => $user, 'form' => $form->createView())); }
/** * @param ConnectionInterface $conn */ public function onOpen(ConnectionInterface $conn) { $userData = $conn->Session->get('user'); if (count($userData) == 2 && is_int($userData[0])) { list($userId, $userRole) = $userData; $user = User::find($userId); if (null === $user) { $conn->close(); return; } $this->em->refresh($user); $conn->user = $user; $this->send(Protocol::userJoin($user)); $this->clients[$user->id] = $conn; $users = array(); foreach ($this->clients as $conn) { $users[] = $conn->user->export(); } $this->sendToUser($user->id, Protocol::data(Protocol::SYNCHRONIZE, $users)); } else { $conn->close(); } }
public function kill($userId) { $this->send(Protocol::userLeave(User::find($userId))); }