Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
CO-OP Search
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kittisak Maneewong
CO-OP Search
Commits
ffea59ad
Commit
ffea59ad
authored
Apr 07, 2019
by
Kittisak Maneewong
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://projectcs.sci.ubu.ac.th/Kittisak162/co-op-search
parents
d924ce96
5c4be305
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
115 additions
and
4 deletions
+115
-4
AuthController.php
app/Http/Controllers/AuthController.php
+73
-0
User.php
app/User.php
+12
-1
app.php
config/app.php
+3
-0
jwt.php
config/jwt.php
+0
-0
app.js
public/js/app.js
+0
-0
Toolbar.vue
resources/js/components/Toolbar.vue
+22
-1
api.php
routes/api.php
+5
-2
No files found.
app/Http/Controllers/AuthController.php
0 → 100644
View file @
ffea59ad
<?php
namespace
App\Http\Controllers
;
use
App\User
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Hash
;
use
Illuminate\Support\Facades\Validator
;
use
Tymon\JWTAuth\Facades\JWTAuth
;
use
Tymon\JWTAuth\Facades\JWTFactory
;
use
Tymon\JWTAuth\Exceptions\JWTException
;
use
Tymon\JWTAuth\Contracts\JWTSubject
;
use
Tymon\JWTAuth\PayloadFactory
;
use
Tymon\JWTAuth\JWTManager
as
JWT
;
class
AuthController
extends
Controller
{
public
function
register
(
Request
$request
)
{
$validator
=
Validator
::
make
(
$request
->
json
()
->
all
()
,
[
'name'
=>
'required|string|max:255'
,
'email'
=>
'required|string|email|max:255|unique:users'
,
'password'
=>
'required|string|min:8|confirmed'
,
]);
if
(
$validator
->
fails
())
{
return
response
()
->
json
(
$validator
->
errors
()
->
toJson
(),
400
);
}
$user
=
User
::
create
([
'name'
=>
$request
->
json
()
->
get
(
'name'
),
'email'
=>
$request
->
json
()
->
get
(
'email'
),
'password'
=>
Hash
::
make
(
$request
->
json
()
->
get
(
'password'
)),
]);
$token
=
JWTAuth
::
fromUser
(
$user
);
return
response
()
->
json
(
compact
(
'user'
,
'token'
),
201
);
}
public
function
login
(
Request
$request
)
{
$credentials
=
$request
->
json
()
->
all
();
try
{
if
(
!
$token
=
JWTAuth
::
attempt
(
$credentials
))
{
return
response
()
->
json
([
'error'
=>
'invalid_credentials'
],
400
);
}
}
catch
(
JWTException
$e
)
{
return
response
()
->
json
([
'error'
=>
'could_not_create_token'
,
500
]);
}
return
response
()
->
json
(
compact
(
'token'
));
}
public
function
getAuthenticatedUser
()
{
try
{
if
(
!
user
==
JWTAuth
::
parseToken
()
->
authenticate
())
{
return
response
()
->
json
([
'user_not_found'
],
404
);
}
}
catch
(
Tymon\JWTAuth\Exceptions\TokenExpiredException
$e
)
{
return
response
()
->
json
([
'token_expired'
],
$e
->
getStatusCode
());
}
catch
(
Tymon\JWTAuth\Exceptions\TokenInvalidException
$e
)
{
return
response
()
->
json
([
'token_invalid'
,
$e
->
getStatusCode
()]);
}
catch
(
Tymon\JWTAuth\Exceptions\JWTException
$e
)
{
return
response
()
->
json
([
'token_absent'
],
$e
->
getStatusCode
());
}
return
response
()
->
json
(
compact
(
'user'
));
}
}
app/User.php
View file @
ffea59ad
...
@@ -5,8 +5,9 @@ namespace App;
...
@@ -5,8 +5,9 @@ namespace App;
use
Illuminate\Notifications\Notifiable
;
use
Illuminate\Notifications\Notifiable
;
use
Illuminate\Contracts\Auth\MustVerifyEmail
;
use
Illuminate\Contracts\Auth\MustVerifyEmail
;
use
Illuminate\Foundation\Auth\User
as
Authenticatable
;
use
Illuminate\Foundation\Auth\User
as
Authenticatable
;
use
Tymon\JWTAuth\Contracts\JWTSubject
;
class
User
extends
Authenticatable
class
User
extends
Authenticatable
implements
JWTSubject
{
{
use
Notifiable
;
use
Notifiable
;
...
@@ -36,4 +37,14 @@ class User extends Authenticatable
...
@@ -36,4 +37,14 @@ class User extends Authenticatable
protected
$casts
=
[
protected
$casts
=
[
'email_verified_at'
=>
'datetime'
,
'email_verified_at'
=>
'datetime'
,
];
];
public
function
getJWTIdentifier
()
{
return
$this
->
getKey
();
}
public
function
getJWTCustomClaims
()
{
return
[];
}
}
}
config/app.php
View file @
ffea59ad
...
@@ -174,6 +174,7 @@ return [
...
@@ -174,6 +174,7 @@ return [
// App\Providers\BroadcastServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider
::
class
,
App\Providers\EventServiceProvider
::
class
,
App\Providers\RouteServiceProvider
::
class
,
App\Providers\RouteServiceProvider
::
class
,
Tymon\JWTAuth\Providers\LaravelServiceProvider
::
class
,
],
],
...
@@ -225,6 +226,8 @@ return [
...
@@ -225,6 +226,8 @@ return [
'URL'
=>
Illuminate\Support\Facades\URL
::
class
,
'URL'
=>
Illuminate\Support\Facades\URL
::
class
,
'Validator'
=>
Illuminate\Support\Facades\Validator
::
class
,
'Validator'
=>
Illuminate\Support\Facades\Validator
::
class
,
'View'
=>
Illuminate\Support\Facades\View
::
class
,
'View'
=>
Illuminate\Support\Facades\View
::
class
,
'JWTAuth'
=>
Tymon\JWTAuth\Facades\JWTAuth
::
class
,
'JWTFactory'
=>
Tymon\JWTAuth\Facades\JWTFactory
::
class
,
],
],
...
...
config/jwt.php
0 → 100644
View file @
ffea59ad
This diff is collapsed.
Click to expand it.
public/js/app.js
View file @
ffea59ad
This diff is collapsed.
Click to expand it.
resources/js/components/Toolbar.vue
View file @
ffea59ad
...
@@ -19,7 +19,28 @@
...
@@ -19,7 +19,28 @@
<img
src=
"../../../public/img/banner.png"
class=
"my-2"
width=
"150"
>
<img
src=
"../../../public/img/banner.png"
class=
"my-2"
width=
"150"
>
</v-toolbar-title>
</v-toolbar-title>
<v-spacer></v-spacer>
<v-spacer></v-spacer>
<v-btn
flat
color=
"black"
class=
"mx-0 px-0"
>
<v-icon>
home
</v-icon>
<span
class=
"body-2 font-weight-bold"
>
หน้าหลัก
</span>
</v-btn>
<v-btn
flat
color=
"black"
class=
"mx-0 px-0 body-2 font-weight-bold"
>
<span
class=
"body-2 font-weight-bold"
>
เกี่ยวกับเรา
</span>
</v-btn>
<v-btn
flat
color=
"black"
class=
"mx-0 px-0 body-2 font-weight-bold"
>
<span
class=
"body-2 font-weight-bold"
>
เกี่ยวกับเรา
</span>
</v-btn>
<v-btn
flat
color=
"black"
class=
"mx-0 px-0 body-2 font-weight-bold"
>
<span
class=
"body-2 font-weight-bold"
>
เกี่ยวกับเรา
</span>
</v-btn>
<v-btn
flat
color=
"black"
class=
"mx-0 px-0 body-2 font-weight-bold"
>
<span
class=
"body-2 font-weight-bold"
>
เกี่ยวกับเรา
</span>
</v-btn>
<v-btn
flat
color=
"black"
class=
"mx-0 px-0 body-2 font-weight-bold"
>
<span
class=
"body-2 font-weight-bold"
>
เกี่ยวกับเรา
</span>
</v-btn>
<v-btn
flat
color=
"black"
class=
"mx-0 px-0 body-2 font-weight-bold"
>
<span
class=
"body-2 font-weight-bold"
>
เกี่ยวกับเรา
</span>
</v-btn>
</v-toolbar>
</v-toolbar>
</v-flex>
</v-flex>
</v-layout>
</v-layout>
...
...
routes/api.php
View file @
ffea59ad
...
@@ -13,6 +13,8 @@ use Illuminate\Http\Request;
...
@@ -13,6 +13,8 @@ use Illuminate\Http\Request;
|
|
*/
*/
Route
::
middleware
(
'auth:api'
)
->
get
(
'/user'
,
function
(
Request
$request
)
{
Route
::
group
([
'prefix'
=>
'auth'
],
function
(
$router
)
{
return
$request
->
user
();
Route
::
post
(
'register'
,
'AuthController@register'
);
Route
::
post
(
'login'
,
'AuthController@login'
);
Route
::
post
(
'current'
,
'AuthController@getAuthenticatedUser'
);
});
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment