Skip to content

Commit

Permalink
Merge pull request #9 from xPand4B/v1.1.1
Browse files Browse the repository at this point in the history
V1.1.1
  • Loading branch information
xPand4B authored Feb 19, 2020
2 parents b3e1c6f + 626ee53 commit 62e9473
Show file tree
Hide file tree
Showing 45 changed files with 1,146 additions and 453 deletions.
24 changes: 14 additions & 10 deletions .env.example → .env.dev
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
APP_NAME=MiPa-Pool
BRAND_ICON=

APP_ENV=production
APP_KEY=
APP_DEBUG=false
APP_ENV=local
APP_KEY=base64:5rVvnSC4Td2RY0QkhkhyqUPQwoWYol3Lkxa1uNOkgHg=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

# Database Credentials
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

# Mail Settings
MAIL_DRIVER=smtp
MAIL_HOST=YOUR_EMAIL_HOSTER
MAIL_PORT=465
MAIL_USERNAME=YOUR_EMAIL_ADDRESS
MAIL_PASSWORD=YOUR_EMAIL_PASSWORD
MAIL_ENCRYPTION=
MAIL_FROM_ADDRESS=SPECIFY_EMAIL_ADDRESS


BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
Expand All @@ -25,13 +36,6 @@ REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
Expand Down
29 changes: 29 additions & 0 deletions .env.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
APP_NAME=MiPa-Pool
BRAND_ICON=

APP_KEY=

# Database Credentials
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

# Mail Settings
MAIL_DRIVER=smtp
MAIL_HOST=YOUR_EMAIL_HOSTER
MAIL_PORT=465
MAIL_USERNAME=YOUR_EMAIL_ADDRESS
MAIL_PASSWORD=YOUR_EMAIL_PASSWORD
MAIL_ENCRYPTION=
MAIL_FROM_ADDRESS=SPECIFY_EMAIL_ADDRESS

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=eu

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
8 changes: 7 additions & 1 deletion UPDATE/UPDATE-1.1.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# How to update to v1.1.x
Version 1.1.x and above are **not compatible** with v1.0.x

In order to update to version 1.1.x you have to do `git pull`.

After that typ `php artisan migrate` to add the new migrations and your done.
After that typ `php artisan migrate:fresh` to add the new migrations.

**!! WARNING!!**

This will delete all existing users!

# Changelog for MiPa-Pool v1.1.x

Expand Down
35 changes: 35 additions & 0 deletions app/Http/Controllers/Auth/ForgotPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace App\Http\Controllers\Auth;

use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Events\SendFlashMessageEvent;
use Illuminate\Support\Facades\Password;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;

class ForgotPasswordController extends Controller
Expand All @@ -29,4 +33,35 @@ public function __construct()
{
$this->middleware('guest');
}

/**
* Send a reset link to the given user.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
*/
public function sendResetLinkEmail(Request $request)
{
$user = User::where('email', $request->email)->first();

if ($user == null) {
event(new SendFlashMessageEvent('error', trans('passwords.user')));
return redirect()->back();
}

$this->validateEmail($request);

// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
$response = $this->broker()->sendResetLink(
$this->credentials($request)
);

event(new SendFlashMessageEvent('success', trans('passwords.sent')));

return $response == Password::RESET_LINK_SENT
? $this->sendResetLinkResponse($request, $response)
: $this->sendResetLinkFailedResponse($request, $response);
}
}
25 changes: 22 additions & 3 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Http\Controllers\Auth;

use Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

Expand Down Expand Up @@ -38,12 +41,28 @@ public function __construct()
}

/**
* Replaces default auth field 'email' with 'username'
* Override redirectTo method.
*
* @return void
*/
public function username()
public function redirectTo()
{
return 'username';
Log::info("User #".Auth::user()->id." has successfully logged in.");
}

