Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkingshott committed Dec 1, 2022
0 parents commit 06eb81d
Show file tree
Hide file tree
Showing 416 changed files with 25,358 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/node_modules
/public/hot
/public/storage
/public/build
/storage/app/*
/storage/clockwork/*
/storage/framework/*
/storage/*.key
/vendor
.vapor
.DS_Store
.env
.env.backup
.env.dusk
.env.ref
.env.staging
.env.production
.github.vapor/
.idea
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
composer.lock
coverage
Homestead.json
Homestead.yaml
npm-debug.log
package-lock.json
vapor.yml
yarn-error.log
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Important

This repo is provided for educational value only. You are not permitted to use all or part of its code to create your own version of TipSea. Doing this, or using the TipSea name, is not allowed.
75 changes: 75 additions & 0 deletions app/Actions/Authentication/LoginAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace App\Actions\Authentication;

use App\Types\Action;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Auth\Events\Lockout;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Validation\ValidationException;

class LoginAction extends Action
{
/**
* Sign the user into the application.
*
*/
public static function execute(array $payload) : void
{
static::verify($payload);

session()->regenerate();
}

/**
* Register a failed attempt to authenticate.
*
*/
protected static function fail(string $key) : void
{
RateLimiter::hit($key);

throw ValidationException::withMessages([
'email' => trans('auth.failed'),
]);
}

/**
* Prevent further authentication requests.
*
*/
protected static function throttle(string $key) : void
{
event(new Lockout(request()));

$seconds = RateLimiter::availableIn($key);

throw ValidationException::withMessages([
'email' => trans('auth.throttle', [
'seconds' => $seconds,
'minutes' => ceil($seconds / 60),
]),
]);
}

/**
* Attempt to authenticate the request's credentials.
*
*/
protected static function verify(array $payload) : mixed
{
$key = Str::lower($payload['email'] . '|' . request()->ip());

if (RateLimiter::tooManyAttempts($key, 5)) {
return static::throttle($key);
}

$credentials = Arr::only($payload, ['email', 'password']);

return Auth::attempt($credentials, $payload['remember'] ?? false)
? RateLimiter::clear($key)
: static::fail($key);
}
}
22 changes: 22 additions & 0 deletions app/Actions/Authentication/LogoutAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Actions\Authentication;

use App\Types\Action;
use Illuminate\Support\Facades\Auth;

class LogoutAction extends Action
{
/**
* Sign the user out of the application.
*
*/
public static function execute() : void
{
Auth::logout();

session()->invalidate();

session()->regenerateToken();
}
}
23 changes: 23 additions & 0 deletions app/Actions/Banner/DeleteAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Actions\Banner;

use App\Types\Action;
use App\Models\Banner;
use App\Storage\Image;

class DeleteAction extends Action
{
/**
* Delete the given banner.
*
*/
public static function execute(Banner $banner) : void
{
Image::delete($banner->graphic);

attempt(fn() => $banner->tips()->update(['banner_id' => null]));

attempt(fn() => $banner->delete());
}
}
24 changes: 24 additions & 0 deletions app/Actions/Banner/StoreAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Actions\Banner;

use App\Models\User;
use App\Types\Action;
use App\Models\Banner;
use App\Actions\Image\StoreAction as ImageAction;

class StoreAction extends Action
{
/**
* Create a new banner using the given user and payload.
*
*/
public static function execute(User $user, array $payload) : Banner
{
$banner = attempt(fn() => $user->banners()->create($payload));

ImageAction::execute($banner, 'graphic');

return $banner;
}
}
27 changes: 27 additions & 0 deletions app/Actions/Banner/UpdateAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Actions\Banner;

use App\Types\Action;
use App\Models\Banner;
use Illuminate\Support\Arr;
use App\Actions\Image\UpdateAction as ImageAction;

