Skip to content

Commit 53b9a04

Browse files
committed
Merge branch 'laravel-5.3'
2 parents 67dc6ce + 9d15c7f commit 53b9a04

File tree

69 files changed

+871
-614
lines changed

Some content is hidden

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

69 files changed

+871
-614
lines changed

classes/Controllers/Elements.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function index($locale = null, $tab = null)
5858

5959
// If handling a deep link to a tab, verify that the passed tab
6060
// slug is a real key in the data. Else 404.
61-
if ($tab && !in_array($tab, $elements->lists('page_label')
61+
if ($tab && !in_array($tab, $elements->pluck('page_label')
6262
->map(function ($title) {
6363
return Str::slug($title);
6464
})
@@ -288,7 +288,7 @@ protected function storeImage(Element $el, $input)
288288
// Check for the image in the input. If isn't found, make no changes.
289289
$name = $el->inputName();
290290
if (!$data = array_first($input['images'],
291-
function ($id, $data) use ($name) {
291+
function ($data, $id) use ($name) {
292292
return $data['name'] == $name;
293293
})) {
294294
return;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Bkwld\Decoy\Controllers;
4+
5+
use Auth;
6+
use Decoy;
7+
use Former;
8+
use Illuminate\Support\Str;
9+
use Illuminate\Http\Request;
10+
use Bkwld\Decoy\Models\Admin;
11+
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
12+
13+
class ForgotPassword extends Base
14+
{
15+
16+
use SendsPasswordResetEmails;
17+
18+
/**
19+
* Display the form to request a password reset link.
20+
*
21+
* @return \Illuminate\Http\Response
22+
*/
23+
public function showLinkRequestForm()
24+
{
25+
// Pass validation rules
26+
Former::withRules([
27+
'email' => 'required|email',
28+
]);
29+
30+
// Set the breadcrumbs
31+
app('decoy.breadcrumbs')->set([
32+
route('decoy::account@login') => 'Login',
33+
url()->current() => 'Forgot Password',
34+
]);
35+
36+
// Show the page
37+
$this->title = 'Forgot Password';
38+
$this->description = 'You know the drill.';
39+
40+
return $this->populateView('decoy::account.forgot');
41+
}
42+
}

classes/Controllers/Login.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Auth;
66
use Former;
77
use Illuminate\Routing\Controller;
8-
use Illuminate\Foundation\Auth\ThrottlesLogins;
98
use Illuminate\Foundation\Auth\AuthenticatesUsers;
109
use Illuminate\Foundation\Validation\ValidatesRequests;
1110

@@ -15,7 +14,7 @@
1514
*/
1615
class Login extends Controller
1716
{
18-
use AuthenticatesUsers, ThrottlesLogins, ValidatesRequests;
17+
use AuthenticatesUsers, ValidatesRequests;
1918

2019
/**
2120
* Use the guest middleware to redirect logged in admins away from the login
@@ -25,7 +24,7 @@ class Login extends Controller
2524
*/
2625
public function __construct()
2726
{
28-
$this->middleware('decoy.guest', ['except' => 'getLogout']);
27+
$this->middleware('decoy.guest', ['except' => 'logout']);
2928
}
3029

3130
/**
@@ -55,7 +54,7 @@ public function showLoginForm()
5554
public function logout()
5655
{
5756
// Logout the session
58-
Auth::guard($this->getGuard())->logout();
57+
Auth::logout();
5958

6059
// Redirect back to previous page so that switching users takes you back to
6160
// your previous page.

classes/Controllers/ResetPassword.php

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,6 @@ class ResetPassword extends Base
1818
{
1919
use ResetsPasswords;
2020

21-
/**
22-
* Display the form to request a password reset link.
23-
*
24-
* @return \Illuminate\Http\Response
25-
*/
26-
public function showLinkRequestForm()
27-
{
28-
// Pass validation rules
29-
Former::withRules([
30-
'email' => 'required|email',
31-
]);
32-
33-
// Set the breadcrumbs
34-
app('decoy.breadcrumbs')->set([
35-
route('decoy::account@login') => 'Login',
36-
url()->current() => 'Forgot Password',
37-
]);
38-
39-
// Show the page
40-
$this->title = 'Forgot Password';
41-
$this->description = 'You know the drill.';
42-
43-
return $this->populateView('decoy::account.forgot');
44-
}
45-
46-
/**
47-
* Get the e-mail subject line to be used for the reset link email.
48-
*
49-
* @return string
50-
*/
51-
protected function getEmailSubject()
52-
{
53-
return 'Recover access to '.Decoy::site();
54-
}
55-
5621
/**
5722
* Display the password reset view for the given token.
5823
*
@@ -120,6 +85,6 @@ protected function resetPassword($user, $password)
12085
'remember_token' => Str::random(60),
12186
])->save();
12287

123-
Auth::guard($this->getGuard())->login($user);
88+
Auth::login($user);
12489
}
12590
}

classes/Input/Localize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function localizableLocales()
121121
Config::get('decoy.site.locales'),
122122

123123
// ... the locales of other localizations ...
124-
$this->other()->lists('locale')->flip()->toArray(),
124+
$this->other()->pluck('locale')->flip()->toArray(),
125125

126126
// ... and the model's locale
127127
[$this->item->locale => null]

classes/Models/Admin.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
use DecoyURL;
1313
use Bkwld\Library\Utils\Text;
1414
use Bkwld\Decoy\Auth\AuthInterface;
15+
use Bkwld\Decoy\Notifications\ResetPassword;
1516
use Illuminate\Auth\Authenticatable;
1617
use Illuminate\Contracts\Auth\Access\Gate;
1718
use Illuminate\Auth\Passwords\CanResetPassword;
1819
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
1920
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
21+
use Illuminate\Notifications\Notifiable;
2022

2123
class Admin extends Base implements
2224
AuthInterface,
@@ -25,7 +27,7 @@ class Admin extends Base implements
2527
{
2628
// Note, not using the Authorizable trait because I've defined my own versions
2729
// for backwards compatability with Decoy 4 and also to have a tigher syntax.
28-
use Authenticatable, CanResetPassword, Traits\HasImages;
30+
use Authenticatable, CanResetPassword, Traits\HasImages, Notifiable;
2931

3032
/**
3133
* The table associated with the model. Explicitly declaring so that sub
@@ -248,6 +250,18 @@ public function cannot($action, $controller)
248250
return $this->cant($action, $controller);
249251
}
250252

253+
/**
254+
* Send the password reset notification. This overrides a method inheritted
255+
* from the CanResetPassword trait
256+
*
257+
* @param string $token
258+
* @return void
259+
*/
260+
public function sendPasswordResetNotification($token)
261+
{
262+
$this->notify(new ResetPassword($token));
263+
}
264+
251265
/**
252266
* A shorthand for getting the admin name as a string
253267
*

classes/Models/Base.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@
1414
use Bkwld\Upchuck\SupportsUploads;
1515
use Bkwld\Library\Utils\Collection;
1616
use Bkwld\Decoy\Exceptions\Exception;
17-
use Cviebrock\EloquentSluggable\SluggableTrait;
17+
use Cviebrock\EloquentSluggable\Sluggable;
18+
use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
1819
use Bkwld\Decoy\Collections\Base as BaseCollection;
19-
use Cviebrock\EloquentSluggable\SluggableInterface;
2020
use Illuminate\Database\Eloquent\Model as Eloquent;
2121
use Illuminate\Database\Eloquent\ModelNotFoundException;
2222
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
2323

24-
abstract class Base extends Eloquent implements SluggableInterface
24+
abstract class Base extends Eloquent
2525
{
2626

2727
/**
2828
* Adding common traits. The memory usage of adding additional methods is
2929
* negligible.
3030
*/
3131
use Cloneable,
32-
SluggableTrait,
32+
Sluggable,
33+
SluggableScopeHelpers,
3334
SupportsUploads,
34-
Traits\CanSerializeTransform {
35-
needsSlugging as traitNeedsSlugging;
36-
}
35+
Traits\CanSerializeTransform
36+
;
3737

3838
/**
3939
* Use the Decoy Base Collection
@@ -195,12 +195,18 @@ public function changes()
195195
* Tell sluggable where to get the source for the slug and apply other
196196
* customizations.
197197
*
198-
* @var array
198+
* @return array
199199
*/
200-
protected $sluggable = [
201-
'build_from' => 'admin_title',
202-
'max_length' => 100,
203-
];
200+
public function sluggable()
201+
{
202+
if (!$this->needsSlugging()) return [];
203+
return [
204+
'slug' => [
205+
'source' => 'admin_title',
206+
'maxLength' => 100,
207+
]
208+
];
209+
}
204210

205211
/**
206212
* Check for a validation rule for a slug column
@@ -209,11 +215,7 @@ public function changes()
209215
*/
210216
protected function needsSlugging()
211217
{
212-
if (!array_key_exists('slug', static::$rules)) {
213-
return false;
214-
}
215-
216-
return $this->traitNeedsSlugging();
218+
return array_key_exists('slug', static::$rules);
217219
}
218220

219221
//---------------------------------------------------------------------------
@@ -636,12 +638,13 @@ public function scopeOtherLocalizations($query)
636638
* Find by the slug and fail if missing. Invokes methods from the
637639
* Sluggable trait.
638640
*
639-
* @param string $string
641+
* @param string $string
642+
* @param array $columns
640643
* @return Illuminate\Database\Eloquent\Model
641644
*
642645
* @throws Illuminate\Database\Eloquent\ModelNotFoundException
643646
*/
644-
public static function findBySlugOrFail($slug)
647+
public static function findBySlugOrFail($slug, array $columns = ['*'])
645648
{
646649
// Model not found, throw exception
647650
if (!$item = static::findBySlug($slug)) {

classes/Models/Change.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public static function log(Model $model, $action, Admin $admin = null)
130130
*/
131131
public static function getActions()
132132
{
133-
return static::groupBy('action')->lists('action', 'action');
133+
return static::groupBy('action')->pluck('action', 'action');
134134
}
135135

136136
/**
@@ -144,7 +144,7 @@ public static function getAdmins()
144144
return static::groupBy('admin_id')
145145
->join('admins', 'admins.id', '=', 'admin_id')
146146
->select(DB::raw('changes.id, CONCAT(first_name, " ", last_name) name'))
147-
->lists('name', 'id');
147+
->pluck('name', 'id');
148148
}
149149

150150
/**

classes/Models/Traits/HasImages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function images()
5858
*/
5959
public function img($name = null)
6060
{
61-
return $this->images->first(function ($key, Image $image) use ($name) {
61+
return $this->images->first(function (Image $image, $key) use ($name) {
6262
return $image->getAttribute('name') == $name;
6363

6464
// When the $name isn't found, return an empty Image object so all the
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Bkwld\Decoy\Notifications;
4+
5+
// Deps
6+
use Decoy;
7+
use Illuminate\Auth\Notifications\ResetPassword as LaravelResetPassword;
8+
use Illuminate\Notifications\Messages\MailMessage;
9+
10+
/**
11+
* Subclass the Laravel reset password so we can send admin to the /admin
12+
*/
13+
class ResetPassword extends LaravelResetPassword
14+
{
15+
16+
/**
17+
* Build the mail representation of the notification.
18+
*
19+
* @param mixed $notifiable
20+
* @return \Illuminate\Notifications\Messages\MailMessage
21+
*/
22+
public function toMail($notifiable)
23+
{
24+
// Make the URL
25+
$dir = config('decoy.core.dir');
26+
$url = url($dir.'/password/reset', $this->token);
27+
28+
// Send the message
29+
return (new MailMessage)
30+
->subject('Recover access to '.Decoy::site())
31+
->line('You are receiving this email because we received a password reset request for your account.')
32+
->action('Reset Password', $url)
33+
->line('If you did not request a password reset, no further action is required.');
34+
}
35+
36+
}

0 commit comments

Comments
 (0)