Skip to content

Commit 431752c

Browse files
authored
Merge pull request #379 from viralsolani/develop
Added version change of generator
2 parents 1227624 + 8e8f320 commit 431752c

Some content is hidden

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

57 files changed

+7613
-13369
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Thumbs.db
1616
_ide_helper.php
1717
composer.phar
1818
error.log
19+
access.log
1920
Todo.rtf
2021
.vagrant
2122
/.vagrant

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ You can now access the server at http://localhost:8000
107107
npm run development
108108
php artisan storage:link
109109
php artisan key:generate
110-
php artisan jwt:secret
111110
php artisan vendor:publish --tag=lfm_public
111+
php artisan migrate
112+
php artisan passport:install
112113

113114
## Please note
114115

access.log

Lines changed: 0 additions & 147 deletions
This file was deleted.

app/Exceptions/Handler.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ public function render($request, Exception $exception)
9090
switch (get_class($exception->getPrevious())) {
9191
case \App\Exceptions\Handler::class:
9292
return $this->setStatusCode($exception->getStatusCode())->respondWithError('Token has not been provided.');
93-
case \Tymon\JWTAuth\Exceptions\TokenExpiredException::class:
94-
return $this->setStatusCode($exception->getStatusCode())->respondWithError('Token has expired.');
95-
case \Tymon\JWTAuth\Exceptions\TokenInvalidException::class:
96-
case \Tymon\JWTAuth\Exceptions\TokenBlacklistedException::class:
97-
return $this->setStatusCode($exception->getStatusCode())->respondWithError('Token is invalid.');
9893
}
9994
}
10095
}

app/Http/Controllers/Api/V1/AuthController.php

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
namespace App\Http\Controllers\Api\V1;
44

5-
use App\Models\Access\User\User;
65
use Illuminate\Http\Request;
7-
use JWTAuth;
8-
use Tymon\JWTAuth\Exceptions\JWTException;
6+
use Illuminate\Support\Facades\Auth;
97
use Validator;
108

119
class AuthController extends APIController
@@ -20,8 +18,8 @@ class AuthController extends APIController
2018
public function login(Request $request)
2119
{
2220
$validation = Validator::make($request->all(), [
23-
'email' => 'required|email',
24-
'password' => 'required|min:4',
21+
'email' => 'required|email',
22+
'password' => 'required|min:4',
2523
]);
2624

2725
if ($validation->fails()) {
@@ -31,10 +29,19 @@ public function login(Request $request)
3129
$credentials = $request->only(['email', 'password']);
3230

3331
try {
34-
if (!$token = JWTAuth::attempt($credentials)) {
32+
if (!Auth::attempt($credentials)) {
3533
return $this->throwValidation(trans('api.messages.login.failed'));
3634
}
37-
} catch (JWTException $e) {
35+
36+
$user = $request->user();
37+
38+
$passportToken = $user->createToken('API Access Token');
39+
40+
// Save generated token
41+
$passportToken->token->save();
42+
43+
$token = $passportToken->accessToken;
44+
} catch (\Exception $e) {
3845
return $this->respondInternalError($e->getMessage());
3946
}
4047

@@ -45,49 +52,30 @@ public function login(Request $request)
4552
}
4653

4754
/**
48-
* Log the user out (Invalidate the token).
55+
* Get the authenticated User.
4956
*
5057
* @return \Illuminate\Http\JsonResponse
5158
*/
52-
public function logout()
59+
public function me()
5360
{
54-
try {
55-
$token = JWTAuth::getToken();
56-
57-
if ($token) {
58-
JWTAuth::invalidate($token);
59-
}
60-
} catch (JWTException $e) {
61-
return $this->respondInternalError($e->getMessage());
62-
}
63-
64-
return $this->respond([
65-
'message' => trans('api.messages.logout.success'),
66-
]);
61+
return response()->json($this->guard()->user());
6762
}
6863

6964
/**
70-
* Refresh a token.
65+
* Log the user out (Invalidate the token).
7166
*
7267
* @return \Illuminate\Http\JsonResponse
7368
*/
74-
public function refresh()
69+
public function logout(Request $request)
7570
{
76-
$token = JWTAuth::getToken();
77-
78-
if (!$token) {
79-
$this->respondUnauthorized(trans('api.messages.refresh.token.not_provided'));
80-
}
81-
8271
try {
83-
$refreshedToken = JWTAuth::refresh($token);
84-
} catch (JWTException $e) {
72+
$request->user()->token()->revoke();
73+
} catch (\Exception $e) {
8574
return $this->respondInternalError($e->getMessage());
8675
}
8776

8877
return $this->respond([
89-
'status' => trans('api.messages.refresh.status'),
90-
'token' => $refreshedToken,
78+
'message' => trans('api.messages.logout.success'),
9179
]);
9280
}
9381
}

app/Http/Controllers/Api/V1/RegisterController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
namespace App\Http\Controllers\Api\V1;
44

5-
use App\Models\User\User;
65
use App\Repositories\Frontend\Access\User\UserRepository;
76
use Config;
87
use Illuminate\Http\Request;
9-
use JWTAuth;
108
use Validator;
119

1210
class RegisterController extends APIController
@@ -53,7 +51,12 @@ public function register(Request $request)
5351
]);
5452
}
5553

