示例#1
0
 public function browse($slug)
 {
     try {
         $board = Board::bySlug($slug)->toArray();
     } catch (AccessDeniedException $e) {
         return Theme::view('errors/access_denied');
     } catch (ModelNotFoundException $e) {
         return Theme::view('errors/not_found');
     }
     return Theme::view('index', ['current_board' => $board]);
 }
示例#2
0
 public function read(Application $app, $id, $slug)
 {
     try {
         $post = Post::with('author', 'children', 'children.author')->findOrFail($id);
     } catch (ModelNotFoundException $e) {
         return Theme::view('errors/not_found');
     }
     if ($slug != $post->slug) {
         return $app->redirect($app->path('site.post.read', ['id' => $id, 'slug' => $post->slug]));
     }
     if (!$post->board->userHasAccess()) {
         return Theme::view('errors/access_denied');
     }
     return Theme::view('post', ['post' => $post->toArray()]);
 }
示例#3
0
 public function register(Request $request, Application $app)
 {
     if (Auth::user()) {
         return $app->redirect($app->path('site.index'));
     }
     $vars = array();
     $form = Form::create('registration_form')->add('name', Type\TextType::class)->add('username', Type\TextType::class, ['constraints' => [new Assert\Regex(['pattern' => '/^[A-Za-z0-9_]+$/', 'match' => true, 'message' => 'Username must only contain alphanumeric characters and underscores.']), new CustomAssert\UniqueRecord(['model' => User::class, 'row' => 'username', 'message' => 'Username already in use.'])]])->add('email', Type\TextType::class, ['constraints' => [new Assert\Email(), new CustomAssert\UniqueRecord(['model' => User::class, 'row' => 'email', 'message' => 'Email already in use.'])]])->add('password', Type\RepeatedType::class, ['type' => Type\PasswordType::class, 'first_options' => ['label' => 'Password'], 'second_options' => ['label' => 'Repeat Password'], 'invalid_message' => 'Password fields did not match.', 'constraints' => [new Assert\Length(['min' => 8, 'minMessage' => 'Password must be at least 8 characters.'])]]);
     $form = $form->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $user = User::create($data);
         Auth::login($user);
         return $app->redirect($app->path('site.index'));
     }
     $vars['registration_form'] = $form->createView();
     return Theme::view('auth/register', $vars);
 }
示例#4
0
 /**
  * Wrapper for Theme::addToFoot()
  * Add code before </body> of template
  *
  * @param string $code Code
  */
 public function addToFoot($code)
 {
     return Theme::addToFoot($code);
 }
示例#5
0
 public function index()
 {
     return Theme::view('index');
 }