Skip to content

Commit 09f478b

Browse files
committed
Merge branch 'master' into release
2 parents a0497fe + d6bad01 commit 09f478b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1092
-557
lines changed

app/Exceptions/AuthException.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php namespace BookStack\Exceptions;
2+
3+
4+
class AuthException extends PrettyException {}

app/Http/Controllers/Auth/AuthController.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace BookStack\Http\Controllers\Auth;
44

5+
use BookStack\Exceptions\AuthException;
6+
use BookStack\Exceptions\PrettyException;
57
use Illuminate\Contracts\Auth\Authenticatable;
68
use Illuminate\Http\Request;
79
use BookStack\Exceptions\SocialSignInException;
@@ -115,6 +117,7 @@ public function postRegister(Request $request)
115117
* @param Request $request
116118
* @param Authenticatable $user
117119
* @return \Illuminate\Http\RedirectResponse
120+
* @throws AuthException
118121
*/
119122
protected function authenticated(Request $request, Authenticatable $user)
120123
{
@@ -132,6 +135,13 @@ protected function authenticated(Request $request, Authenticatable $user)
132135
}
133136

134137
if (!$user->exists) {
138+
139+
// Check for users with same email already
140+
$alreadyUser = $user->newQuery()->where('email', '=', $user->email)->count() > 0;
141+
if ($alreadyUser) {
142+
throw new AuthException('A user with the email ' . $user->email . ' already exists but with different credentials.');
143+
}
144+
135145
$user->save();
136146
$this->userRepo->attachDefaultRole($user);
137147
auth()->login($user);
@@ -184,14 +194,11 @@ protected function registerUser(array $userData, $socialAccount = false)
184194
}
185195

186196
if (setting('registration-confirmation') || setting('registration-restrict')) {
187-
$newUser->email_confirmed = false;
188197
$newUser->save();
189198
$this->emailConfirmationService->sendConfirmation($newUser);
190199
return redirect('/register/confirm');
191200
}
192201

193-
$newUser->email_confirmed = true;
194-
195202
auth()->login($newUser);
196203
session()->flash('success', 'Thanks for signing up! You are now registered and signed in.');
197204
return redirect($this->redirectPath());

app/Http/Controllers/BookController.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
<?php
2-
3-
namespace BookStack\Http\Controllers;
1+
<?php namespace BookStack\Http\Controllers;
42

