Skip to content

Commit

Permalink
finish release 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DemianD committed Jul 16, 2017
2 parents ea38e66 + c5a77fe commit 86ba381
Show file tree
Hide file tree
Showing 109 changed files with 2,800 additions and 397 deletions.
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
sudo: false
matrix:
include:
- language: php
php: 7.0
before_script:
- cd api
- travis_retry composer self-update
- travis_retry composer update --no-interaction --prefer-source
script:
- phpunit --coverage-text --coverage-clover=coverage.clover

- language: node_js
node_js:
- "node"
cache:
yarn: true,
directories:
- node_modules
before_script:
- npm install -g yarn
- cd web-app
- travis_retry yarn install
script:
- yarn build-css
- yarn lint
- travis_retry yarn test
- travis_retry yarn run build
15 changes: 15 additions & 0 deletions api/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
6 changes: 6 additions & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
APP_FRONT_END_URL=http://localhost:3000

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
Expand Down Expand Up @@ -31,3 +32,8 @@ MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

DEPLOY_BRANCH_WEBHOOK=master

FACEBOOK_CLIENT_ID=
FACEBOOK_CLIENT_SECRET=
56 changes: 56 additions & 0 deletions api/app/Console/Commands/Deploy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class Deploy extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'deploy';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Build and deploy the application';

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

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info("DEPLOY APPLICATION\n");

$this->exec('cd .. && bash deploy.sh');

$this->info("DEPLOYED APPLICATION\n");
}

protected function exec($command)
{
$pwd = base_path();

$result = shell_exec("cd $pwd && $command");
$this->output->write($result);

return $result;
}
}
3 changes: 2 additions & 1 deletion api/app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console;

use App\Console\Commands\Deploy;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

Expand All @@ -13,7 +14,7 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
//
Deploy::class,
];

/**
Expand Down
8 changes: 4 additions & 4 deletions api/app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace App\Exceptions;

use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\File;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

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

return new Response(File::get(public_path().'/build/index.html'), Response::HTTP_OK);
Expand Down
52 changes: 48 additions & 4 deletions api/app/Http/Controllers/Api/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,79 @@

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Http\Request;
use Tymon\JWTAuth\Facades\JWTAuth;
use App\Http\Controllers\Controller;
use App\Http\Requests\Api\UserRegistrationModel;

class AuthController extends Controller
{
/**
* Authenticate the user and create a token.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function auth(Request $request)
{
$credentials = $request->only('email', 'password');

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

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

/**
* Return the current authenticated user.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function me(Request $request)
{
dd(auth()->user());
$user = auth()->user();

return response()->json(auth()->user());
return response()->json($user);
}

/**
* Refresh the JWT token.
*
* @return \Illuminate\Http\JsonResponse
*/
public function refresh()
{
$token = JWTAuth::getToken();
$newToken = JWTAuth::refresh($token);

return response()->json(compact('newToken'));
}

public function logout()
{
JWTAuth::invalidate(JWTAuth::getToken());
}

/**
* Register a new User.
*
* @param \App\Http\Requests\Api\UserRegistrationModel $request
*
* @return mixed
*/
public function register(UserRegistrationModel $request)
{
$account = [
'name' => $request->name,
'email' => $request->email,
'password' => bcrypt($request->password),
];

User::create($account);
}
}
46 changes: 46 additions & 0 deletions api/app/Http/Controllers/Api/AuthSocialiteController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Http\Controllers\Api;

use App\User;
use App\Provider;
use Tymon\JWTAuth\Facades\JWTAuth;
use App\Http\Controllers\Controller;
use Laravel\Socialite\Facades\Socialite;

class AuthSocialiteController extends Controller
{
private $driver = 'facebook';

public function redirectToProvider()
{
return Socialite::driver($this->driver)->stateless()->redirect();
}

public function handleProviderCallback()
{
$facebookUser = Socialite::driver($this->driver)->stateless()->user();

$user = $this->firstOrCreateUser($facebookUser);

$this->firstOrCreateProvider($user, $facebookUser);

$token = JWTAuth::fromUser($user);
$redirectUrl = sprintf('%s/login/callback/%s/%s', config('app.url_front_end'), $this->driver, $token);

return redirect()->to($redirectUrl);
}

private function firstOrCreateUser($facebookUser)
{
return User::firstOrCreate(['email' => $facebookUser->email], ['name' => $facebookUser->name]);
}

private function firstOrCreateProvider($user, $facebookUser)
{
return Provider::updateOrCreate(
['user_id' => $user->id, 'provider' => $this->driver],
['provider_id' => $facebookUser->id, 'provider_token' => $facebookUser->token]
);
}
}
Loading

0 comments on commit 86ba381

Please sign in to comment.