forked from caneara/tipsea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 06eb81d
Showing
416 changed files
with
25,358 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
Oops, something went wrong.