Skip to content

Commit

Permalink
Merge branch 'laravel-5.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
brokenhd committed Apr 6, 2017
2 parents 67dc6ce + 9d15c7f commit 53b9a04
Show file tree
Hide file tree
Showing 69 changed files with 871 additions and 614 deletions.
4 changes: 2 additions & 2 deletions classes/Controllers/Elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function index($locale = null, $tab = null)

// If handling a deep link to a tab, verify that the passed tab
// slug is a real key in the data. Else 404.
if ($tab && !in_array($tab, $elements->lists('page_label')
if ($tab && !in_array($tab, $elements->pluck('page_label')
->map(function ($title) {
return Str::slug($title);
})
Expand Down Expand Up @@ -288,7 +288,7 @@ protected function storeImage(Element $el, $input)
// Check for the image in the input. If isn't found, make no changes.
$name = $el->inputName();
if (!$data = array_first($input['images'],
function ($id, $data) use ($name) {
function ($data, $id) use ($name) {
return $data['name'] == $name;
})) {
return;
Expand Down
42 changes: 42 additions & 0 deletions classes/Controllers/ForgotPassword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Bkwld\Decoy\Controllers;

use Auth;
use Decoy;
use Former;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Bkwld\Decoy\Models\Admin;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;

class ForgotPassword extends Base
{

use SendsPasswordResetEmails;

/**
* Display the form to request a password reset link.
*
* @return \Illuminate\Http\Response
*/
public function showLinkRequestForm()
{
// Pass validation rules
Former::withRules([
'email' => 'required|email',
]);

// Set the breadcrumbs
app('decoy.breadcrumbs')->set([
route('decoy::account@login') => 'Login',
url()->current() => 'Forgot Password',
]);

// Show the page
$this->title = 'Forgot Password';
$this->description = 'You know the drill.';

return $this->populateView('decoy::account.forgot');
}
}
7 changes: 3 additions & 4 deletions classes/Controllers/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Auth;
use Former;
use Illuminate\Routing\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Foundation\Validation\ValidatesRequests;

Expand All @@ -15,7 +14,7 @@
*/
class Login extends Controller
{
use AuthenticatesUsers, ThrottlesLogins, ValidatesRequests;
use AuthenticatesUsers, ValidatesRequests;

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

/**
Expand Down Expand Up @@ -55,7 +54,7 @@ public function showLoginForm()
public function logout()
{
// Logout the session
Auth::guard($this->getGuard())->logout();
Auth::logout();

// Redirect back to previous page so that switching users takes you back to
// your previous page.
Expand Down
37 changes: 1 addition & 36 deletions classes/Controllers/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,6 @@ class ResetPassword extends Base
{
use ResetsPasswords;

/**
* Display the form to request a password reset link.
*
* @return \Illuminate\Http\Response
*/
public function showLinkRequestForm()
{
// Pass validation rules
Former::withRules([
'email' => 'required|email',
]);

// Set the breadcrumbs
app('decoy.breadcrumbs')->set([
route('decoy::account@login') => 'Login',
url()->current() => 'Forgot Password',
]);

// Show the page
$this->title = 'Forgot Password';
$this->description = 'You know the drill.';

return $this->populateView('decoy::account.forgot');
}

/**
* Get the e-mail subject line to be used for the reset link email.
*
* @return string
*/
protected function getEmailSubject()
{
return 'Recover access to '.Decoy::site();
}

/**
* Display the password reset view for the given token.
*
Expand Down Expand Up @@ -120,6 +85,6 @@ protected function resetPassword($user, $password)
'remember_token' => Str::random(60),
])->save();

Auth::guard($this->getGuard())->login($user);
Auth::login($user);
}
}
2 changes: 1 addition & 1 deletion classes/Input/Localize.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function localizableLocales()
Config::get('decoy.site.locales'),

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

// ... and the model's locale
[$this->item->locale => null]
Expand Down
16 changes: 15 additions & 1 deletion classes/Models/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
use DecoyURL;
use Bkwld\Library\Utils\Text;
use Bkwld\Decoy\Auth\AuthInterface;
use Bkwld\Decoy\Notifications\ResetPassword;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Notifications\Notifiable;

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

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

/**
* Send the password reset notification. This overrides a method inheritted
* from the CanResetPassword trait
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPassword($token));
}

/**
* A shorthand for getting the admin name as a string
*
Expand Down
41 changes: 22 additions & 19 deletions classes/Models/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@
use Bkwld\Upchuck\SupportsUploads;
use Bkwld\Library\Utils\Collection;
use Bkwld\Decoy\Exceptions\Exception;
use Cviebrock\EloquentSluggable\SluggableTrait;
use Cviebrock\EloquentSluggable\Sluggable;
use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
use Bkwld\Decoy\Collections\Base as BaseCollection;
use Cviebrock\EloquentSluggable\SluggableInterface;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

abstract class Base extends Eloquent implements SluggableInterface
abstract class Base extends Eloquent
{

/**
* Adding common traits. The memory usage of adding additional methods is
* negligible.
*/
use Cloneable,
SluggableTrait,
Sluggable,
SluggableScopeHelpers,
SupportsUploads,
Traits\CanSerializeTransform {
needsSlugging as traitNeedsSlugging;
}
Traits\CanSerializeTransform
;

/**
* Use the Decoy Base Collection
Expand Down Expand Up @@ -195,12 +195,18 @@ public function changes()
* Tell sluggable where to get the source for the slug and apply other
* customizations.
*
* @var array
* @return array
*/
protected $sluggable = [
'build_from' => 'admin_title',
'max_length' => 100,
];
public function sluggable()
{
if (!$this->needsSlugging()) return [];
return [
'slug' => [
'source' => 'admin_title',
'maxLength' => 100,
]
];
}

/**
* Check for a validation rule for a slug column
Expand All @@ -209,11 +215,7 @@ public function changes()
*/
protected function needsSlugging()
{
if (!array_key_exists('slug', static::$rules)) {
return false;
}

return $this->traitNeedsSlugging();
return array_key_exists('slug', static::$rules);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -636,12 +638,13 @@ public function scopeOtherLocalizations($query)
* Find by the slug and fail if missing. Invokes methods from the
* Sluggable trait.
*
* @param string $string
* @param string $string
* @param array $columns
* @return Illuminate\Database\Eloquent\Model
*
* @throws Illuminate\Database\Eloquent\ModelNotFoundException
*/
public static function findBySlugOrFail($slug)
public static function findBySlugOrFail($slug, array $columns = ['*'])
{
// Model not found, throw exception
if (!$item = static::findBySlug($slug)) {
Expand Down
4 changes: 2 additions & 2 deletions classes/Models/Change.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static function log(Model $model, $action, Admin $admin = null)
*/
public static function getActions()
{
return static::groupBy('action')->lists('action', 'action');
return static::groupBy('action')->pluck('action', 'action');
}

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

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/Models/Traits/HasImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function images()
*/
public function img($name = null)
{
return $this->images->first(function ($key, Image $image) use ($name) {
return $this->images->first(function (Image $image, $key) use ($name) {
return $image->getAttribute('name') == $name;

// When the $name isn't found, return an empty Image object so all the
Expand Down
36 changes: 36 additions & 0 deletions classes/Notifications/ResetPassword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Bkwld\Decoy\Notifications;

// Deps
use Decoy;
use Illuminate\Auth\Notifications\ResetPassword as LaravelResetPassword;
use Illuminate\Notifications\Messages\MailMessage;

/**
* Subclass the Laravel reset password so we can send admin to the /admin
*/
class ResetPassword extends LaravelResetPassword
{

/**
* Build the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
// Make the URL
$dir = config('decoy.core.dir');
$url = url($dir.'/password/reset', $this->token);

// Send the message
return (new MailMessage)
->subject('Recover access to '.Decoy::site())
->line('You are receiving this email because we received a password reset request for your account.')
->action('Reset Password', $url)
->line('If you did not request a password reset, no further action is required.');
}

}
Loading

0 comments on commit 53b9a04

Please sign in to comment.