56-
$token = JWTAuth::fromUser($user);
54+
$passportToken = $user->createToken('API Access Token');
55+
56+
// Save generated token
57+
$passportToken->token->save();
58+
59+
$token = $passportToken->accessToken;
5760

5861
return $this->respondCreated([
5962
'message' => trans('api.messages.registeration.success'),

app/Http/Kernel.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace App\Http;
44

55
use Illuminate\Foundation\Http\Kernel as HttpKernel;
6-
use Tymon\JWTAuth\Middleware\GetUserFromToken;
7-
use Tymon\JWTAuth\Middleware\RefreshToken;
86

97
/**
108
* Class Kernel.
@@ -76,7 +74,5 @@ class Kernel extends HttpKernel
7674
*/
7775
'access.routeNeedsRole' => \App\Http\Middleware\RouteNeedsRole::class,
7876
'access.routeNeedsPermission' => \App\Http\Middleware\RouteNeedsPermission::class,
79-
'jwt.auth' => GetUserFromToken::class,
80-
'jwt.refresh' => RefreshToken::class,
8177
];
8278
}

app/Http/Requests/Backend/Access/Role/ManageRoleRequest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function authorize()
2727
public function rules()
2828
{
2929
return [
30-
//
3130
];
3231
}
3332
}

app/Models/Access/User/User.php

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@
1010
use Illuminate\Database\Eloquent\SoftDeletes;
1111
use Illuminate\Foundation\Auth\User as Authenticatable;
1212
use Illuminate\Notifications\Notifiable;
13-
use Tymon\JWTAuth\Contracts\JWTSubject;
13+
use Laravel\Passport\HasApiTokens;
1414

1515
/**
1616
* Class User.
1717
*/
18-
class User extends Authenticatable implements JWTSubject
18+
class User extends Authenticatable
1919
{
2020
use UserScope,
2121
UserAccess,
2222
Notifiable,
2323
SoftDeletes,
2424
UserAttribute,
2525
UserRelationship,
26-
UserSendPasswordReset;
26+
UserSendPasswordReset,
27+
HasApiTokens;
2728
/**
2829
* The database table used by the model.
2930
*
@@ -78,6 +79,18 @@ public function getJWTIdentifier()
7879
return $this->getKey();
7980
}
8081

82+
/**
83+
* Set password attribute.
84+
*
85+
* @param [string] $password
86+
*/
87+
public function setPasswordAttribute($password)
88+
{
89+
if (!empty($password)) {
90+
$this->attributes['password'] = bcrypt($password);
91+
}
92+
}
93+
8194
/**
8295
* Return a key value array, containing any custom claims to be added to the JWT.
8396
*
@@ -86,17 +99,17 @@ public function getJWTIdentifier()
8699
public function getJWTCustomClaims()
87100
{
88101
return [
89-
'id' => $this->id,
90-
'first_name' => $this->first_name,
91-
'last_name' => $this->last_name,
92-
'email' => $this->email,
93-
'picture' => $this->getPicture(),
94-
'confirmed' => $this->confirmed,
95-
'role' => optional($this->roles()->first())->name,
96-
'permissions' => $this->permissions()->get(),
97-
'status' => $this->status,
98-
'created_at' => $this->created_at->toIso8601String(),
99-
'updated_at' => $this->updated_at->toIso8601String(),
102+
'id' => $this->id,
103+
'first_name' => $this->first_name,
104+
'last_name' => $this->last_name,
105+
'email' => $this->email,
106+
'picture' => $this->getPicture(),
107+
'confirmed' => $this->confirmed,
108+
'role' => optional($this->roles()->first())->name,
109+
'permissions' => $this->permissions()->get(),
110+
'status' => $this->status,
111+
'created_at' => $this->created_at->toIso8601String(),
112+
'updated_at' => $this->updated_at->toIso8601String(),
100113
];
101114
}
102115
}

app/Providers/AppServiceProvider.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,6 @@ public function register()
5858
* Sets third party service providers that are only needed on local/testing environments
5959
*/
6060
if ($this->app->environment() != 'production') {
61-
/**
62-
* Loader for registering facades.
63-
*/
64-
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
65-
66-
/*
67-
* Load third party local providers
68-
*/
69-
$this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);
70-
71-
/*
72-
* Load third party local aliases
73-
*/
74-
$loader->alias('Debugbar', \Barryvdh\Debugbar\Facade::class);
7561
}
7662
}
7763
}

0 commit comments

Comments
 (0)