Skip to content

Commit

Permalink
Merge branch 'v0.12' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddanbrown committed Oct 30, 2016
2 parents f7b01ae + 2af0021 commit 97bbf79
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 39 deletions.
58 changes: 30 additions & 28 deletions app/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,44 +160,46 @@ public function getShortName($length = 25)
public function fullTextSearchQuery($fieldsToSearch, $terms, $wheres = [])
{
$exactTerms = [];
if (count($terms) === 0) {
$search = $this;
$orderBy = 'updated_at';
} else {
foreach ($terms as $key => $term) {
$term = htmlentities($term, ENT_QUOTES);
$term = preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $term);
if (preg_match('/&quot;.*?&quot;/', $term)) {
$term = str_replace('&quot;', '', $term);
$exactTerms[] = '%' . $term . '%';
$term = '"' . $term . '"';
} else {
$term = '' . $term . '*';
}
if ($term !== '*') $terms[$key] = $term;
$fuzzyTerms = [];
$search = static::newQuery();
foreach ($terms as $key => $term) {
$safeTerm = htmlentities($term, ENT_QUOTES);
$safeTerm = preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $safeTerm);
if (preg_match('/&quot;.*?&quot;/', $safeTerm) || is_numeric($safeTerm)) {
$safeTerm = preg_replace('/^"(.*?)"$/', '$1', $term);
$exactTerms[] = '%' . $safeTerm . '%';
} else {
$safeTerm = '' . $safeTerm . '*';
if (trim($safeTerm) !== '*') $fuzzyTerms[] = $safeTerm;
}
$termString = implode(' ', $terms);
}
$isFuzzy = count($exactTerms) === 0 || count($fuzzyTerms) > 0;

// Perform fulltext search if relevant terms exist.
if ($isFuzzy) {
$termString = implode(' ', $fuzzyTerms);
$fields = implode(',', $fieldsToSearch);
$search = static::selectRaw('*, MATCH(name) AGAINST(? IN BOOLEAN MODE) AS title_relevance', [$termString]);
$search = $search->selectRaw('*, MATCH(name) AGAINST(? IN BOOLEAN MODE) AS title_relevance', [$termString]);
$search = $search->whereRaw('MATCH(' . $fields . ') AGAINST(? IN BOOLEAN MODE)', [$termString]);
}

// Ensure at least one exact term matches if in search
if (count($exactTerms) > 0) {
$search = $search->where(function ($query) use ($exactTerms, $fieldsToSearch) {
foreach ($exactTerms as $exactTerm) {
foreach ($fieldsToSearch as $field) {
$query->orWhere($field, 'like', $exactTerm);
}
// Ensure at least one exact term matches if in search
if (count($exactTerms) > 0) {
$search = $search->where(function ($query) use ($exactTerms, $fieldsToSearch) {
foreach ($exactTerms as $exactTerm) {
foreach ($fieldsToSearch as $field) {
$query->orWhere($field, 'like', $exactTerm);
}
});
}
$orderBy = 'title_relevance';
};
}
});
}
$orderBy = $isFuzzy ? 'title_relevance' : 'updated_at';

// Add additional where terms
foreach ($wheres as $whereTerm) {
$search->where($whereTerm[0], $whereTerm[1], $whereTerm[2]);
}

// Load in relations
if ($this->isA('page')) {
$search = $search->with('book', 'chapter', 'createdBy', 'updatedBy');
Expand Down
44 changes: 44 additions & 0 deletions app/Http/Controllers/Auth/PasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use BookStack\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request;
use Password;

class PasswordController extends Controller
{
Expand All @@ -29,4 +31,46 @@ public function __construct()
{
$this->middleware('guest');
}


/**
* Send a reset link to the given user.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function sendResetLinkEmail(Request $request)
{
$this->validate($request, ['email' => 'required|email']);

$broker = $this->getBroker();

$response = Password::broker($broker)->sendResetLink(
$request->only('email'), $this->resetEmailBuilder()
);

switch ($response) {
case Password::RESET_LINK_SENT:
$message = 'A password reset link has been sent to ' . $request->get('email') . '.';
session()->flash('success', $message);
return $this->getSendResetLinkEmailSuccessResponse($response);

case Password::INVALID_USER:
default:
return $this->getSendResetLinkEmailFailureResponse($response);
}
}

/**
* Get the response for after a successful password reset.
*
* @param string $response
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function getResetSuccessResponse($response)
{
$message = 'Your password has been successfully reset.';
session()->flash('success', $message);
return redirect($this->redirectPath())->with('status', trans($response));
}
}
5 changes: 5 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ function baseUrl($path, $forceAppDomain = false)
$path = implode('/', array_splice($explodedPath, 3));
}

// Return normal url path if not specified in config
if (config('app.url') === '') {
return url($path);
}

return rtrim(config('app.url'), '/') . '/' . $path;
}

Expand Down
4 changes: 3 additions & 1 deletion config/setting-defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
'app-name' => 'BookStack',
'app-editor' => 'wysiwyg',
'app-color' => '#0288D1',
'app-color-light' => 'rgba(21, 101, 192, 0.15)'
'app-color-light' => 'rgba(21, 101, 192, 0.15)',
'app-custom-head' => false,
'registration-enabled' => false,

];
1 change: 1 addition & 0 deletions resources/assets/sass/_blocks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
border-left: 3px solid #BBB;
background-color: #EEE;
padding: $-s;
display: flex;
&:before {
font-family: 'Material-Design-Iconic-Font';
padding-right: $-s;
Expand Down
2 changes: 1 addition & 1 deletion resources/assets/sass/_text.scss
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ ul {

ol {
list-style: decimal;
padding-left: $-m * 1.3;
padding-left: $-m * 2;
overflow: hidden;
}

Expand Down
7 changes: 7 additions & 0 deletions resources/views/auth/password.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
@extends('public')

@section('header-buttons')
<a href="{{ baseUrl("/login") }}"><i class="zmdi zmdi-sign-in"></i>Sign in</a>
@if(setting('registration-enabled'))
<a href="{{ baseUrl("/register") }}"><i class="zmdi zmdi-account-add"></i>Sign up</a>
@endif
@stop

@section('content')


Expand Down
7 changes: 7 additions & 0 deletions resources/views/auth/reset.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
@extends('public')

@section('header-buttons')
<a href="{{ baseUrl("/login") }}"><i class="zmdi zmdi-sign-in"></i>Sign in</a>
@if(setting('registration-enabled'))
<a href="{{ baseUrl("/register") }}"><i class="zmdi zmdi-account-add"></i>Sign up</a>
@endif
@stop

@section('body-class', 'image-cover login')

@section('content')
Expand Down
2 changes: 1 addition & 1 deletion resources/views/base.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@include('partials/custom-styles')

<!-- Custom user content -->
@if(setting('app-custom-head', false))
@if(setting('app-custom-head'))
{!! setting('app-custom-head') !!}
@endif
</head>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/emails/email-confirmation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@
<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;">
Email Confirmation</h1>
<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;">
Thanks for joining <a href="{{ baseUrl('/') }}">{{ setting('app-name')}}</a>. <br/>
Thanks for joining <a href="{{ baseUrl('/', true) }}">{{ setting('app-name')}}</a>. <br/>
Please confirm your email address by clicking the button below.</p>
<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%;">
<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;">
<td class="padding"
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;">
<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;">
<a class="btn-primary" href="{{ baseUrl('/register/confirm/' . $token) }}"
<a class="btn-primary" href="{{ baseUrl('/register/confirm/' . $token, true) }}"
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
Email</a></p>
</td>
Expand Down
Loading

0 comments on commit 97bbf79

Please sign in to comment.