Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BlazOrazem committed Jun 21, 2017
1 parent 9aa7b54 commit 90bf9c5
Show file tree
Hide file tree
Showing 23 changed files with 248 additions and 49 deletions.
4 changes: 3 additions & 1 deletion .env.example
@@ -1,5 +1,5 @@
APP_ENV=local
APP_KEY=SomeRandomString
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=
Expand Down Expand Up @@ -32,6 +32,8 @@ MAIL_FROM_NAME=
MAILGUN_DOMAIN=
MAILGUN_SECRET=

SPARKPOST_SECRET=

PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=
Expand Down
14 changes: 14 additions & 0 deletions app/Console/Commands/ProjectInstall.php
Expand Up @@ -58,6 +58,9 @@ public function handle()
$this->comment('| Application settings |');
$this->comment('------------------------');

$appName = $this->ask('Enter your application name (eg. My Company)');
$appMail = $this->ask('Enter your application email (eg. info@test.com)');

$appUrl = $this->ask('Enter the URL of your application without trailing slash (eg. http://www.numencode.app)');
fwrite($env, 'APP_URL=' . $appUrl . PHP_EOL);
fwrite($env, PHP_EOL);
Expand All @@ -79,6 +82,16 @@ public function handle()
$dbPass = $this->ask('Enter the DB password');
fwrite($env, 'DB_PASSWORD=' . $dbPass . PHP_EOL);

fwrite($env, PHP_EOL);
fwrite($env, 'MAIL_DRIVER=log' . PHP_EOL);
fwrite($env, 'MAIL_HOST=' . PHP_EOL);
fwrite($env, 'MAIL_PORT=' . PHP_EOL);
fwrite($env, 'MAIL_USERNAME=' . PHP_EOL);
fwrite($env, 'MAIL_PASSWORD=' . PHP_EOL);
fwrite($env, 'MAIL_ENCRYPTION=null' . PHP_EOL);
fwrite($env, 'MAIL_FROM_ADDRESS=' . $appMail . PHP_EOL);
fwrite($env, 'MAIL_FROM_NAME="' . $appName . '"' . PHP_EOL);

fwrite($env, PHP_EOL);
fwrite($env, 'GOOGLE_ANALYTICS=');

Expand Down Expand Up @@ -186,6 +199,7 @@ public function handle()

// Silently setup the application key again to prevent any errors

sleep(3);
$appKey = $this->getFreshApplication();
$artisanKey = $appKey['artisan'];
$artisanKey::call('key:generate');
Expand Down
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Expand Up @@ -60,6 +60,7 @@ class Kernel extends HttpKernel

'is_authenticated' => \Cms\Http\Middleware\IsAuthenticated::class,
'is_guest' => \Cms\Http\Middleware\IsGuest::class,
'allowance' => \Cms\Http\Middleware\CheckAllowance::class,
'localization' => \Cms\Http\Middleware\Localization::class,
];
}
12 changes: 12 additions & 0 deletions app/Models/Blog/BlogItem.php
Expand Up @@ -65,6 +65,18 @@ public function comments()
return $this->hasMany(BlogItemComment::class);
}

/**
* Blog item has published comments.
*
* @return object
*/
public function publishedComments()
{
return $this->comments->filter(function ($value) {
return $value->is_published;
});
}

/**
* Blog category belongs to url.
*
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Blog/BlogItemComment.php
Expand Up @@ -22,7 +22,7 @@ class BlogItemComment extends Model
*
* @var array
*/
protected $fillable = ['comment'];
protected $fillable = ['user_id', 'is_published', 'comment'];

/**
* No fallback translation.
Expand Down
33 changes: 23 additions & 10 deletions app/Models/User/Traits/UserRoles.php
Expand Up @@ -2,12 +2,13 @@

namespace Numencode\Models\User\Traits;

use Illuminate\Database\Eloquent\Collection;
use Numencode\Models\User\Role;

trait UserRoles
{
/**
* Return the entity's roles.
* User can have many roles.
*
* @return object
*/
Expand All @@ -17,23 +18,31 @@ public function roles()
}

