Skip to content

Commit 97bbf79

Browse files
committed
Merge branch 'v0.12' into release
2 parents f7b01ae + 2af0021 commit 97bbf79

File tree

16 files changed

+150
-39
lines changed

16 files changed

+150
-39
lines changed

app/Entity.php

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -160,44 +160,46 @@ public function getShortName($length = 25)
160160
public function fullTextSearchQuery($fieldsToSearch, $terms, $wheres = [])
161161
{
162162
$exactTerms = [];
163-
if (count($terms) === 0) {
164-
$search = $this;
165-
$orderBy = 'updated_at';
166-
} else {
167-
foreach ($terms as $key => $term) {
168-
$term = htmlentities($term, ENT_QUOTES);
169-
$term = preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $term);
170-
if (preg_match('/&quot;.*?&quot;/', $term)) {
171-
$term = str_replace('&quot;', '', $term);
172-
$exactTerms[] = '%' . $term . '%';
173-
$term = '"' . $term . '"';
174-
} else {
175-
$term = '' . $term . '*';
176-
}
177-
if ($term !== '*') $terms[$key] = $term;
163+
$fuzzyTerms = [];
164+
$search = static::newQuery();
165+
foreach ($terms as $key => $term) {
166+
$safeTerm = htmlentities($term, ENT_QUOTES);
167+
$safeTerm = preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $safeTerm);
168+
if (preg_match('/&quot;.*?&quot;/', $safeTerm) || is_numeric($safeTerm)) {
169+
$safeTerm = preg_replace('/^"(.*?)"$/', '$1', $term);
170+
$exactTerms[] = '%' . $safeTerm . '%';
171+
} else {
172+
$safeTerm = '' . $safeTerm . '*';
173+
if (trim($safeTerm) !== '*') $fuzzyTerms[] = $safeTerm;
178174
}
179-
$termString = implode(' ', $terms);
175+
}
176+
$isFuzzy = count($exactTerms) === 0 || count($fuzzyTerms) > 0;
177+
178+
// Perform fulltext search if relevant terms exist.
179+
if ($isFuzzy) {
180+
$termString = implode(' ', $fuzzyTerms);
180181
$fields = implode(',', $fieldsToSearch);
181-
$search = static::selectRaw('*, MATCH(name) AGAINST(? IN BOOLEAN MODE) AS title_relevance', [$termString]);
182+
$search = $search->selectRaw('*, MATCH(name) AGAINST(? IN BOOLEAN MODE) AS title_relevance', [$termString]);
182183
$search = $search->whereRaw('MATCH(' . $fields . ') AGAINST(? IN BOOLEAN MODE)', [$termString]);
184+
}
183185

184-
// Ensure at least one exact term matches if in search
185-
if (count($exactTerms) > 0) {
186-
$search = $search->where(function ($query) use ($exactTerms, $fieldsToSearch) {
187-
foreach ($exactTerms as $exactTerm) {
188-
foreach ($fieldsToSearch as $field) {
189-
$query->orWhere($field, 'like', $exactTerm);
190-
}
186+
// Ensure at least one exact term matches if in search
187+
if (count($exactTerms) > 0) {
188+
$search = $search->where(function ($query) use ($exactTerms, $fieldsToSearch) {
189+
foreach ($exactTerms as $exactTerm) {
190+
foreach ($fieldsToSearch as $field) {
191+
$query->orWhere($field, 'like', $exactTerm);
191192
}
192-
});
193-
}
194-
$orderBy = 'title_relevance';
195-
};
193+
}
194+
});
195+
}
196+
$orderBy = $isFuzzy ? 'title_relevance' : 'updated_at';
196197

197198
// Add additional where terms
198199
foreach ($wheres as $whereTerm) {
199200
$search->where($whereTerm[0], $whereTerm[1], $whereTerm[2]);
200201
}
202+
201203
// Load in relations
202204
if ($this->isA('page')) {
203205
$search = $search->with('book', 'chapter', 'createdBy', 'updatedBy');

app/Http/Controllers/Auth/PasswordController.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use BookStack\Http\Controllers\Controller;
66
use Illuminate\Foundation\Auth\ResetsPasswords;
7+
use Illuminate\Http\Request;
8+
use Password;
79

810
class PasswordController extends Controller
911
{
@@ -29,4 +31,46 @@ public function __construct()
2931
{
3032
$this->middleware('guest');
3133
}
34+
35+
36+
/**
37+
* Send a reset link to the given user.
38+
*
39+
* @param \Illuminate\Http\Request $request
40+
* @return \Illuminate\Http\Response
41+
*/
42+
public function sendResetLinkEmail(Request $request)
43+
{
44+
$this->validate($request, ['email' => 'required|email']);
45+
46+
$broker = $this->getBroker();
47+
48+
$response = Password::broker($broker)->sendResetLink(
49+
$request->only('email'), $this->resetEmailBuilder()
50+
);
51+
52+
switch ($response) {
53+
case Password::RESET_LINK_SENT:
54+
$message = 'A password reset link has been sent to ' . $request->get('email') . '.';
55+
session()->flash('success', $message);
56+
return $this->getSendResetLinkEmailSuccessResponse($response);
57+
58+
case Password::INVALID_USER:
59+
default:
60+
return $this->getSendResetLinkEmailFailureResponse($response);
61+
}
62+
}
63+
64+
/**
65+
* Get the response for after a successful password reset.
66+
*
67+
* @param string $response
68+
* @return \Symfony\Component\HttpFoundation\Response
69+
*/
70+
protected function getResetSuccessResponse($response)
71+
{
72+
$message = 'Your password has been successfully reset.';
73+
session()->flash('success', $message);
74+
return redirect($this->redirectPath())->with('status', trans($response));
75+
}
3276
}

app/helpers.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ function baseUrl($path, $forceAppDomain = false)
8484
$path = implode('/', array_splice($explodedPath, 3));
8585
}
8686

87+
// Return normal url path if not specified in config
88+
if (config('app.url') === '') {
89+
return url($path);
90+
}
91+
8792
return rtrim(config('app.url'), '/') . '/' . $path;
8893
}
8994

