Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eugcay/onepilot exam #1

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .idea/Landish.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
$schedule->command('auth:clear-resets')->everyFifteenMinutes();
}

/**
Expand Down
40 changes: 40 additions & 0 deletions app/Http/Controllers/Auth/ForgotPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use Inertia\Inertia;

class ForgotPasswordController extends Controller
{
Expand All @@ -20,6 +29,37 @@ class ForgotPasswordController extends Controller

use SendsPasswordResetEmails;


public function showLinkRequestForm(): \Inertia\Response
{
return Inertia::render('Auth/Passwords/Email');
}

/**
* @throws ValidationException
*/
public function sendResetLinkEmail(Request $request)
{

$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)
);

if ($response == Password::RESET_LINK_SENT) {
$this->sendResetLinkResponse($request, $response);
return redirect()->route('login')->with('success', 'We have sent a password reset link!');
} else {
$this->sendResetLinkFailedResponse($request, $response);
return redirect()->route('forgot')->with('error', 'We don\'t recognise this email:(');
// White Screen pops up after echo...
}
}

/**
* Create a new controller instance.
*
Expand Down
33 changes: 33 additions & 0 deletions app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Password;
use Inertia\Inertia;

class ResetPasswordController extends Controller
{
Expand Down Expand Up @@ -36,4 +39,34 @@ public function __construct()
{
$this->middleware('guest');
}

public function showResetForm()
{
return Inertia::render('Auth/Passwords/Reset');
}

public function reset(Request $request)
{
{
$request->validate($this->rules(), $this->validationErrorMessages());

// Here we will attempt to reset the user's password. If it is successful we
// will update the password on an actual user model and persist it to the
// database. Otherwise we will parse the error and return the response.
$response = $this->broker()->reset(
$this->credentials($request), function ($user, $password) {
$this->resetPassword($user, $password);
}
);

// If the password was successfully reset, we will redirect the user back to
// the application's home authenticated view. If there is an error we can
// redirect them back to where they came from with their error message.
if ($response == Password::PASSWORD_RESET) {
$this->sendResetResponse($request, $response);
} else {
$this->sendResetFailedResponse($request, $response);
}
}
}
}
16 changes: 14 additions & 2 deletions app/Http/Controllers/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@

namespace App\Http\Controllers;

use App\Http\Resources\ReportsCollection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Request;
use Inertia\Inertia;

class ReportsController extends Controller
{
public function __invoke()
public function index()
{
return Inertia::render('Reports/Index');
return Inertia::render('Reports/Index', [
'filters' => Request::all('search', 'trashed'),
'reports' => new ReportsCollection(
Auth::user()->account->reports()
->orderBy('title')
->filter(Request::only('search', 'trashed'))
->paginate()
->appends(Request::all())
),
]);
}
}
21 changes: 21 additions & 0 deletions app/Http/Resources/ReportsCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;

class ReportsCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return $this->collection->map->only(
'id', 'title', 'description', 'date', 'deleted_at'
);
}
}
25 changes: 25 additions & 0 deletions app/Http/Resources/ReportsResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ReportsResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->title,
'description' => $this->description,
'date' => $this->date,
'deleted_at' => $this->deleted_at,
];
}
}
5 changes: 5 additions & 0 deletions app/Models/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public function organizations()
return $this->hasMany(Organization::class);
}

public function reports()
{
return $this->hasMany(Report::class);
}

public function contacts()
{
return $this->hasMany(Contact::class);
Expand Down
24 changes: 24 additions & 0 deletions app/Models/Report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;

class Report extends Model
{
use SoftDeletes, HasFactory;

public function scopeFilter($query, array $filters)
{
$query->when($filters['search'] ?? null, function ($query, $search) {
$query->where('title', 'like', '%'.$search.'%');
})->when($filters['trashed'] ?? null, function ($query, $trashed) {
if ($trashed === 'with') {
$query->withTrashed();
} elseif ($trashed === 'only') {
$query->onlyTrashed();
}
});
}
}
20 changes: 19 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Models;

use App\Notifications\ResetPasswordNotification;
use Illuminate\Contracts\Auth\CanResetPassword;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use League\Glide\Server;
use Illuminate\Support\Facades\App;
Expand All @@ -14,14 +16,20 @@
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Http\UploadedFile;

class User extends Model implements AuthenticatableContract, AuthorizableContract
class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPassword
{
use SoftDeletes, Authenticatable, Authorizable, HasFactory;
use \Illuminate\Notifications\Notifiable;

protected $casts = [
'owner' => 'boolean',
];

protected $fillable = [
'email',
'password',
];

public function account()
{
return $this->belongsTo(Account::class);
Expand Down Expand Up @@ -93,4 +101,14 @@ public function scopeFilter($query, array $filters)
}
});
}

public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}

public function getEmailForPasswordReset(): string
{
return $this->email;
}
}
Loading