Skip to content

Commit 0d5f112

Browse files
committed
versi 1.0
0 parents  commit 0d5f112

Some content is hidden

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

84 files changed

+6989
-0
lines changed

app/Console/Commands/Inspire.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Foundation\Inspiring;
7+
8+
class Inspire extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'inspire';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Display an inspiring quote';
23+
24+
/**
25+
* Execute the console command.
26+
*
27+
* @return mixed
28+
*/
29+
public function handle()
30+
{
31+
$this->comment(PHP_EOL.Inspiring::quote().PHP_EOL);
32+
}
33+
}

app/Console/Kernel.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Console;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
7+
8+
class Kernel extends ConsoleKernel
9+
{
10+
/**
11+
* The Artisan commands provided by your application.
12+
*
13+
* @var array
14+
*/
15+
protected $commands = [
16+
// Commands\Inspire::class,
17+
];
18+
19+
/**
20+
* Define the application's command schedule.
21+
*
22+
* @param \Illuminate\Console\Scheduling\Schedule $schedule
23+
* @return void
24+
*/
25+
protected function schedule(Schedule $schedule)
26+
{
27+
// $schedule->command('inspire')
28+
// ->hourly();
29+
}
30+
}

app/Events/Event.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
abstract class Event
6+
{
7+
//
8+
}