/**
* Assign a role to the entity.
* Assign roles to the user.
*
* @param string $role Role name
* @param array $roleIds Role IDs
*
* @return mixed
* @return null
*/
public function assignRole($role)
public function assignRoles(array $roleIds)
{
return $this->roles()->save(
Role::where($role)->firstOrFail()
);
foreach ($roleIds as $roleId) {
$role = Role::find($roleId);

if ($this->hasRole($role->name)) {
continue;
}

$this->roles()->save($role);
}

return true;
}

/**
* Determine if the entity has a given role.
*
* @param string|object $role Role name
* @param string|object|collection $role Role name
*
* @return bool
*/
Expand All @@ -43,6 +52,10 @@ public function hasRole($role)
return $this->roles->contains('name', $role);
}

return !!$role->intersect($this->roles)->count();
if ($role instanceof Collection) {
return !!$this->roles->intersect($role)->count();
}

return $this->roles->contains($role);
}
}
13 changes: 13 additions & 0 deletions app/Providers/RouteServiceProvider.php
Expand Up @@ -43,6 +43,7 @@ public function map()
->group(function () {
$this->mapDatabaseDrivenRoutes();
$this->mapPublicRoutes();
$this->mapPublicAuthorizedRoutes();
$this->mapAuthRoutes();
$this->mapAuthGuestRoutes();
$this->mapAuthAuthorizedRoutes();
Expand All @@ -66,6 +67,18 @@ protected function mapPublicRoutes()
->group(base_path('routes/public.php'));
}

/**
* Public Authorized routes
*
* @return void
*/
protected function mapPublicAuthorizedRoutes()
{
Route::middleware('is_authenticated')
->namespace($this->cmsNamespace)
->group(base_path('routes/public.authorized.php'));
}

/**
* Authentication routes
*
Expand Down
6 changes: 3 additions & 3 deletions config/mail.php
Expand Up @@ -16,7 +16,7 @@
|
*/

'driver' => env('MAIL_DRIVER', 'smtp'),
'driver' => env('MAIL_DRIVER', 'log'),

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -56,8 +56,8 @@
*/

'from' => [
'address' => env('MAIL_FROM_ADDRESS'),
'name' => env('MAIL_FROM_NAME'),
'address' => env('MAIL_FROM_ADDRESS', 'info@test.com'),
'name' => env('MAIL_FROM_NAME', 'Numencode CMS'),
],

/*
Expand Down
21 changes: 17 additions & 4 deletions config/numencode.php
Expand Up @@ -4,7 +4,7 @@

/*
|--------------------------------------------------------------------------
| Default namespace for app models.
| Default Namespace For The App Models
|--------------------------------------------------------------------------
|
| This is the default namespace for the application models.
Expand All @@ -17,7 +17,7 @@

/*
|--------------------------------------------------------------------------
| Date formats.
| Date Formats
|--------------------------------------------------------------------------
|
| Default date formats across the application.
Expand All @@ -43,7 +43,20 @@

/*
|--------------------------------------------------------------------------
| Un-deletable managers.
| Initial User Roles
|--------------------------------------------------------------------------
|
| The roles which are initially assigned to a user
| upon registration and/or email verification.
|
*/

'registration_roles' => [3],
'verification_roles' => [3, 4],

/*
|--------------------------------------------------------------------------
| Un-deletable Managers
|--------------------------------------------------------------------------
|
| Managers with ID's in this array cannot be deleted from the database.
Expand All @@ -67,7 +80,7 @@

/*
|--------------------------------------------------------------------------
| Max depth for page structure node
| Max Depth For Page Structure Node
|--------------------------------------------------------------------------
|
| The depth of a node is the number of edges from the node to the tree's
Expand Down
9 changes: 6 additions & 3 deletions modules/Admin/Http/Middleware/CheckPermission.php
Expand Up @@ -21,9 +21,10 @@ class CheckPermission
* Multiple permissions can be sent to the handle() method, divided with the pipe character:
* Route::get('demo', 'DemoController@index')->middleware('permission:view_demo|edit_demo');
*
* @param Request $request
* @param Closure $next
* @param string $permission
* @param Request $request Request
* @param Closure $next Closure
* @param string $permission Permission
*
* @return mixed
*/
public function handle(Request $request, Closure $next, $permission)
Expand Down Expand Up @@ -59,6 +60,8 @@ protected function revoke()

/**
* Flash error message for unauthorized action.
*
* @return void
*/
protected function flashError()
{
Expand Down
12 changes: 8 additions & 4 deletions modules/Admin/Http/RoleController.php
Expand Up @@ -147,8 +147,10 @@ public function assignPermission($roleId, $permissionId)
/**
* Assign or un-assign role to a given manager.
*
* @param Manager $manager
* @param Role $role
* @param Manager $manager Manager
* @param Role $role Role
*
* @return void
*/
public function assignManagerRole(Manager $manager, Role $role)
{
Expand All @@ -158,8 +160,10 @@ public function assignManagerRole(Manager $manager, Role $role)
/**
* Assign or un-assign role to a given user.
*
* @param User $user
* @param Role $role
* @param User $user User
* @param Role $role Role
*
* @return void
*/
public function assignUserRole(User $user, Role $role)
{
Expand Down
6 changes: 4 additions & 2 deletions modules/Cms/Http/Auth/ProfileController.php
Expand Up @@ -21,12 +21,14 @@ public function showProfileUpdateForm()
/**
* Update the user profile.
*
* @param ProfileRequest $request
* @param ProfileRequest $request Profile request
* @param UserRepository $repository User repository
*
* @return \Illuminate\Http\RedirectResponse
*/
public function update(ProfileRequest $request, UserRepository $repository)
{
$repository->updateUser($this->user, $request);
$repository->updateUser(auth()->user(), $request);

flash()->success(trans('messages.success'), trans('messages.user_profile.profile_success'));

Expand Down
3 changes: 3 additions & 0 deletions modules/Cms/Http/Auth/RegisterController.php
Expand Up @@ -55,6 +55,8 @@ protected function create(array $data)
'is_verified' => config('login.verification') ? false : true,
]);

$user->assignRoles(config('numencode.registration_roles'));

if (config('login.verification')) {
Mail::to($user)->send(new EmailVerification($user));
}
Expand Down Expand Up @@ -85,6 +87,7 @@ public function verifyEmail($token)

if ($user) {
$user->verifyEmail();
$user->assignRoles(config('numencode.verification_roles'));

flash()->overlay(trans('messages.email_verified.title'),
trans('messages.email_verified.success', ['email' => $user->email]), 'success'
Expand Down
23 changes: 23 additions & 0 deletions modules/Cms/Http/BlogController.php
Expand Up @@ -4,6 +4,7 @@

use Numencode\Models\Blog\BlogItem;
use Numencode\Models\Blog\BlogCategory;
use Numencode\Models\Blog\BlogItemComment;

class BlogController extends BaseController
{
Expand Down Expand Up @@ -46,4 +47,26 @@ public function random()

return view('theme::blog.random', compact('randomBlog'));
}

/**
* Add comment to a blog post.
*
* @param BlogItem $blogItem Blog entry
*
* @return \Illuminate\Http\RedirectResponse
*/
public function addComment(BlogItem $blogItem)
{
$this->validate(request(), [
'comment' => 'required',
]);

$blogItem->comments()->create([
'user_id' => auth()->user()->id,
'is_published' => true,
'comment' => request()->comment,
]);

return redirect()->back();
}
}

0 comments on commit 90bf9c5

Please sign in to comment.