config/setting-defaults.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
'app-name' => 'BookStack',
99
'app-editor' => 'wysiwyg',
1010
'app-color' => '#0288D1',
11-
'app-color-light' => 'rgba(21, 101, 192, 0.15)'
11+
'app-color-light' => 'rgba(21, 101, 192, 0.15)',
12+
'app-custom-head' => false,
13+
'registration-enabled' => false,
1214

1315
];

resources/assets/sass/_blocks.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
border-left: 3px solid #BBB;
136136
background-color: #EEE;
137137
padding: $-s;
138+
display: flex;
138139
&:before {
139140
font-family: 'Material-Design-Iconic-Font';
140141
padding-right: $-s;

resources/assets/sass/_text.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ ul {
252252

253253
ol {
254254
list-style: decimal;
255-
padding-left: $-m * 1.3;
255+
padding-left: $-m * 2;
256256
overflow: hidden;
257257
}
258258

resources/views/auth/password.blade.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
@extends('public')
22

3+
@section('header-buttons')
4+
<a href="{{ baseUrl("/login") }}"><i class="zmdi zmdi-sign-in"></i>Sign in</a>
5+
@if(setting('registration-enabled'))
6+
<a href="{{ baseUrl("/register") }}"><i class="zmdi zmdi-account-add"></i>Sign up</a>
7+
@endif
8+
@stop
9+
310
@section('content')
411

512

resources/views/auth/reset.blade.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
@extends('public')
22

3+
@section('header-buttons')
4+
<a href="{{ baseUrl("/login") }}"><i class="zmdi zmdi-sign-in"></i>Sign in</a>
5+
@if(setting('registration-enabled'))
6+
<a href="{{ baseUrl("/register") }}"><i class="zmdi zmdi-account-add"></i>Sign up</a>
7+
@endif
8+
@stop
9+
310
@section('body-class', 'image-cover login')
411

512
@section('content')

resources/views/base.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
@include('partials/custom-styles')
2424

2525
<!-- Custom user content -->
26-
@if(setting('app-custom-head', false))
26+
@if(setting('app-custom-head'))
2727
{!! setting('app-custom-head') !!}
2828
@endif
2929
</head>

resources/views/emails/email-confirmation.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@
162162
<h1 style="padding-top:0;padding-bottom:0;padding-right:0;padding-left:0;font-family:'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;color:#444;margin-top:10px;margin-bottom:10px;margin-right:0;margin-left:0;line-height:1.2;font-weight:200;font-size:36px;">
163163
Email Confirmation</h1>
164164
<p style="margin-top:0;margin-right:0;margin-left:0;padding-top:0;padding-bottom:0;padding-right:0;padding-left:0;font-family:'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;line-height:1.6;margin-bottom:10px;font-weight:normal;font-size:14px;color:#888888;">
165-
Thanks for joining <a href="{{ baseUrl('/') }}">{{ setting('app-name')}}</a>. <br/>
165+
Thanks for joining <a href="{{ baseUrl('/', true) }}">{{ setting('app-name')}}</a>. <br/>
166166
Please confirm your email address by clicking the button below.</p>
167167
<table style="margin-top:0;margin-bottom:0;margin-right:0;margin-left:0;padding-top:0;padding-bottom:0;padding-right:0;padding-left:0;font-family:'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;font-size:100%;line-height:1.6;width:100%;">
168168
<tr style="margin-top:0;margin-bottom:0;margin-right:0;margin-left:0;padding-top:0;padding-bottom:0;padding-right:0;padding-left:0;font-family:'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;font-size:100%;line-height:1.6;">
169169
<td class="padding"
170170
style="margin-top:0;margin-bottom:0;margin-right:0;margin-left:0;font-family:'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;font-size:100%;line-height:1.6;padding-top:10px;padding-bottom:10px;padding-right:0;padding-left:0;">
171171
<p style="margin-top:0;margin-right:0;margin-left:0;padding-top:0;padding-bottom:0;padding-right:0;padding-left:0;font-family:'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;line-height:1.6;margin-bottom:10px;font-weight:normal;font-size:14px;color:#888888;">
172-
<a class="btn-primary" href="{{ baseUrl('/register/confirm/' . $token) }}"
172+
<a class="btn-primary" href="{{ baseUrl('/register/confirm/' . $token, true) }}"
173173
style="margin-top:0;margin-bottom:0;margin-left:0;padding-top:0;padding-bottom:0;padding-right:0;padding-left:0;font-family:'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;font-size:100%;text-decoration:none;color:#FFF;background-color:#348eda;border-style:solid;border-color:#348eda;border-width:10px 20px;line-height:2;font-weight:bold;margin-right:10px;text-align:center;cursor:pointer;display:inline-block;border-radius:4px;">Confirm
174174
Email</a></p>
175175
</td>

0 commit comments

Comments
 (0)