/**
* Get the needed authorization credentials from the request.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
protected function credentials(Request $request)
{
$field = filter_var($request->get($this->username()), FILTER_VALIDATE_EMAIL) ? $this->username() : 'username';

return [
$field => $request->get($this->username()),
'password' => $request->password,
];
}
}
13 changes: 9 additions & 4 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Mail;
use App\Mail\Auth\EmailVerificationMail;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;

Expand Down Expand Up @@ -53,7 +55,7 @@ protected function validator(array $data)
'username' => 'required|string|max:255|unique:users',
'firstname' => 'required|string|max:255',
'surname' => 'required|string|max:255',
// 'email' => 'required|string|email|max:255|unique:users',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
}
Expand All @@ -70,12 +72,15 @@ protected function create(array $data)
'username' => $data['username'],
'firstname' => $data['firstname'],
'surname' => $data['surname'],
// 'email' => $data['email'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);

Log::info("User #".$user->id." has been successfully created.");


Mail::to($user->email)
->send(new EmailVerificationMail($user));

return $user;
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use Auth;
use App\Models\Menu;
use App\Models\Order;
use App\Helper\TimeHelper;
use App\Helper\CurrencyHelper;
Expand All @@ -12,7 +13,6 @@
use App\Events\Orders\UpdateOrderEvent;
use App\Http\Requests\Orders\OrderRequest;
use App\Events\Orders\NewOrderCreationEvent;
use App\Models\Menu;

class OrderController extends Controller
{
Expand All @@ -33,7 +33,7 @@ public function index()
{
$orders = Order::Open()
->orderBy('id', 'desc')
->paginate(15);
->paginate(10);

for($i = 0; $i < sizeof($orders); $i++){
$orders[$i] = CurrencyHelper::getSum($orders[$i]);
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class Kernel extends HttpKernel
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
/**
* Custom Middlewares
*/
\App\Http\Middleware\CheckIfEmailExists::class,
],

'api' => [
Expand Down
36 changes: 36 additions & 0 deletions app/Http/Middleware/CheckIfEmailExists.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Middleware;

use Auth;
use Closure;
use Illuminate\Support\Facades\Log;
use App\Notifications\AddEmailNotification;

class CheckIfEmailExists
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($user = Auth::user()) {
if (! isset($user->email)) {
if ($user->notifications->where('type', 'App\Notifications\AddEmailNotification')->count() == 0 ) {
$user->notify(new AddEmailNotification($user->id));
Log::info("User #".Auth::user()->id." has received the 'AddEmail' notification.");
}
}else{
if ($user->notifications->where('type', 'App\Notifications\AddEmailNotification')->count() == 1 ) {
$user->notifications->where('type', 'App\Notifications\AddEmailNotification')->first()->markAsRead();
}
}
}

return $next($request);
}
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RedirectIfAuthenticated
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/home');
return redirect('/');
}

return $next($request);
Expand Down
12 changes: 6 additions & 6 deletions app/Listeners/Profile/UpdateProfileListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public function handle()
}

// Check if email has changed
// if(request('email') != $user->email){
// request()->validate([
// 'email' => 'required|email|max:255|unique:users'
// ]);
// }
if(request('email') != $user->email){
request()->validate([
'email' => 'required|email|max:255|unique:users'
]);
}

// Check if password is set
if(!empty(request('password'))){
Expand All @@ -82,7 +82,7 @@ public function handle()
'username' => request('username'),
'firstname' => request('firstname'),
'surname' => request('surname'),
// 'email' => request('email'),
'email' => request('email'),
'about_me' => request('about_me'),
]);

Expand Down
54 changes: 54 additions & 0 deletions app/Mail/Auth/EmailVerificationMail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App\Mail\Auth;

use Carbon\Carbon;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use App\MiPaPo\Mail\MiPaPoMailer;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\URL;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class EmailVerificationMail extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels, MiPaPoMailer;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
$verifyUrl = URL::temporarySignedRoute(
'verification.verify',
Carbon::now()->addMinutes(config('auth.verification.expire', 60)),
['id' => $this->user->id]
);

$mail = $this
->subject(trans('mail.verify.subject'))
->introLines([
trans('mail.verify.line')
])
->action(trans('mail.verify.action'), $verifyUrl)
->markdown('mails.default');

Log::info("User #".$this->user->id." has requested an 'verify email' email.");

return $mail;
}
}
Loading

0 comments on commit 62e9473

Please sign in to comment.