mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-26 08:13:16 +00:00
Update SiteController, add curatedOnboarding method that gracefully falls back to open registration when applicable
This commit is contained in:
parent
853a729f76
commit
95199843e3
1 changed files with 173 additions and 137 deletions
|
@ -2,14 +2,18 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Page;
|
||||||
|
use App\Profile;
|
||||||
|
use App\Services\FollowerService;
|
||||||
|
use App\Status;
|
||||||
|
use App\User;
|
||||||
|
use App\Util\ActivityPub\Helpers;
|
||||||
|
use App\Util\Localization\Localization;
|
||||||
|
use Auth;
|
||||||
|
use Cache;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use App, Auth, Cache, View;
|
use View;
|
||||||
use App\Util\Lexer\PrettyNumber;
|
|
||||||
use App\{Follower, Page, Profile, Status, User, UserFilter};
|
|
||||||
use App\Util\Localization\Localization;
|
|
||||||
use App\Services\FollowerService;
|
|
||||||
use App\Util\ActivityPub\Helpers;
|
|
||||||
|
|
||||||
class SiteController extends Controller
|
class SiteController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -29,7 +33,7 @@ class SiteController extends Controller
|
||||||
|
|
||||||
public function homeTimeline(Request $request)
|
public function homeTimeline(Request $request)
|
||||||
{
|
{
|
||||||
if($request->has('force_old_ui')) {
|
if ($request->has('force_old_ui')) {
|
||||||
return view('timeline.home', ['layout' => 'feed']);
|
return view('timeline.home', ['layout' => 'feed']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,8 +44,8 @@ class SiteController extends Controller
|
||||||
{
|
{
|
||||||
// todo: add other locales after pushing new l10n strings
|
// todo: add other locales after pushing new l10n strings
|
||||||
$locales = Localization::languages();
|
$locales = Localization::languages();
|
||||||
if(in_array($locale, $locales)) {
|
if (in_array($locale, $locales)) {
|
||||||
if($request->user()) {
|
if ($request->user()) {
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
$user->language = $locale;
|
$user->language = $locale;
|
||||||
$user->save();
|
$user->save();
|
||||||
|
@ -54,10 +58,11 @@ class SiteController extends Controller
|
||||||
|
|
||||||
public function about()
|
public function about()
|
||||||
{
|
{
|
||||||
return Cache::remember('site.about_v2', now()->addMinutes(15), function() {
|
return Cache::remember('site.about_v2', now()->addMinutes(15), function () {
|
||||||
$user_count = number_format(User::count());
|
$user_count = number_format(User::count());
|
||||||
$post_count = number_format(Status::count());
|
$post_count = number_format(Status::count());
|
||||||
$rules = config_cache('app.rules') ? json_decode(config_cache('app.rules'), true) : null;
|
$rules = config_cache('app.rules') ? json_decode(config_cache('app.rules'), true) : null;
|
||||||
|
|
||||||
return view('site.about', compact('rules', 'user_count', 'post_count'))->render();
|
return view('site.about', compact('rules', 'user_count', 'post_count'))->render();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -69,39 +74,45 @@ class SiteController extends Controller
|
||||||
|
|
||||||
public function communityGuidelines(Request $request)
|
public function communityGuidelines(Request $request)
|
||||||
{
|
{
|
||||||
return Cache::remember('site:help:community-guidelines', now()->addDays(120), function() {
|
return Cache::remember('site:help:community-guidelines', now()->addDays(120), function () {
|
||||||
$slug = '/site/kb/community-guidelines';
|
$slug = '/site/kb/community-guidelines';
|
||||||
$page = Page::whereSlug($slug)->whereActive(true)->first();
|
$page = Page::whereSlug($slug)->whereActive(true)->first();
|
||||||
|
|
||||||
return View::make('site.help.community-guidelines')->with(compact('page'))->render();
|
return View::make('site.help.community-guidelines')->with(compact('page'))->render();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function privacy(Request $request)
|
public function privacy(Request $request)
|
||||||
{
|
{
|
||||||
$page = Cache::remember('site:privacy', now()->addDays(120), function() {
|
$page = Cache::remember('site:privacy', now()->addDays(120), function () {
|
||||||
$slug = '/site/privacy';
|
$slug = '/site/privacy';
|
||||||
|
|
||||||
return Page::whereSlug($slug)->whereActive(true)->first();
|
return Page::whereSlug($slug)->whereActive(true)->first();
|
||||||
});
|
});
|
||||||
|
|
||||||
return View::make('site.privacy')->with(compact('page'))->render();
|
return View::make('site.privacy')->with(compact('page'))->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function terms(Request $request)
|
public function terms(Request $request)
|
||||||
{
|
{
|
||||||
$page = Cache::remember('site:terms', now()->addDays(120), function() {
|
$page = Cache::remember('site:terms', now()->addDays(120), function () {
|
||||||
$slug = '/site/terms';
|
$slug = '/site/terms';
|
||||||
|
|
||||||
return Page::whereSlug($slug)->whereActive(true)->first();
|
return Page::whereSlug($slug)->whereActive(true)->first();
|
||||||
});
|
});
|
||||||
|
|
||||||
return View::make('site.terms')->with(compact('page'))->render();
|
return View::make('site.terms')->with(compact('page'))->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function redirectUrl(Request $request)
|
public function redirectUrl(Request $request)
|
||||||
{
|
{
|
||||||
abort_if(!$request->user(), 404);
|
abort_if(! $request->user(), 404);
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'url' => 'required|url'
|
'url' => 'required|url',
|
||||||
]);
|
]);
|
||||||
$url = request()->input('url');
|
$url = request()->input('url');
|
||||||
abort_if(Helpers::validateUrl($url) == false, 404);
|
abort_if(Helpers::validateUrl($url) == false, 404);
|
||||||
|
|
||||||
return view('site.redirect', compact('url'));
|
return view('site.redirect', compact('url'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,17 +125,18 @@ class SiteController extends Controller
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
abort_if($user && $profile->id == $user->profile_id, 404);
|
abort_if($user && $profile->id == $user->profile_id, 404);
|
||||||
$following = $user != null ? FollowerService::follows($user->profile_id, $profile->id) : false;
|
$following = $user != null ? FollowerService::follows($user->profile_id, $profile->id) : false;
|
||||||
|
|
||||||
return view('site.intents.follow', compact('profile', 'user', 'following'));
|
return view('site.intents.follow', compact('profile', 'user', 'following'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function legacyProfileRedirect(Request $request, $username)
|
public function legacyProfileRedirect(Request $request, $username)
|
||||||
{
|
{
|
||||||
$username = Str::contains($username, '@') ? '@' . $username : $username;
|
$username = Str::contains($username, '@') ? '@'.$username : $username;
|
||||||
if(str_contains($username, '@')) {
|
if (str_contains($username, '@')) {
|
||||||
$profile = Profile::whereUsername($username)
|
$profile = Profile::whereUsername($username)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
if($profile->domain == null) {
|
if ($profile->domain == null) {
|
||||||
$url = "/$profile->username";
|
$url = "/$profile->username";
|
||||||
} else {
|
} else {
|
||||||
$url = "/i/web/profile/_/{$profile->id}";
|
$url = "/i/web/profile/_/{$profile->id}";
|
||||||
|
@ -146,7 +158,7 @@ class SiteController extends Controller
|
||||||
$profile = Profile::whereUsername($un)
|
$profile = Profile::whereUsername($un)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
if($profile->domain == null) {
|
if ($profile->domain == null) {
|
||||||
$url = "/$profile->username";
|
$url = "/$profile->username";
|
||||||
} else {
|
} else {
|
||||||
$url = $request->user() ? "/i/web/profile/_/{$profile->id}" : $profile->url();
|
$url = $request->user() ? "/i/web/profile/_/{$profile->id}" : $profile->url();
|
||||||
|
@ -157,11 +169,35 @@ class SiteController extends Controller
|
||||||
|
|
||||||
public function legalNotice(Request $request)
|
public function legalNotice(Request $request)
|
||||||
{
|
{
|
||||||
$page = Cache::remember('site:legal-notice', now()->addDays(120), function() {
|
$page = Cache::remember('site:legal-notice', now()->addDays(120), function () {
|
||||||
$slug = '/site/legal-notice';
|
$slug = '/site/legal-notice';
|
||||||
|
|
||||||
return Page::whereSlug($slug)->whereActive(true)->first();
|
return Page::whereSlug($slug)->whereActive(true)->first();
|
||||||
});
|
});
|
||||||
abort_if(!$page, 404);
|
abort_if(! $page, 404);
|
||||||
|
|
||||||
return View::make('site.legal-notice')->with(compact('page'))->render();
|
return View::make('site.legal-notice')->with(compact('page'))->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function curatedOnboarding(Request $request)
|
||||||
|
{
|
||||||
|
if ($request->user()) {
|
||||||
|
return redirect('/i/web');
|
||||||
|
}
|
||||||
|
|
||||||
|
$regOpen = (bool) config_cache('pixelfed.open_registration');
|
||||||
|
$curOnboarding = (bool) config_cache('instance.curated_registration.enabled');
|
||||||
|
$curOnlyClosed = (bool) config('instance.curated_registration.state.only_enabled_on_closed_reg');
|
||||||
|
if ($regOpen) {
|
||||||
|
if ($curOnlyClosed) {
|
||||||
|
return redirect('/register');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (! $curOnboarding) {
|
||||||
|
return redirect('/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('auth.curated-register.index', ['step' => 1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue