From 0b12d4e0c373e64773c72d6119778013d06d88e6 Mon Sep 17 00:00:00 2001 From: Joseph Cohen Date: Sun, 8 Nov 2015 20:12:52 -0600 Subject: [PATCH] Add validation to signup and trans strings --- app/Http/Controllers/SignupController.php | 26 ++++++++++++++++------- resources/lang/en/cachet.php | 9 ++++++++ resources/lang/en/dashboard.php | 7 +++++- resources/lang/en/forms.php | 2 ++ resources/views/signup.blade.php | 14 ++++++------ 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/SignupController.php b/app/Http/Controllers/SignupController.php index 178a2ac7..b865a1b9 100644 --- a/app/Http/Controllers/SignupController.php +++ b/app/Http/Controllers/SignupController.php @@ -11,6 +11,7 @@ namespace CachetHQ\Cachet\Http\Controllers; +use AltThree\Validator\ValidationException; use CachetHQ\Cachet\Commands\Invite\ClaimInviteCommand; use CachetHQ\Cachet\Commands\User\SignupUserCommand; use CachetHQ\Cachet\Facades\Setting; @@ -50,7 +51,9 @@ class SignupController extends Controller return View::make('signup') ->withPageTitle(Setting::get('app_name')) ->withAboutApp(Markdown::convertToHtml(Setting::get('app_about'))) - ->withCode($invite->code); + ->withCode($invite->code) + ->withUsername(Binput::old('username')) + ->withEmail(Binput::old('emai', $invite->email)); } /** @@ -72,16 +75,23 @@ class SignupController extends Controller throw new BadRequestHttpException(); } - $this->dispatch(new SignupUserCommand( - Binput::get('username'), - Binput::get('password'), - Binput::get('email'), - 2 - )); + try { + $this->dispatch(new SignupUserCommand( + Binput::get('username'), + Binput::get('password'), + Binput::get('email'), + 2 + )); + } catch (ValidationException $e) { + return Redirect::route('signup.invite', ['code' => $invite->code]) + ->withInput(Binput::except('password')) + ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('cachet.signup.failure'))) + ->withErrors($e->getMessageBag()); + } $this->dispatch(new ClaimInviteCommand($invite)); return Redirect::route('status-page') - ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.unsubscribed'))); + ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('cachet.signup.unsubscribed'))); } } diff --git a/resources/lang/en/cachet.php b/resources/lang/en/cachet.php index e72106ce..73028119 100755 --- a/resources/lang/en/cachet.php +++ b/resources/lang/en/cachet.php @@ -87,6 +87,15 @@ return [ ], ], + 'signup' => [ + 'title' => 'Sign Up', + 'username' => 'Username', + 'email' => 'Email', + 'password' => 'Password', + 'success' => 'Your account has been created.', + 'failure' => 'Something went wrong with the signup.', + ], + // Other 'powered_by' => ':app Status Page is powered by Cachet.', 'about_this_site' => 'About This Site', diff --git a/resources/lang/en/dashboard.php b/resources/lang/en/dashboard.php index db440c2d..1a63d36a 100755 --- a/resources/lang/en/dashboard.php +++ b/resources/lang/en/dashboard.php @@ -142,7 +142,7 @@ return [ 'add' => [ 'title' => 'Add a New Team Member', 'success' => 'Team member added.', - 'failure' => 'Something went wrong with the component.', + 'failure' => 'Something went wrong with the user.', ], 'edit' => [ 'title' => 'Update Profile', @@ -153,6 +153,11 @@ return [ 'success' => 'User deleted.', 'failure' => 'Something went wrong when deleting this user.', ], + 'invite' => [ + 'title' => 'Invite a New Team Member', + 'success' => 'The users invited.', + 'failure' => 'Something went wrong with the invite.', + ], ], // Settings diff --git a/resources/lang/en/forms.php b/resources/lang/en/forms.php index 8b7478a0..123d1883 100755 --- a/resources/lang/en/forms.php +++ b/resources/lang/en/forms.php @@ -165,6 +165,8 @@ return [ 'submit' => 'Submit', 'cancel' => 'Cancel', 'remove' => 'Remove', + 'invite' => 'Invite', + 'signup' => 'Sign Up', // Other 'optional' => '* Optional', diff --git a/resources/views/signup.blade.php b/resources/views/signup.blade.php index 64fe08de..48f6b121 100644 --- a/resources/views/signup.blade.php +++ b/resources/views/signup.blade.php @@ -24,24 +24,24 @@
- {{ trans('cachet.subscriber.subscribe') }} + {{ trans('cachet.signup.title') }}
- - + +
- - + +
- +
- +