Skip to content

Commit

Permalink
#2
Browse files Browse the repository at this point in the history
  • Loading branch information
h2dvnnet committed Nov 18, 2016
0 parents commit a6c8b7c
Show file tree
Hide file tree
Showing 93 changed files with 12,063 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto
*.css linguist-vendored
*.scss linguist-vendored
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/node_modules
/public/storage
/storage/*.key
/vendor
/.idea
Homestead.json
Homestead.yaml
.env
48 changes: 48 additions & 0 deletions app/Bot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace SmartBots;

use Moloquent;

class Bot extends Moloquent
{
private $virtual_bot = false; // No hardware connection but wanna test software?
/**
* Should timestamp (create_at, update_at,...) appear in the collection?.
*
* @var boolean
*/
public $timestamps = false;

/**
* The primary key for the model.
*
* @var string
*/
protected $primaryKey = '_id';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'hub_id','name','token','image','description','type','online','active','state','status'
];

/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'token'
];

// Relationships -----------------------------------------------------------------------------------------

public function hub() {
return $this->belongsTo('SmartBots\Hub','hub_id');
}
}
49 changes: 49 additions & 0 deletions app/BotPermission.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace SmartBots;

use Moloquent;

class BotPermission extends Moloquent
{
/**
* Should timestamp (create_at, update_at,...) appear in the collection?.
*
* @var boolean
*/
public $timestamps = false;

/**
* The primary key for the model.
*
* @var string
*/
protected $primaryKey = '_id';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id','bot_id','high','notice'
];

/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
//
];

// Relationships -----------------------------------------------------------------------------------------

public function bot() {
return $this->belongsTo('SmartBots\Bot','bot_id');
}
public function user() {
return $this->belongsTo('SmartBots\User','user_id');
}
}
75 changes: 75 additions & 0 deletions app/Console/Commands/KeySetCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
namespace SmartBots\Console\Commands;

use Illuminate\Console\Command;

class KeySetCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'key:set {--show : Display the key instead of modifying files}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Set the application key (do not use ket:generate)';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$key = $this->generateRandomKey();
if ($this->option('show')) {
return $this->line('<comment>'.$key.'</comment>');
}
// Next, we will replace the application key in the environment file so it is
// automatically setup for this developer. This key gets generated using a
// secure random byte generator and is later base64 encoded for storage.
$this->setKeyInEnvironmentFile($key);
$this->laravel['config']['app.key'] = $key;
$this->info("Application key [$key] set successfully.");
}

/**
* Set the application key in the environment file.
*
* @param string $key
* @return void
*/
protected function setKeyInEnvironmentFile($key)
{
file_put_contents($this->laravel->environmentFilePath(), str_replace(
'APP_KEY='.$this->laravel['config']['app.key'],
'APP_KEY='.$key,
file_get_contents($this->laravel->environmentFilePath())
));
}

/**
* Generate a random key for the application.
*
* @return string
*/
protected function generateRandomKey()
{
return str_random($this->laravel['config']['app.cipher'] == 'AES-128-CBC' ? 16 : 32);
}
}
40 changes: 40 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace SmartBots\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
Commands\KeySetCommand::class,
];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
}

/**
* Register the Closure based commands for the application.
*
* @return void
*/
protected function commands()
{
require base_path('routes/console.php');
}
}
71 changes: 71 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace SmartBots\Exceptions;

use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
\Illuminate\Auth\AuthenticationException::class,
\Illuminate\Auth\Access\AuthorizationException::class,
\Symfony\Component\HttpKernel\Exception\HttpException::class,
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
\Illuminate\Session\TokenMismatchException::class,
\Illuminate\Validation\ValidationException::class,
];

/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
if ($exception instanceof Tymon\JWTAuth\Exceptions\TokenExpiredException) {
return response()->json(['token_expired'], $exception->getStatusCode());
} else if ($exception instanceof Tymon\JWTAuth\Exceptions\TokenInvalidException) {
return response()->json(['token_invalid'], $exception->getStatusCode());
}

return parent::render($request, $exception);
}

/**
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}

return redirect()->guest('login');
}
}
32 changes: 32 additions & 0 deletions app/Http/Controllers/Auth/ForgotPasswordController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace SmartBots\Http\Controllers\Auth;

use SmartBots\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;

class ForgotPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset emails and
| includes a trait which assists in sending these notifications from
| your application to your users. Feel free to explore this trait.
|
*/

use SendsPasswordResetEmails;

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}
39 changes: 39 additions & 0 deletions app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace SmartBots\Http\Controllers\Auth;

use SmartBots\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;

class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/

use ResetsPasswords;

/**
* Where to redirect users after resetting their password.
*
* @var string
*/
protected $redirectTo = '/home';

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}
10 changes: 10 additions & 0 deletions app/Http/Controllers/BotController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace SmartBots\Http\Controllers;

use Illuminate\Http\Request;

class BotController extends Controller
{
//
}
13 changes: 13 additions & 0 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace SmartBots\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
Loading

0 comments on commit a6c8b7c

Please sign in to comment.