Skip to content

Commit 83bcedb

Browse files
authored
Merge pull request #158 from oSoc17/release/0.2.0
release/0.2.0
2 parents 6664d23 + c5a77fe commit 83bcedb

File tree

109 files changed

+2800
-397
lines changed

Some content is hidden

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

109 files changed

+2800
-397
lines changed

.travis.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
sudo: false
2+
matrix:
3+
include:
4+
- language: php
5+
php: 7.0
6+
before_script:
7+
- cd api
8+
- travis_retry composer self-update
9+
- travis_retry composer update --no-interaction --prefer-source
10+
script:
11+
- phpunit --coverage-text --coverage-clover=coverage.clover
12+
13+
- language: node_js
14+
node_js:
15+
- "node"
16+
cache:
17+
yarn: true,
18+
directories:
19+
- node_modules
20+
before_script:
21+
- npm install -g yarn
22+
- cd web-app
23+
- travis_retry yarn install
24+
script:
25+
- yarn build-css
26+
- yarn lint
27+
- travis_retry yarn test
28+
- travis_retry yarn run build

api/.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

api/.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ APP_KEY=
44
APP_DEBUG=true
55
APP_LOG_LEVEL=debug
66
APP_URL=http://localhost
7+
APP_FRONT_END_URL=http://localhost:3000
78

89
DB_CONNECTION=mysql
910
DB_HOST=127.0.0.1
@@ -31,3 +32,8 @@ MAIL_ENCRYPTION=null
3132
PUSHER_APP_ID=
3233
PUSHER_APP_KEY=
3334
PUSHER_APP_SECRET=
35+
36+
DEPLOY_BRANCH_WEBHOOK=master
37+
38+
FACEBOOK_CLIENT_ID=
39+
FACEBOOK_CLIENT_SECRET=

api/app/Console/Commands/Deploy.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
7+
class Deploy extends Command
8+
{
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'deploy';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Build and deploy the application';
22+
23+
/**
24+
* Create a new command instance.
25+
*
26+
* @return void
27+
*/
28+
public function __construct()
29+
{
30+
parent::__construct();
31+
}
32+
33+
/**
34+
* Execute the console command.
35+
*
36+
* @return mixed
37+
*/
38+
public function handle()
39+
{
40+
$this->info("DEPLOY APPLICATION\n");
41+
42+
$this->exec('cd .. && bash deploy.sh');
43+
44+
$this->info("DEPLOYED APPLICATION\n");
45+
}
46+
47+
protected function exec($command)
48+
{
49+
$pwd = base_path();
50+
51+
$result = shell_exec("cd $pwd && $command");
52+
$this->output->write($result);
53+
54+
return $result;
55+
}
56+
}

api/app/Console/Kernel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Console;
44

5+
use App\Console\Commands\Deploy;
56
use Illuminate\Console\Scheduling\Schedule;
67
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
78

@@ -13,7 +14,7 @@ class Kernel extends ConsoleKernel
1314
* @var array
1415
*/
1516
protected $commands = [
16-
//
17+
Deploy::class,
1718
];
1819

