From 47e5c07061847acbb46ecfc201019360f9bc6e1b Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 8 Aug 2023 00:00:24 -0600 Subject: [PATCH] Add ProfileAliasController, hello account migrations! --- .../Controllers/ProfileAliasController.php | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 app/Http/Controllers/ProfileAliasController.php diff --git a/app/Http/Controllers/ProfileAliasController.php b/app/Http/Controllers/ProfileAliasController.php new file mode 100644 index 00000000..024005a8 --- /dev/null +++ b/app/Http/Controllers/ProfileAliasController.php @@ -0,0 +1,64 @@ +middleware('auth'); + } + + public function index(Request $request) + { + $aliases = $request->user()->profile->aliases; + return view('settings.aliases.index', compact('aliases')); + } + + public function store(Request $request) + { + $this->validate($request, [ + 'acct' => 'required' + ]); + + $acct = $request->input('acct'); + + if($request->user()->profile->aliases->count() >= 3) { + return back()->with('error', 'You can only add 3 account aliases.'); + } + + $webfingerService = WebfingerService::lookup($acct); + if(!$webfingerService || !isset($webfingerService['url'])) { + return back()->with('error', 'Invalid account, cannot add alias at this time.'); + } + $alias = new ProfileAlias; + $alias->profile_id = $request->user()->profile_id; + $alias->acct = $acct; + $alias->uri = $webfingerService['url']; + $alias->save(); + + return back()->with('status', 'Successfully added alias!'); + } + + public function delete(Request $request) + { + $this->validate($request, [ + 'acct' => 'required', + 'id' => 'required|exists:profile_aliases' + ]); + + $alias = ProfileAlias::where('profile_id', $request->user()->profile_id) + ->where('acct', $request->input('acct')) + ->findOrFail($request->input('id')); + + $alias->delete(); + + return back()->with('status', 'Successfully deleted alias!'); + } +}