Skip to content

Commit ee14e95

Browse files
author
José Fernando Cordova
committed
Structure
1 parent d59c9ac commit ee14e95

File tree

107 files changed

+8328
-0
lines changed

Some content is hidden

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

107 files changed

+8328
-0
lines changed

.docker/Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM php:7.1.8-apache
2+
3+
MAINTAINER jfernancordova@gmail.com
4+
5+
# apt-get
6+
RUN apt-get update
7+
RUN apt-get -y install bzip2 git nano wget zip unzip
8+
RUN apt-get -y install libmcrypt-dev libzzip-dev zziplib-bin zlib1g-dev
9+
10+
# MySQL client for Initial Tasks
11+
RUN apt-get update &&\
12+
apt-get install -y mysql-client
13+
14+
# docker-php ext-install:
15+
RUN docker-php-ext-install mcrypt
16+
RUN docker-php-ext-install zip
17+
18+
# pdo_mysql
19+
RUN docker-php-ext-install pdo_mysql
20+
21+
# rsyslog: (for Loggly etc)
22+
RUN apt-get update && apt-get -y install rsyslog && apt-get clean
23+
RUN sed -i '1s/^/$MaxMessageSize 64k\n/' /etc/rsyslog.conf
24+
25+
# composer:
26+
COPY .docker/composer-install.sh /tmp
27+
RUN /tmp/composer-install.sh && mv /usr/local/bin/composer.phar /usr/local/bin/composer
28+
29+
# DIR
30+
WORKDIR /docker-laravel-api-dev
31+
COPY . ./
32+
33+
# apache:
34+
COPY .docker/vhost.conf /etc/apache2/sites-available/000-default.conf
35+
36+
# composer configuration:
37+
COPY ./composer.json ./composer.json
38+
COPY ./composer.lock ./composer.lock
39+
40+
# www-data:
41+
RUN chown -R www-data:www-data ./ && a2enmod rewrite
42+
USER root

.docker/composer-install.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
4+
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
5+
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
6+
7+
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
8+
then
9+
>&2 echo 'ERROR: Invalid installer signature'
10+
rm composer-setup.php
11+
exit 1
12+
fi
13+
14+
php composer-setup.php --install-dir=/usr/local/bin --quiet
15+
RESULT=$?
16+
rm composer-setup.php
17+
exit $RESULT

.docker/vhost.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<VirtualHost *:80>
2+
DocumentRoot /docker-laravel-api-dev/public
3+
4+
<Directory "/docker-laravel-api-dev/public">
5+
AllowOverride all
6+
Require all granted
7+
</Directory>
8+
9+
ErrorLog ${APACHE_LOG_DIR}/error.log
10+
CustomLog ${APACHE_LOG_DIR}/access.log combined
11+
</VirtualHost>

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-/.docker/local-mysql-datadir
2+
/vendor

