Skip to content

Commit

Permalink
Merge pull request #142 from viralsolani/develop
Browse files Browse the repository at this point in the history
Test Cases & Major Refactoring
  • Loading branch information
viralsolani authored Jan 12, 2018
2 parents 741aea6 + 1b867e3 commit 9f46d98
Show file tree
Hide file tree
Showing 100 changed files with 3,690 additions and 644 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

# Access
ENABLE_REGISTRATION=true
REQUIRES_APPROVAL=false

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
Expand Down
19 changes: 19 additions & 0 deletions app/Helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ function generateUuid()
return uuid::uuid4();
}

if (!function_exists('homeRoute')) {

/**
* Return the route to the "home" page depending on authentication/authorization status.
*
* @return string
*/
function homeRoute()
{
if (access()->allow('view-backend')) {
return 'admin.dashboard';
} elseif (auth()->check()) {
return 'frontend.user.dashboard';
}

return 'frontend.index';
}
}

/*
* Global helpers file with misc functions.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,49 +57,49 @@ public function store(StoreBlogCategoriesRequest $request)
$this->blogcategory->create($request->all());

return redirect()
->route('admin.blogcategories.index')
->route('admin.blogCategories.index')
->with('flash_success', trans('alerts.backend.blogcategories.created'));
}

/**
* @param \App\Models\BlogCategories\BlogCategory $blogcategory
* @param \App\Models\BlogCategories\BlogCategory $blogCategory
* @param \App\Http\Requests\Backend\BlogCategories\EditBlogCategoriesRequest $request
*
* @return mixed
*/
public function edit(BlogCategory $blogcategory, EditBlogCategoriesRequest $request)
public function edit(BlogCategory $blogCategory, EditBlogCategoriesRequest $request)
{
return view('backend.blogcategories.edit')
->with('blogcategory', $blogcategory);
->with('blogcategory', $blogCategory);
}

/**
* @param \App\Models\BlogCategories\BlogCategory $blogcategory
* @param \App\Models\BlogCategories\BlogCategory $blogCategory
* @param \App\Http\Requests\Backend\BlogCategories\UpdateBlogCategoriesRequest $request
*
* @return mixed
*/
public function update(BlogCategory $blogcategory, UpdateBlogCategoriesRequest $request)
public function update(BlogCategory $blogCategory, UpdateBlogCategoriesRequest $request)
{
$this->blogcategory->update($blogcategory, $request->all());
$this->blogcategory->update($blogCategory, $request->all());

return redirect()
->route('admin.blogcategories.index')
->route('admin.blogCategories.index')
->with('flash_success', trans('alerts.backend.blogcategories.updated'));
}

/**
* @param \App\Models\BlogCategories\BlogCategory $blogcategory
* @param \App\Models\BlogCategories\BlogCategory $blogCategory
* @param \App\Http\Requests\Backend\BlogCategories\DeleteBlogCategoriesRequest $request
*
* @return mixed
*/
public function destroy(BlogCategory $blogcategory, DeleteBlogCategoriesRequest $request)
public function destroy(BlogCategory $blogCategory, DeleteBlogCategoriesRequest $request)
{
$this->blogcategory->delete($blogcategory);
$this->blogcategory->delete($blogCategory);

return redirect()
->route('admin.blogcategories.index')
->route('admin.blogCategories.index')
->with('flash_success', trans('alerts.backend.blogcategories.deleted'));
}
}
24 changes: 12 additions & 12 deletions app/Http/Controllers/Backend/BlogTags/BlogTagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,49 +60,49 @@ public function store(StoreBlogTagsRequest $request)
$this->blogtag->create($request->except('token'));

return redirect()
->route('admin.blogtags.index')
->route('admin.blogTags.index')
->with('flash_success', trans('alerts.backend.blogtags.created'));
}

/**
* @param \App\Models\BlogTags\BlogTag $blogtag
* @param \App\Models\BlogTags\BlogTag $blogTag
* @param \App\Http\Requests\Backend\BlogTags\EditBlogTagsRequest $request
*
* @return mixed
*/
public function edit(BlogTag $blogtag, EditBlogTagsRequest $request)
public function edit(BlogTag $blogTag, EditBlogTagsRequest $request)
{
return view('backend.blogtags.edit')
->with('blogtag', $blogtag);
->with('blogtag', $blogTag);
}