class UpdateAction extends Action
{
/**
* Update the given banner using the given payload.
*
*/
public static function execute(Banner $banner, array $payload) : Banner
{
static::make()->when(
$payload['graphic'] ?? '',
fn() => ImageAction::execute($banner, 'graphic', $payload['graphic'])
);

$attributes = Arr::except($payload, 'graphic');

return attempt(fn() => tap($banner)->update($attributes));
}
}
19 changes: 19 additions & 0 deletions app/Actions/Bookmark/DeleteAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Actions\Bookmark;

use App\Models\Tip;
use App\Models\User;
use App\Types\Action;

class DeleteAction extends Action
{
/**
* Delete an existing bookmark using the given user and tip.
*
*/
public static function execute(User $user, Tip $tip) : void
{
attempt(fn() => $user->bookmarks()->where('tip_id', $tip->id)->delete());
}
}
24 changes: 24 additions & 0 deletions app/Actions/Bookmark/StoreAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Actions\Bookmark;

use App\Models\Tip;
use App\Models\User;
use App\Types\Action;
use App\Models\Bookmark;

class StoreAction extends Action
{
/**
* Create a new bookmark using the given user and tip.
*
*/
public static function execute(User $user, Tip $tip) : Bookmark
{
$payload = [
'tip_id' => $tip->id,
];

return attempt(fn() => $user->bookmarks()->create($payload));
}
}
34 changes: 34 additions & 0 deletions app/Actions/Bookmark/ViewAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Actions\Bookmark;

use App\Models\Tip;
use App\Models\User;
use App\Types\Action;
use App\Actions\Tip\SearchAction;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Contracts\Pagination\Paginator;

class ViewAction extends Action
{
/**
* Retrieve the tips that have been bookmarked by the given user.
*
*/
public static function execute(User $user, array $payload) : Paginator
{
return SearchAction::execute(static::query($user), $user, $payload);
}

/**
* Generate the base query.
*
*/
protected static function query(User $user) : Builder
{
return Tip::join('bookmarks', function($join) use ($user) {
return $join->on('bookmarks.tip_id', '=', 'tips.id')
->where('bookmarks.user_id', $user->id);
});
}
}
18 changes: 18 additions & 0 deletions app/Actions/Comment/DeleteAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Actions\Comment;

use App\Types\Action;
use App\Models\Comment;

class DeleteAction extends Action
{
/**
* Delete the given comment.
*
*/
public static function execute(Comment $comment) : void
{
attempt(fn() => $comment->delete());
}
}
38 changes: 38 additions & 0 deletions app/Actions/Comment/NotifyAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Actions\Comment;

use App\Models\Tip;
use App\Models\User;
use App\Types\Action;
use App\Models\Comment;
use App\Enums\NotificationType;
use App\Actions\Notification\StoreAction;
use App\Notifications\CommentReceivedNotification;

class NotifyAction extends Action
{
/**
* Advise the owner of the given tip.
*
*/
public static function execute(User $user, Comment | Tip $source, string $message) : void
{
$tip = $source instanceof Tip ? $source : $source->tip;

StoreAction::execute($source->user, $user, $tip, NotificationType::COMMENT, $message);

if (! setting($source->user, 'notifications_email_comments')) {
return;
}

$payload = [
'user' => $user->name,
'title' => $tip->title,
'message' => $message,
'url' => route('tips.show', ['tip' => $tip]),
];

$source->user->notify(new CommentReceivedNotification($payload));
}
}
28 changes: 28 additions & 0 deletions app/Actions/Comment/ReplyAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Actions\Comment;

use App\Models\User;
use App\Types\Action;
use App\Models\Comment;

class ReplyAction extends Action
{
/**
* Create a comment from the given user for the given comment.
*
*/
public static function execute(User $user, Comment $comment, string $message) : Comment
{
$payload = [
'user_id' => $user->id,
'tip_id' => $comment->tip_id,
'parent_id' => $comment->id,
'message' => $message,
];

NotifyAction::execute($user, $comment, $message);

return attempt(fn() => Comment::create($payload));
}
}
Loading

0 comments on commit 06eb81d

Please sign in to comment.