.env.example

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
APP_ENV=local
2+
APP_KEY=
3+
APP_DEBUG=true
4+
APP_LOG_LEVEL=debug
5+
APP_URL=http://localhost
6+
7+
DB_CONNECTION=mysql
8+
DB_HOST=db
9+
DB_PORT=3306
10+
DB_DATABASE=apiLaravelDocker
11+
DB_USERNAME=apiLaravelDocker
12+
DB_PASSWORD=apiLaravelDocker
13+
14+
BROADCAST_DRIVER=log
15+
CACHE_DRIVER=file
16+
SESSION_DRIVER=file
17+
QUEUE_DRIVER=sync
18+
19+
REDIS_HOST=127.0.0.1
20+
REDIS_PASSWORD=null
21+
REDIS_PORT=6379
22+
23+
MAIL_DRIVER=smtp
24+
MAIL_HOST=mailtrap.io
25+
MAIL_PORT=2525
26+
MAIL_USERNAME=null
27+
MAIL_PASSWORD=null
28+
MAIL_ENCRYPTION=null
29+
30+
PUSHER_APP_ID=
31+
PUSHER_KEY=
32+
PUSHER_SECRET=
33+
34+
API_PREFIX=api
35+
API_SUBTYPE=app
36+
API_VERSION=v1
37+
38+
SIGN_UP_RELEASE_TOKEN=false
39+
PASSWORD_RESET_RELEASE_TOKEN=false
40+
41+
JWT_SECRET=my-dummy-token

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto
2+
*.css linguist-vendored
3+
*.scss linguist-vendored

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@
22
.env.*.php
33
.env.php
44
.env
5+
6+
\.docker/local-mysql-datadir/
7+
8+
\.idea/
9+
10+
vendor/

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
sudo: required
2+
3+
language: php
4+
5+
php:
6+
# Test against PHP 7.1.8 version ...
7+
- 7.1.8
8+
9+
services:
10+
- docker
11+
12+
before_script:
13+
- chmod +x ./scripts/runtests.sh
14+
- docker-compose -f docker-compose.yml up --build -d
15+
- docker ps -a
16+
- sleep 30 # wait for Mysql to start
17+
18+
script: ./scripts/runtests.sh
19+
20+
after_script:
21+
- docker-compose -f docker-compose.yml down
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace App\Api\V1\Controllers;
4+
5+
use App\User;
6+
use App\Http\Controllers\Controller;
7+
use Illuminate\Http\JsonResponse;
8+
use Illuminate\Support\Facades\Password;
9+
use App\Api\V1\Requests\ForgotPasswordRequest;
10+
use Symfony\Component\HttpKernel\Exception\HttpException;
11+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
12+
use App\Helpers\ApiResponse;
13+
14+
class ForgotPasswordController extends Controller
15+
{
16+
/**
17+
* @param ForgotPasswordRequest $request
18+
* @return \Illuminate\Http\JsonResponse
19+
*/
20+
public function sendResetEmail(ForgotPasswordRequest $request): JsonResponse
21+
{
22+
$user = User::where('email', '=', $request->get('email'))->first();
23+
if (!$user) {
24+
throw new NotFoundHttpException();
25+
}
26+
27+
$broker = $this->getPasswordBroker();
28+
$sendingResponse = $broker->sendResetLink($request->only('email'));
29+
30+
if ($sendingResponse !== Password::RESET_LINK_SENT) {
31+
throw new HttpException(500);
32+
}
33+
34+
ApiResponse::response(200, 'Ok');
35+
}
36+
37+
/**
38+
* Get the broker to be used during password reset.
39+
*
40+
* @return \Illuminate\Contracts\Auth\PasswordBroker
41+
*/
42+
private function getPasswordBroker()
43+
{
44+
return Password::broker();
45+
}
46+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace App\Api\V1\Controllers;
4+
5+
use App\Helpers\ApiResponse;
6+
use Illuminate\Http\JsonResponse;
7+
use Symfony\Component\HttpKernel\Exception\HttpException;
8+
use Tymon\JWTAuth\JWTAuth;
9+
use App\Http\Controllers\Controller;
10+
use App\Api\V1\Requests\LoginRequest;
11+
use Tymon\JWTAuth\Exceptions\JWTException;
12+
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
13+
use Auth;
14+
15+
class LoginController extends Controller
16+
{
17+
/**
18+
* Log the user in
19+
*
20+
* @param LoginRequest $request
21+
* @param JWTAuth $JWTAuth
22+
* @return \Illuminate\Http\JsonResponse
23+
*/
24+
public function login(LoginRequest $request, JWTAuth $JWTAuth): JsonResponse
25+
{
26+
$credentials = $request->only(['email', 'password']);
27+
28+
try {
29+
$token = Auth::guard()->attempt($credentials);
30+
31+
if(!$token) {
32+
throw new AccessDeniedHttpException();
33+
}
34+
35+
} catch (JWTException $e) {
36+
throw new HttpException(500);
37+
}
38+
39+
ApiResponse::response(200, 'Ok',
40+
['token' => $token, 'expires_in' => Auth::guard()->factory()->getTTL() * 60]);
41+
}
42+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Api\V1\Controllers;
4+
5+
use App\Helpers\ApiResponse;
6+
use App\Http\Controllers\Controller;
7+
use Auth;
8+
use Illuminate\Http\JsonResponse;
9+
10+
class LogoutController extends Controller
11+
{
12+
/**
13+
* Create a new AuthController instance.
14+
*
15+
* @return void
16+
*/
17+
public function __construct()
18+
{
19+
$this->middleware('auth:api', []);
20+
}
21+
22+
/**
23+
* Log the user out (Invalidate the token)
24+
*
25+
* @return \Illuminate\Http\JsonResponse
26+
*/
27+
public function logout(): JsonResponse
28+
{
29+
Auth::guard()->logout();
30+
ApiResponse::response(200, 'Ok', ['message' => 'Successfully logged out']);
31+
}
32+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Api\V1\Controllers;
4+
use App\Helpers\ApiResponse;
5+
use App\Http\Controllers\Controller;
6+
use Auth;
7+
8+
class RefreshController extends Controller
9+
{
10+
/**
11+
* Refresh a token.
12+
*
13+
* @return \Illuminate\Http\JsonResponse
14+
*/
15+
public function refresh()
16+
{
17+
$token = Auth::guard()->refresh();
18+
19+
return ApiResponse::response(200, 'Ok',
20+
['token' => $token, 'expires_in' => Auth::guard()->factory()->getTTL() * 60]);
21+
22+
}
23+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
namespace App\Api\V1\Controllers;
4+
5+
use App\Helpers\ApiResponse;
6+
use Config;
7+
use App\User;
8+
use Illuminate\Http\JsonResponse;
9+
use Tymon\JWTAuth\JWTAuth;
10+
use App\Http\Controllers\Controller;
11+
use Illuminate\Support\Facades\Password;
12+
use App\Api\V1\Requests\ResetPasswordRequest;
13+
use Symfony\Component\HttpKernel\Exception\HttpException;
14+
15+
class ResetPasswordController extends Controller
16+
{
17+
/**
18+
* @param ResetPasswordRequest $request
19+
* @param JWTAuth $JWTAuth
20+
* @return \Illuminate\Http\JsonResponse
21+
*/
22+
public function resetPassword(ResetPasswordRequest $request, JWTAuth $JWTAuth): JsonResponse
23+
{
24+
$response = $this->broker()->reset(
25+
$this->credentials($request), function ($user, $password) {
26+
$this->reset($user, $password);
27+
}
28+
);
29+
30+
if($response !== Password::PASSWORD_RESET) {
31+
throw new HttpException(500);
32+
}
33+
34+
if(!Config::get('boilerplate.reset_password.release_token')) {
35+
return response()->json([
36+
'status' => 'ok',
37+
]);
38+
}
39+
40+
$user = User::where('email', '=', $request->get('email'))->first();
41+
42+
return ApiResponse::response(200, 'Ok', ['token' => $JWTAuth->fromUser($user)]);
43+
}
44+
45+
/**
46+
* Get the broker to be used during password reset.
47+
*
48+
* @return \Illuminate\Contracts\Auth\PasswordBroker
49+
*/
50+
public function broker()
51+
{
52+
return Password::broker();
53+
}
54+
55+
/**
56+
* Get the password reset credentials from the request.
57+
*
58+
* @param ResetPasswordRequest $request
59+
* @return array
60+
*/
61+
protected function credentials(ResetPasswordRequest $request)
62+
{
63+
return $request->only(
64+
'email', 'password', 'password_confirmation', 'token'
65+
);
66+
}
67+
68+
/**
69+
* Reset the given user's password.
70+
*
71+
* @param \Illuminate\Contracts\Auth\CanResetPassword $user
72+
* @param string $password
73+
* @return void
74+
*/
75+
protected function reset($user, $password)
76+
{
77+
$user->password = $password;
78+
$user->save();
79+
}
80+
}

0 commit comments

Comments
 (0)