From da0b3b5f1ce032b682c4d1e0db43d7cba025b9a3 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 15 Feb 2019 20:13:24 -0700 Subject: [PATCH] Add user invites --- app/Http/Controllers/UserInviteController.php | 52 +++++++++++++++++++ app/UserInvite.php | 15 ++++++ ...02_15_033323_create_user_invites_table.php | 39 ++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 app/Http/Controllers/UserInviteController.php create mode 100644 app/UserInvite.php create mode 100644 database/migrations/2019_02_15_033323_create_user_invites_table.php diff --git a/app/Http/Controllers/UserInviteController.php b/app/Http/Controllers/UserInviteController.php new file mode 100644 index 000000000..c9f83301f --- /dev/null +++ b/app/Http/Controllers/UserInviteController.php @@ -0,0 +1,52 @@ +paginate(10); + $limit = config('pixelfed.user_invites.limit.total'); + $used = UserInvite::whereUserId(Auth::id())->count(); + return view('settings.invites.home', compact('invites', 'limit', 'used')); + } + + public function store(Request $request) + { + abort_unless(Auth::check(), 403); + $this->validate($request, [ + 'email' => 'required|email|unique:users|unique:user_invites', + 'message' => 'nullable|string|max:500', + 'tos' => 'required|accepted' + ]); + + $invite = new UserInvite; + $invite->user_id = Auth::id(); + $invite->profile_id = Auth::user()->profile->id; + $invite->email = $request->input('email'); + $invite->message = $request->input('message'); + $invite->key = (string) Str::uuid(); + $invite->token = str_random(32); + $invite->save(); + + return redirect(route('settings.invites')); + } +} diff --git a/app/UserInvite.php b/app/UserInvite.php new file mode 100644 index 000000000..c8761a775 --- /dev/null +++ b/app/UserInvite.php @@ -0,0 +1,15 @@ +key, $this->token]); + return $url; + } +} diff --git a/database/migrations/2019_02_15_033323_create_user_invites_table.php b/database/migrations/2019_02_15_033323_create_user_invites_table.php new file mode 100644 index 000000000..62bfbd5b5 --- /dev/null +++ b/database/migrations/2019_02_15_033323_create_user_invites_table.php @@ -0,0 +1,39 @@ +bigIncrements('id'); + $table->bigInteger('user_id')->unsigned()->index(); + $table->bigInteger('profile_id')->unsigned()->index(); + $table->string('email')->unique()->index(); + $table->text('message')->nullable(); + $table->string('key'); + $table->string('token'); + $table->timestamp('valid_until')->nullable(); + $table->timestamp('used_at')->nullable()->index(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('user_invites'); + } +}