/**
* @param \App\Models\BlogTags\BlogTag $blogtag
* @param \App\Models\BlogTags\BlogTag $blogTag
* @param \App\Http\Requests\Backend\BlogTags\UpdateBlogTagsRequest $request
*
* @return mixed
*/
public function update(BlogTag $blogtag, UpdateBlogTagsRequest $request)
public function update(BlogTag $blogTag, UpdateBlogTagsRequest $request)
{
$this->blogtag->update($blogtag, $request->except(['_method', '_token']));
$this->blogtag->update($blogTag, $request->except(['_method', '_token']));

return redirect()
->route('admin.blogtags.index')
->route('admin.blogTags.index')
->with('flash_success', trans('alerts.backend.blogtags.updated'));
}

/**
* @param \App\Models\BlogTags\BlogTag $blogtag
* @param \App\Models\BlogTags\BlogTag $blogTag
* @param \App\Http\Requests\Backend\BlogTags\DeleteBlogTagsRequest $request
*
* @return mixed
*/
public function destroy(BlogTag $blogtag, DeleteBlogTagsRequest $request)
public function destroy(BlogTag $blogTag, DeleteBlogTagsRequest $request)
{
$this->blogtag->delete($blogtag);
$this->blogtag->delete($blogTag);

return redirect()
->route('admin.blogtags.index')
->route('admin.blogTags.index')
->with('flash_success', trans('alerts.backend.blogtags.deleted'));
}
}
17 changes: 8 additions & 9 deletions app/Http/Controllers/Backend/Pages/PagesTableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Http\Controllers\Controller;
use App\Http\Requests\Backend\Pages\ManagePageRequest;
use App\Repositories\Backend\Pages\PagesRepository;
use Carbon\Carbon;
use Yajra\DataTables\Facades\DataTables;

/**
Expand All @@ -32,17 +31,17 @@ public function __invoke(ManagePageRequest $request)
{
return Datatables::of($this->pages->getForDataTable())
->escapeColumns(['title'])
->addColumn('status', function ($pages) {
return $pages->status_label;
->addColumn('status', function ($page) {
return $page->status_label;
})
->addColumn('created_at', function ($pages) {
return Carbon::parse($pages->created_at)->toDateString();
->addColumn('created_at', function ($page) {
return $page->created_at->toDateString();
})
->addColumn('updated_at', function ($pages) {
return Carbon::parse($pages->updated_at)->toDateString();
->addColumn('created_by', function ($page) {
return $page->created_by;
})
->addColumn('actions', function ($pages) {
return $pages->action_buttons;
->addColumn('actions', function ($page) {
return $page->action_buttons;
})
->make(true);
}
Expand Down
19 changes: 0 additions & 19 deletions app/Http/Controllers/Backend/Settings/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Http\Requests\Backend\Settings\UpdateSettingsRequest;
use App\Models\Settings\Setting;
use App\Repositories\Backend\Settings\SettingsRepository;
use Illuminate\Http\Request;

/**
* Class SettingsController.
Expand Down Expand Up @@ -50,22 +49,4 @@ public function update(Setting $setting, UpdateSettingsRequest $request)
->route('admin.settings.edit', $setting->id)
->with('flash_success', trans('alerts.backend.settings.updated'));
}

/**
* @param Setting $setting
* @param Request $request
* Remove logo or favicon icon
*
* @return mixed
*/
public function removeIcon(Request $request)
{
$this->settings->removeicon($request->data);

return json_encode(
[
'status' => true,
]
);
}
}
41 changes: 41 additions & 0 deletions app/Http/Controllers/Backend/Settings/SettingsLogoController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Http\Controllers\Backend\Settings;

use App\Http\Controllers\Controller;
use App\Models\Settings\Setting;
use App\Repositories\Backend\Settings\SettingsRepository;
use Illuminate\Http\Request;