1920
/**

api/app/Exceptions/Handler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
namespace App\Exceptions;
44

55
use Exception;
6-
use Illuminate\Auth\AuthenticationException;
7-
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
86
use Illuminate\Http\Response;
9-
use Illuminate\Support\Facades\File;
107
use Illuminate\Support\Facades\Log;
8+
use Illuminate\Support\Facades\File;
9+
use Illuminate\Auth\AuthenticationException;
10+
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
1111
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1212

1313
class Handler extends ExceptionHandler
@@ -51,7 +51,7 @@ public function report(Exception $exception)
5151
public function render($request, Exception $exception)
5252
{
5353
// If no route is found, we will serve the React app. React will show a 404 page.
54-
if ($exception instanceof NotFoundHttpException && !strpos($request->url(), '/api')) {
54+
if ($exception instanceof NotFoundHttpException && ! strpos($request->url(), '/api')) {
5555
Log::info('NotFoundHttpException, Route not found, serving index.html of build folder');
5656

5757
return new Response(File::get(public_path().'/build/index.html'), Response::HTTP_OK);

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

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,79 @@
22

33
namespace App\Http\Controllers\Api;
44

5-
use App\Http\Controllers\Controller;
5+
use App\User;
66
use Illuminate\Http\Request;
77
use Tymon\JWTAuth\Facades\JWTAuth;
8+
use App\Http\Controllers\Controller;
9+
use App\Http\Requests\Api\UserRegistrationModel;
810

911
class AuthController extends Controller
1012
{
13+
/**
14+
* Authenticate the user and create a token.
15+
*
16+
* @param \Illuminate\Http\Request $request
17+
*
18+
* @return \Illuminate\Http\JsonResponse
19+
*/
1120
public function auth(Request $request)
1221
{
1322
$credentials = $request->only('email', 'password');
1423

15-
if (!$token = JWTAuth::attempt($credentials)) {
24+
if (! $token = JWTAuth::attempt($credentials)) {
1625
return response()->json(['error' => 'invalid_credentials'], 401);
1726
}
1827

1928
return response()->json(compact('token'));
2029
}
2130

31+
/**
32+
* Return the current authenticated user.
33+
*
34+
* @param \Illuminate\Http\Request $request
35+
*
36+
* @return \Illuminate\Http\JsonResponse
37+
*/
2238
public function me(Request $request)
2339
{
24-
dd(auth()->user());
40+
$user = auth()->user();
2541

26-
return response()->json(auth()->user());
42+
return response()->json($user);
2743
}
2844

45+
/**
46+
* Refresh the JWT token.
47+
*
48+
* @return \Illuminate\Http\JsonResponse
49+
*/
2950
public function refresh()
3051
{
3152
$token = JWTAuth::getToken();
3253
$newToken = JWTAuth::refresh($token);
3354

3455
return response()->json(compact('newToken'));
3556
}
57+
58+
public function logout()
59+
{
60+
JWTAuth::invalidate(JWTAuth::getToken());
61+
}
62+
63+
/**
64+
* Register a new User.
65+
*
66+
* @param \App\Http\Requests\Api\UserRegistrationModel $request
67+
*
68+
* @return mixed
69+
*/
70+
public function register(UserRegistrationModel $request)
71+
{
72+
$account = [
73+
'name' => $request->name,
74+
'email' => $request->email,
75+
'password' => bcrypt($request->password),
76+
];
77+
78+
User::create($account);
79+
}
3680
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api;
4+
5+
use App\User;
6+
use App\Provider;
7+
use Tymon\JWTAuth\Facades\JWTAuth;
8+
use App\Http\Controllers\Controller;
9+
use Laravel\Socialite\Facades\Socialite;
10+
11+
class AuthSocialiteController extends Controller
12+
{
13+
private $driver = 'facebook';
14+
15+
public function redirectToProvider()
16+
{
17+
return Socialite::driver($this->driver)->stateless()->redirect();
18+
}
19+
20+
public function handleProviderCallback()
21+
{
22+
$facebookUser = Socialite::driver($this->driver)->stateless()->user();
23+
24+
$user = $this->firstOrCreateUser($facebookUser);
25+
26+
$this->firstOrCreateProvider($user, $facebookUser);
27+
28+
$token = JWTAuth::fromUser($user);
29+
$redirectUrl = sprintf('%s/login/callback/%s/%s', config('app.url_front_end'), $this->driver, $token);
30+
31+
return redirect()->to($redirectUrl);
32+
}
33+
34+
private function firstOrCreateUser($facebookUser)
35+
{
36+
return User::firstOrCreate(['email' => $facebookUser->email], ['name' => $facebookUser->name]);
37+
}
38+
39+
private function firstOrCreateProvider($user, $facebookUser)
40+
{
41+
return Provider::updateOrCreate(
42+
['user_id' => $user->id, 'provider' => $this->driver],
43+
['provider_id' => $facebookUser->id, 'provider_token' => $facebookUser->token]
44+
);
45+
}
46+
}

0 commit comments

Comments
 (0)