app/Exceptions/Handler.php

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
use Illuminate\Validation\ValidationException;
7+
use Illuminate\Auth\Access\AuthorizationException;
8+
use Illuminate\Database\Eloquent\ModelNotFoundException;
9+
use Symfony\Component\HttpKernel\Exception\HttpException;
10+
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
11+
12+
class Handler extends ExceptionHandler
13+
{
14+
/**
15+
* A list of the exception types that should not be reported.
16+
*
17+
* @var array
18+
*/
19+
protected $dontReport = [
20+
AuthorizationException::class,
21+
HttpException::class,
22+
ModelNotFoundException::class,
23+
ValidationException::class,
24+
];
25+
26+
/**
27+
* Report or log an exception.
28+
*
29+
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
30+
*
31+
* @param \Exception $e
32+
* @return void
33+
*/
34+
public function report(Exception $e)
35+
{
36+
parent::report($e);
37+
}
38+
39+
/**
40+
* Render an exception into an HTTP response.
41+
*
42+
* @param \Illuminate\Http\Request $request
43+
* @param \Exception $e
44+
* @return \Illuminate\Http\Response
45+
*/
46+
public function render($request, Exception $e)
47+
{
48+
if($e instanceof ModelNotFoundException){
49+
$e = new NotFoundException($e->getMessage(),$e);
50+
}
51+
52+
if($e instanceof TokenExpiredException){
53+
return response()->json(['token_expired'],$e->getStatusCode());
54+
}elseif($e instanceof TokenInvalidException){
55+
return response()->json(['token_invalid'],$e->getStatusCode());
56+
}elseif($e instanceof TokenBlackListedException){
57+
return response()->json(['token is blacklisted'],$e->getStatusCode());
58+
}
59+
60+
return parent::render($request,$e);
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\User;
6+
use Validator;
7+
use Tymon\JWTAuth\Exceptions\JWTException;
8+
use Tymon\JWTAuth\Facades\JWTAuth;
9+
use App\Http\Controllers\Controller;
10+
use Illuminate\Http\Request;
11+
use Illuminate\Foundation\Auth\ThrottlesLogins;
12+
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
13+
14+
class AuthController extends Controller
15+
{
16+
/*
17+
|--------------------------------------------------------------------------
18+
| Registration & Login Controller
19+
|--------------------------------------------------------------------------
20+
|
21+
| This controller handles the registration of new users, as well as the
22+
| authentication of existing users. By default, this controller uses
23+
| a simple trait to add these behaviors. Why don't you explore it?
24+
|
25+
*/
26+
27+
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
28+
29+
/**
30+
* Where to redirect users after login / registration.
31+
*
32+
* @var string
33+
*/
34+
protected $redirectTo = '/';
35+
36+
/**
37+
* Create a new authentication controller instance.
38+
*
39+
* @return void
40+
*/
41+
// public function __construct()
42+
// {
43+
// $this->middleware($this->guestMiddleware(), ['except' => 'logout']);
44+
// }
45+
public function index(){
46+
try{
47+
return User::all();
48+
}catch(Exception $ex){
49+
return $ex;
50+
}
51+
}
52+
public function show(){
53+
try {
54+
$user = JWTAuth::parseToken()->ToUser();
55+
if(! $user){
56+
return $this->response->errorNotFound("user not found");
57+
}
58+
} catch (Exception $ex) {
59+
return $this->response->error("something went wrong");
60+
}
61+
62+
return $this->response->array(compact('user'))->setStatusCode(200);
63+
}
64+
public function authenticate(Request $request){
65+
$credentials= $request->only('email','password');
66+
try{
67+
if(!$token = JWTAuth::attempt($credentials)){
68+
return $this->response->errorUnauthorized();
69+
}
70+
}catch(JWTException $ex){
71+
return $this->response->errorInternal();
72+
73+
}
74+
75+
return $this->response->array(compact('token'))->setStatusCode(200);
76+
}
77+
/**
78+
* Get a validator for an incoming registration request.
79+
*
80+
* @param array $data
81+
* @return \Illuminate\Contracts\Validation\Validator
82+
*/
83+
protected function validator(array $data)
84+
{
85+
return Validator::make($data, [
86+
'name' => 'required|max:255',
87+
'email' => 'required|email|max:255|unique:users',
88+
'password' => 'required|min:6|confirmed',
89+
]);
90+
}
91+
92+
/**
93+
* Create a new user instance after a valid registration.
94+
*
95+
* @param array $data
96+
* @return User
97+
*/
98+
protected function create(array $data)
99+
{
100+
return User::create([
101+
'name' => $data['name'],
102+
'email' => $data['email'],
103+
'password' => bcrypt($data['password']),
104+
]);
105+
}
106+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Foundation\Auth\ResetsPasswords;
7+
8+
class PasswordController extends Controller
9+
{
10+
/*
11+
|--------------------------------------------------------------------------
12+
| Password Reset Controller
13+
|--------------------------------------------------------------------------
14+
|
15+
| This controller is responsible for handling password reset requests
16+
| and uses a simple trait to include this behavior. You're free to
17+
| explore this trait and override any methods you wish to tweak.
18+
|
19+
*/
20+
21+
use ResetsPasswords;
22+
23+
/**
24+
* Create a new password controller instance.
25+
*
26+
* @return void
27+
*/
28+
public function __construct()
29+
{
30+
$this->middleware('guest');
31+
}
32+
}

app/Http/Controllers/Controller.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
use Dingo\Api\Routing\Helpers;
5+
use Illuminate\Foundation\Bus\DispatchesJobs;
6+
use Illuminate\Routing\Controller as BaseController;
7+
use Illuminate\Foundation\Validation\ValidatesRequests;
8+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
9+
use Illuminate\Foundation\Auth\Access\AuthorizesResources;
10+
11+
class Controller extends BaseController
12+
{
13+
use AuthorizesResources, DispatchesJobs, ValidatesRequests,Helpers;
14+
}
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use App\User;
7+
use App\Role;
8+
use App\Permission;
9+
use App\Http\Requests;
10+
11+
class HomeController extends Controller
12+
{
13+
//
14+
public function index()
15+
{
16+
return "hello"; # code...
17+
}
18+
19+
public function attachUserRole($userid ,$role){
20+
$user = User::find($userid);
21+
$roleid = Role::where("name",$role)->first();
22+
$user->roles()->attach($roleid);
23+
24+
return $user;
25+
}
26+
27+
public function getUserRole($userid){
28+
29+
return User::find($userid)->roles;
30+
31+
}
32+
33+
34+
public function attachPermissions(Request $request){
35+
$parameters= $request->only('permission','role');
36+
$permissionParam= $parameters['permission'];
37+
$roleParam = $parameters['role'];
38+
$role = Role::where("name",$roleParam)->first();
39+
$permission = Permission::where("name",$permissionParam)->first();
40+
$role->attachPermission($permission);
41+
42+
return $this->response->created();
43+
}
44+
45+
public function getPermission($roleParam){
46+
47+
$role = Role::where("name",$roleParam)->first();
48+
49+
return $role->perms;
50+
}
51+
}

0 commit comments

Comments
 (0)