Skip to content
Closed
4 changes: 2 additions & 2 deletions app/Exceptions/CannotCreateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class CannotCreateUser extends Exception
{
public static function duplicateEmailAddress(string $emailAddress): self
public static function duplicateEmailAddress(string $emailAddress): CannotCreateUser
{
return new static("The email address [$emailAddress] already exists.");
}

public static function duplicateUsername(string $username): self
public static function duplicateUsername(string $username): CannotCreateUser
{
return new static("The username [$username] already exists.");
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/ThreadRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ThreadRequest extends Request
public function rules()
{
return [
'subject' => 'required|max:60|'.DoesNotContainUrlRule::NAME.'|'.SpamRule::NAME,
'subject' => 'required|'.DoesNotContainUrlRule::NAME.'|'.SpamRule::NAME,
'body' => 'required|'.SpamRule::NAME,
'tags' => 'array',
'tags.*' => 'exists:tags,id',
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Requests/UpdateProfileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ public function rules()

public function bio(): string
{
return (string) $this->get('bio', '');
return $this->get('bio', '');
}

public function name(): string
{
return (string) $this->get('name');
return $this->get('name');
}

public function email(): string
{
return (string) $this->get('email');
return $this->get('email');
}

public function username(): string
{
return (string) $this->get('username');
return $this->get('username');
}
}
8 changes: 0 additions & 8 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace App\Providers;

use App\Models\Thread;
use Psr\Log\LoggerInterface;
use Illuminate\Contracts\Logging\Log;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Relations\Relation;

Expand All @@ -27,10 +25,4 @@ public function bootMacros()
{
require base_path('resources/macros/blade.php');
}

public function register()
{
$this->app->alias('bugsnag.multi', Log::class);
$this->app->alias('bugsnag.multi', LoggerInterface::class);
}
}
6 changes: 3 additions & 3 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,17 @@ public function countSolutions(): int
})->count();
}

public static function findByUsername(string $username): self
public static function findByUsername(string $username): User
{
return static::where('username', $username)->firstOrFail();
}

public static function findByEmailAddress(string $emailAddress): self
public static function findByEmailAddress(string $emailAddress): User
{
return static::where('email', $emailAddress)->firstOrFail();
}

public static function findByGithubId(string $githubId): self
public static function findByGithubId(string $githubId): User
{
return static::where('github_id', $githubId)->firstOrFail();
}
Expand Down
3 changes: 2 additions & 1 deletion resources/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ require('./bootstrap');

$('select.selectize').selectize({ maxItems: 3 });
$('textarea.wysiwyg').markdown({ iconlibrary: 'fa' });
$('.forum-content > p').twembed();

// const app = new Vue({
// el: '#app'
// });
// });
5 changes: 3 additions & 2 deletions resources/assets/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
*/
require('vue-resource');
require('selectize');
require('markdown'); // This doesn't seems to work so we require it directly in base.blade.php
require('to-markdown');
require('bootstrap-markdown/js/bootstrap-markdown');
require('./embed-twitter');
require('prismjs');
require('prismjs/components/prism-json');
require('prismjs/components/prism-css');
require('prismjs/components/prism-javascript');
require('prismjs/components/prism-less');
require('prismjs/components/prism-sass');
require('prismjs/components/prism-php');
window.markdown = require('markdown').markdown;
require('prismjs/components/prism-php');
20 changes: 20 additions & 0 deletions resources/assets/js/embed-twitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$.fn.twembed = function () {
const regex = /((http(s|):\/\/)|)twitter.com\/\w*\/status\/\d*/g;

function transformTwitterLinkToBlockquote(link, content) {
content.innerHTML = content.innerHTML.replace(
link,
`<blockquote class="twitter-tweet" data-lang="en"><a href="${link}">${link}</a></blockquote>`
)
}

function searchForTwitterLinks(id, content) {
const match = regex.exec($(content).text());

if (match && match[0]) {
transformTwitterLinkToBlockquote(match[0], content);
}
}

$(this).each(searchForTwitterLinks);
};
3 changes: 1 addition & 2 deletions resources/views/forum/threads/_form.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{!! Form::open(['route' => $route, 'method' => $method ?? 'POST']) !!}
@formGroup('subject')
{!! Form::label('subject') !!}
{!! Form::text('subject', isset($thread) ? $thread->subject() : null, ['class' => 'form-control', 'required', 'maxlength' => '60']) !!}
<span class="help-block">Maximum 60 characters.</span>
{!! Form::text('subject', isset($thread) ? $thread->subject() : null, ['class' => 'form-control', 'required']) !!}
@error('subject')
@endFormGroup

Expand Down
4 changes: 4 additions & 0 deletions resources/views/forum/threads/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

@extends('layouts.default')

@push('scripts-head')
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
@endpush

@section('content')
<div class="row forum">
<div class="col-md-3">
Expand Down
3 changes: 3 additions & 0 deletions resources/views/layouts/base.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
@include('layouts._favicons')
@include('layouts._google_analytics')
@include('layouts._ads._ad_sense')

@stack('scripts-head')
</head>
<body class="{{ $bodyClass ?? '' }}">

Expand All @@ -31,6 +33,7 @@
@include('layouts._footer')
</div>

<script src="{{ asset('build/custom/markdown.js') }}"></script>
<script src="{{ mix('build/js/app.js') }}"></script>

@include('layouts._intercom')
Expand Down
41 changes: 0 additions & 41 deletions tests/Feature/ForumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,45 +122,4 @@ public function users_cannot_delete_a_thread_they_do_not_own()
$this->delete('/forum/my-first-thread')
->assertForbidden();
}

/** @test */
public function users_cannot_create_a_thread_with_a_subject_that_is_too_long()
{
$tag = factory(Tag::class)->create(['name' => 'Test Tag']);

$this->login();

$this->visit('/forum/create-thread')
->submitForm('Create Thread', [
'subject' => 'How to make Eloquent, Doctrine, Entities and Annotations work together in Laravel?',
'body' => 'This is a thread with 82 characters in the subject',
'tags' => [$tag->id()],
])
->seePageIs('/forum/create-thread')
->see('Something went wrong. Please review the fields below.')
->see('The subject may not be greater than 60 characters.');
}

/** @test */
public function users_cannot_edit_a_thread_with_a_subject_that_is_too_long()
{
$user = $this->createUser();
$tag = factory(Tag::class)->create(['name' => 'Test Tag']);
factory(Thread::class)->create([
'author_id' => $user->id(),
'slug' => 'my-first-thread',
]);

$this->loginAs($user);

$this->visit('/forum/my-first-thread/edit')
->submitForm('Update Thread', [
'subject' => 'How to make Eloquent, Doctrine, Entities and Annotations work together in Laravel?',
'body' => 'This is a thread with 82 characters in the subject',
'tags' => [$tag->id()],
])
->seePageIs('/forum/my-first-thread/edit')
->see('Something went wrong. Please review the fields below.')
->see('The subject may not be greater than 60 characters.');
}
}
8 changes: 3 additions & 5 deletions webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const { mix } = require('laravel-mix');
*/

mix.js('resources/assets/js/app.js', 'public/build/js')
.sass('resources/assets/sass/app.scss', 'public/build/css');

if (mix.config.inProduction) {
mix.version();
}
.sass('resources/assets/sass/app.scss', 'public/build/css')
.version()
.copy('node_modules/markdown/lib/markdown.js', 'public/build/custom/markdown.js');