Skip to content

Commit

Permalink
Merge pull request #117 from Kurozora/wesbite
Browse files Browse the repository at this point in the history
  • Loading branch information
kiritokatklian authored Apr 21, 2021
2 parents 64c778b + 40a2f88 commit 510d9bb
Show file tree
Hide file tree
Showing 35 changed files with 1,980 additions and 220,701 deletions.
20 changes: 9 additions & 11 deletions app/Http/Controllers/MiscController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Storage;
use League\CommonMark\CommonMarkConverter;
use Markdown;

class MiscController extends Controller
{
Expand All @@ -21,17 +21,17 @@ class MiscController extends Controller
public function getPrivacyPolicy(): JsonResponse
{
// Get MarkDown content
$privacyPolicyText = $this->getContentOfFile('resources/static/privacy_policy.md');
$privacyPolicyMarkdown = $this->getContentOfFile('resources/static/privacy_policy.md');

// Prepare for converting Markdown to HTML
$commonMarkConverter = new CommonMarkConverter();
$privacyPolicyText = Markdown::parse($privacyPolicyMarkdown);

return JSONResult::success([
'data' => [
'type' => 'legal',
'href' => route('api.legal.privacy-policy', [], false),
'attributes' => [
'text' => $commonMarkConverter->convertToHtml($privacyPolicyText)
'text' => $privacyPolicyText->toHtml()
]
]
]);
Expand All @@ -47,17 +47,17 @@ public function getPrivacyPolicy(): JsonResponse
public function getTermsOfUse(): JsonResponse
{
// Get MarkDown content
$termsOfUseText = $this->getContentOfFile('resources/static/terms_of_use.md');
$termsOfUseMarkdown = $this->getContentOfFile('resources/static/terms_of_use.md');

// Prepare for converting Markdown to HTML
$commonMarkConverter = new CommonMarkConverter();
$termsOfUseText = Markdown::parse($termsOfUseMarkdown);

return JSONResult::success([
'data' => [
'type' => 'legal',
'href' => route('api.legal.terms-of-use', [], false),
'attributes' => [
'text' => $commonMarkConverter->convertToHtml($termsOfUseText)
'text' => $termsOfUseText->toHtml()
]
]
]);
Expand All @@ -73,12 +73,10 @@ public function getTermsOfUse(): JsonResponse
*/
protected function getContentOfFile(string $filePath): string
{
// Get the privacy policy text
$termsOfUseText = null;

// Create the file if it does not exist yet
if (!Storage::exists($filePath))
if (!Storage::exists($filePath)) {
Storage::put($filePath, 'Page is empty. Please inform an administrator.');
}

// Get the last update date
$lastUpdateUnix = Carbon::createFromTimestamp(Storage::lastModified($filePath));
Expand Down
12 changes: 11 additions & 1 deletion app/Http/Controllers/Web/NewPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ class NewPasswordController extends Controller
*/
public function create(Request $request): Application|Factory|View
{
return view('auth.reset-password', ['request' => $request]);
// Obfuscate the email for privacy.
$em = explode('@', $request->email);
$name = implode('@', array_slice($em, 0, count($em) - 1));
$len = strlen($name);

$email = substr($name, 0, 1 - $len) . str_repeat('*', $len - 1) . '@' . end($em);

return view('auth.reset-password', [
'email' => $email,
'request' => $request
]);
}

/**
Expand Down
7 changes: 2 additions & 5 deletions app/Http/Controllers/Web/PasswordResetLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ public function store(Request $request): RedirectResponse
// 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.
$status = Password::sendResetLink(
Password::sendResetLink(
$request->only('email')
);

return $status == Password::RESET_LINK_SENT
? back()->with('status', __($status))
: back()->withInput($request->only('email'))
->withErrors(['email' => __($status)]);
return back()->with('status', __('If an account exists with this Kurozora ID, you should receive an email with your reset link shortly.'));
}
}
24 changes: 23 additions & 1 deletion app/Http/Controllers/Web/SignUpUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Requests\Web\SignUpRequest;
use App\Models\User;
use Auth;
use Browser;
use Illuminate\Auth\Events\Registered;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
Expand Down Expand Up @@ -45,7 +46,11 @@ public function store(SignUpRequest $request): Application|RedirectResponse|Redi
$newUser = User::create([
'username' => $data['username'],
'email' => $data['email'],
'password' => User::hashPass($data['password'])
'password' => User::hashPass($data['password']),
'settings' => [
'can_change_username' => false,
'tv_rating' => -1
]
]);

if ($request->hasFile('profileImage') &&
Expand All @@ -58,6 +63,23 @@ public function store(SignUpRequest $request): Application|RedirectResponse|Redi

Auth::login($newUser);

$this->prepareAuthenticatedSession();

return redirect('/');
}

/**
* Prepares the authenticated session for the newly authenticated user.
*/
protected function prepareAuthenticatedSession()
{
$browser = Browser::detect();

Auth::user()->createSession([
'platform' => $browser->platformFamily(),
'platform_version' => $browser->platformVersion(),
'device_vendor' => $browser->deviceFamily(),
'device_model' => $browser->deviceModel(),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Controllers\Controller;
use App\Http\Requests\Web\TwoFactorSignInRequest;
use Auth;
use Browser;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
Expand Down Expand Up @@ -48,6 +49,23 @@ public function store(TwoFactorSignInRequest $request): RedirectResponse

Auth::login($user, $request->remember());

$this->prepareAuthenticatedSession();

return redirect()->intended();
}

/**
* Prepares the authenticated session for the newly authenticated user.
*/
protected function prepareAuthenticatedSession()
{
$browser = Browser::detect();

Auth::user()->createSession([
'platform' => $browser->platformFamily(),
'platform_version' => $browser->platformVersion(),
'device_vendor' => $browser->deviceFamily(),
'device_model' => $browser->deviceModel(),
]);
}
}
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"guzzlehttp/guzzle": "^7.3",
"hisorange/browser-detect": "^4.4",
"imdhemy/laravel-purchases": "^0.10.2",
"itsgoingd/clockwork": "^5.0",
"laraning/nova-time-field": "^1.0",
"laravel-notification-channels/apn": "^3.0",
"laravel/framework": "^8.0",
Expand Down
Loading

0 comments on commit 510d9bb

Please sign in to comment.