/**
* Class SettingsLogoController.
*/
class SettingsLogoController extends Controller
{
protected $settings;

/**
* @param \App\Repositories\Backend\Settings\SettingsRepository $settings
*/
public function __construct(SettingsRepository $settings)
{
$this->settings = $settings;
}

/**
* Remove logo or favicon icon.
*
* @param \App\Models\Settings\Setting $setting
* @param \Illuminate\Http\Request $request
*
* @return mixed
*/
public function destroy(Setting $setting, Request $request)
{
$this->settings->removeLogo($setting, $request->data);

return json_encode([
'status' => true,
]);
}
}
18 changes: 17 additions & 1 deletion app/Http/Controllers/Frontend/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function showRegistrationForm()
*/
public function register(RegisterRequest $request)
{
if (config('access.users.confirm_email')) {
/*if (config('access.users.confirm_email')) {
$user = $this->user->create($request->all());
event(new UserRegistered($user));
Expand All @@ -59,6 +59,22 @@ public function register(RegisterRequest $request)
access()->login($this->user->create($request->all()));
event(new UserRegistered(access()->user()));
return redirect($this->redirectPath());
}*/

if (config('access.users.confirm_email') || config('access.users.requires_approval')) {
$user = $this->user->create($request->only('first_name', 'last_name', 'email', 'password', 'is_term_accept'));
event(new UserRegistered($user));

return redirect($this->redirectPath())->withFlashSuccess(
config('access.users.requires_approval') ?
trans('exceptions.frontend.auth.confirmation.created_pending') :
trans('exceptions.frontend.auth.confirmation.created_confirm')
);
} else {
access()->login($this->user->create($request->only('first_name', 'last_name', 'email', 'password', 'is_term_accept')));
event(new UserRegistered(access()->user()));

return redirect($this->redirectPath());
}
}
Expand Down
29 changes: 26 additions & 3 deletions app/Http/Controllers/Frontend/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,20 @@ public function redirectPath()
*/
public function showResetForm($token = null)
{
return view('frontend.auth.passwords.reset')
->withToken($token)
->withEmail($this->user->getEmailForPasswordToken($token));
if (!$token) {
return redirect()->route('frontend.auth.password.email');
}

$user = $this->user->findByPasswordResetToken($token);

if ($user && app()->make('auth.password.broker')->tokenExists($user, $token)) {
return view('frontend.auth.passwords.reset')
->withToken($token)
->withEmail($user->email);
}

return redirect()->route('frontend.auth.password.email')
->withFlashDanger(trans('exceptions.frontend.auth.password.reset_problem'));
}

/**
Expand Down Expand Up @@ -80,4 +91,16 @@ protected function validationErrorMessages()
'password.regex' => 'Password must contain at least 1 uppercase letter and 1 number.',
];
}

/**
* Get the response for a successful password reset.
*
* @param string $response
*
* @return \Illuminate\Http\RedirectResponse
*/
protected function sendResetResponse($response)
{
return redirect()->route(homeRoute())->withFlashSuccess(trans($response));
}
}
15 changes: 14 additions & 1 deletion app/Http/Requests/Backend/Access/Role/StoreRoleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,22 @@ public function authorize()
*/
public function rules()
{
$permissions = '';

if ($this->associated_permissions != 'all') {
$permissions = 'required';
}

return [
'name' => 'required|max:191',
'permissions' => 'required',
'permissions' => $permissions,
];
}

public function messages()
{
return [
'permissions.required' => 'You must select at least one permission for this role.',
];
}
}
15 changes: 14 additions & 1 deletion app/Http/Requests/Backend/Access/Role/UpdateRoleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,22 @@ public function authorize()
*/
public function rules()
{
$permissions = '';

if ($this->associated_permissions != 'all') {
$permissions = 'required';
}

return [
'name' => 'required|max:191',
'permissions' => 'required',
'permissions' => $permissions,
];
}

public function messages()
{
return [
'permissions.required' => 'You must select at least one permission for this role.',
];
}
}
Loading

0 comments on commit 9f46d98

Please sign in to comment.