53
use Activity;
64
use BookStack\Repos\UserRepo;
75
use Illuminate\Http\Request;
8-
96
use Illuminate\Support\Facades\Auth;
10-
use Illuminate\Support\Str;
117
use BookStack\Http\Requests;
128
use BookStack\Repos\BookRepo;
139
use BookStack\Repos\ChapterRepo;
@@ -40,7 +36,6 @@ public function __construct(BookRepo $bookRepo, PageRepo $pageRepo, ChapterRepo
4036

4137
/**
4238
* Display a listing of the book.
43-
*
4439
* @return Response
4540
*/
4641
public function index()
@@ -54,7 +49,6 @@ public function index()
5449

5550
/**
5651
* Show the form for creating a new book.
57-
*
5852
* @return Response
5953
*/
6054
public function create()
@@ -88,7 +82,6 @@ public function store(Request $request)
8882

8983
/**
9084
* Display the specified book.
91-
*
9285
* @param $slug
9386
* @return Response
9487
*/
@@ -103,7 +96,6 @@ public function show($slug)
10396

10497
/**
10598
* Show the form for editing the specified book.
106-
*
10799
* @param $slug
108100
* @return Response
109101
*/
@@ -117,7 +109,6 @@ public function edit($slug)
117109

118110
/**
119111
* Update the specified book in storage.
120-
*
121112
* @param Request $request
122113
* @param $slug
123114
* @return Response
@@ -267,7 +258,7 @@ public function restrict($bookSlug, Request $request)
267258
$book = $this->bookRepo->getBySlug($bookSlug);
268259
$this->checkOwnablePermission('restrictions-manage', $book);
269260
$this->bookRepo->updateRestrictionsFromRequest($request, $book);
270-
session()->flash('success', 'Page Restrictions Updated');
261+
session()->flash('success', 'Book Restrictions Updated');
271262
return redirect($book->getUrl());
272263
}
273264
}

app/Http/Controllers/ChapterController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function restrict($bookSlug, $chapterSlug, Request $request)
187187
$chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
188188
$this->checkOwnablePermission('restrictions-manage', $chapter);
189189
$this->chapterRepo->updateRestrictionsFromRequest($request, $chapter);
190-
session()->flash('success', 'Page Restrictions Updated');
190+
session()->flash('success', 'Chapter Restrictions Updated');
191191
return redirect($chapter->getUrl());
192192
}
193193
}

app/Http/Controllers/ImageController.php

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
<?php
2-
3-
namespace BookStack\Http\Controllers;
1+
<?php namespace BookStack\Http\Controllers;
42

53
use BookStack\Exceptions\ImageUploadException;
64
use BookStack\Repos\ImageRepo;
75
use Illuminate\Filesystem\Filesystem as File;
86
use Illuminate\Http\Request;
9-
use Illuminate\Support\Facades\Auth;
10-
use Intervention\Image\Facades\Image as ImageTool;
11-
use Illuminate\Support\Facades\DB;
127
use BookStack\Image;
138
use BookStack\Repos\PageRepo;
149

@@ -44,6 +39,24 @@ public function getAllByType($type, $page = 0)
4439
return response()->json($imgData);
4540
}
4641

42+
/**
43+
* Search through images within a particular type.
44+
* @param $type
45+
* @param int $page
46+
* @param Request $request
47+
* @return mixed
48+
*/
49+
public function searchByType($type, $page = 0, Request $request)
50+
{
51+
$this->validate($request, [
52+
'term' => 'required|string'
53+
]);
54+
55+
$searchTerm = $request->get('term');
56+
$imgData = $this->imageRepo->searchPaginatedByType($type, $page,24, $searchTerm);
57+
return response()->json($imgData);
58+
}
59+
4760
/**
4861
* Get all images for a user.
4962
* @param int $page
@@ -55,6 +68,27 @@ public function getAllForUserType($page = 0)
5568
return response()->json($imgData);
5669
}
5770

71+
/**
72+
* Get gallery images with a specific filter such as book or page
73+
* @param $filter
74+
* @param int $page
75+
* @param Request $request
76+
*/
77+
public function getGalleryFiltered($filter, $page = 0, Request $request)
78+
{
79+
$this->validate($request, [
80+
'page_id' => 'required|integer'
81+
]);
82+
83+
$validFilters = collect(['page', 'book']);
84+
if (!$validFilters->contains($filter)) return response('Invalid filter', 500);
85+
86+
$pageId = $request->get('page_id');
87+
$imgData = $this->imageRepo->getGalleryFiltered($page, 24, strtolower($filter), $pageId);
88+
89+
return response()->json($imgData);
90+
}
91+
5892
/**
5993
* Handles image uploads for use on pages.
6094
* @param string $type

app/Http/Controllers/PageController.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use BookStack\Exceptions\NotFoundException;
55
use BookStack\Repos\UserRepo;
66
use BookStack\Services\ExportService;
7+
use Carbon\Carbon;
78
use Illuminate\Http\Request;
89
use BookStack\Http\Requests;
910
use BookStack\Repos\BookRepo;
@@ -88,14 +89,19 @@ public function store(Request $request, $bookSlug, $pageId)
8889

8990
$input = $request->all();
9091
$book = $this->bookRepo->getBySlug($bookSlug);
91-
$input['priority'] = $this->bookRepo->getNewPriority($book);
9292

9393
$draftPage = $this->pageRepo->getById($pageId, true);
9494

9595
$chapterId = $draftPage->chapter_id;
9696
$parent = $chapterId !== 0 ? $this->chapterRepo->getById($chapterId) : $book;
9797
$this->checkOwnablePermission('page-create', $parent);
9898

99+
if ($parent->isA('chapter')) {
100+
$input['priority'] = $this->chapterRepo->getNewPriority($parent);
101+
} else {
102+
$input['priority'] = $this->bookRepo->getNewPriority($parent);
103+
}
104+
99105
$page = $this->pageRepo->publishDraft($draftPage, $input);
100106

101107
Activity::add($page, 'page_create', $book->id);
@@ -164,6 +170,7 @@ public function edit($bookSlug, $pageSlug)
164170
$draft = $this->pageRepo->getUserPageDraft($page, $this->currentUser->id);
165171
$page->name = $draft->name;
166172
$page->html = $draft->html;
173+
$page->markdown = $draft->markdown;
167174
$page->isDraft = true;
168175
$warnings [] = $this->pageRepo->getUserPageDraftMessage($draft);
169176
}
@@ -204,12 +211,18 @@ public function saveDraft(Request $request, $pageId)
204211
$page = $this->pageRepo->getById($pageId, true);
205212
$this->checkOwnablePermission('page-update', $page);
206213
if ($page->draft) {
207-
$draft = $this->pageRepo->updateDraftPage($page, $request->only(['name', 'html']));
214+
$draft = $this->pageRepo->updateDraftPage($page, $request->only(['name', 'html', 'markdown']));
208215
} else {
209-
$draft = $this->pageRepo->saveUpdateDraft($page, $request->only(['name', 'html']));
216+
$draft = $this->pageRepo->saveUpdateDraft($page, $request->only(['name', 'html', 'markdown']));
210217
}
211-
$updateTime = $draft->updated_at->format('H:i');
212-
return response()->json(['status' => 'success', 'message' => 'Draft saved at ' . $updateTime]);
218+
219+
$updateTime = $draft->updated_at->timestamp;
220+
$utcUpdateTimestamp = $updateTime + Carbon::createFromTimestamp(0)->offset;
221+
return response()->json([
222+
'status' => 'success',
223+
'message' => 'Draft saved at ',
224+
'timestamp' => $utcUpdateTimestamp
225+
]);
213226
}
214227

215228
/**

app/Http/Middleware/Authenticate.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ class Authenticate
1111
{
1212
/**
1313
* The Guard implementation.
14-
*
1514
* @var Guard
1615
*/
1716
protected $auth;
1817

1918
/**
2019
* Create a new filter instance.
21-
*
2220
* @param Guard $auth
2321
*/
2422
public function __construct(Guard $auth)
@@ -28,14 +26,13 @@ public function __construct(Guard $auth)
2826

2927
/**
3028
* Handle an incoming request.
31-
*
3229
* @param \Illuminate\Http\Request $request
3330
* @param \Closure $next
3431
* @return mixed
3532
*/
3633
public function handle($request, Closure $next)
3734
{
38-
if(auth()->check() && auth()->user()->email_confirmed == false) {
35+
if ($this->auth->check() && setting('registration-confirmation') && !$this->auth->user()->email_confirmed) {
3936
return redirect()->guest('/register/confirm/awaiting');
4037
}
4138

app/Http/routes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
Route::post('/{type}/upload', 'ImageController@uploadByType');
7676
Route::get('/{type}/all', 'ImageController@getAllByType');
7777
Route::get('/{type}/all/{page}', 'ImageController@getAllByType');
78+
Route::get('/{type}/search/{page}', 'ImageController@searchByType');
79+
Route::get('/gallery/{filter}/{page}', 'ImageController@getGalleryFiltered');
7880
Route::delete('/{imageId}', 'ImageController@destroy');
7981
});
8082

app/Page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class Page extends Entity
88
{
9-
protected $fillable = ['name', 'html', 'priority'];
9+
protected $fillable = ['name', 'html', 'priority', 'markdown'];
1010

1111
protected $simpleAttributes = ['name', 'id', 'slug'];
1212

app/PageRevision.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class PageRevision extends Model
66
{
7-
protected $fillable = ['name', 'html', 'text'];
7+
protected $fillable = ['name', 'html', 'text', 'markdown'];
88

99
/**
1010
* Get the user that created the page revision

0 commit comments

Comments
 (0)