Add validation to signup and trans strings

This commit is contained in:
Joseph Cohen 2015-11-08 20:12:52 -06:00
parent a88140ed53
commit 0b12d4e0c3
5 changed files with 42 additions and 16 deletions

View File

@ -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('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.unsubscribed')));
->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.signup.unsubscribed')));
}
}

View File

@ -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 <a href="https://cachethq.io" class="links">Cachet</a>.',
'about_this_site' => 'About This Site',

View File

@ -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

View File

@ -165,6 +165,8 @@ return [
'submit' => 'Submit',
'cancel' => 'Cancel',
'remove' => 'Remove',
'invite' => 'Invite',
'signup' => 'Sign Up',
// Other
'optional' => '* Optional',

View File

@ -24,24 +24,24 @@
<div class="panel panel-meassage">
<div class="panel-heading">
<strong>{{ trans('cachet.subscriber.subscribe') }}</strong>
<strong>{{ trans('cachet.signup.title') }}</strong>
</div>
<div class="panel-body">
<form action="{{ route('signup.invite', ['code' => $code]) }}" method="post" class="form">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label for="username">{{ trans('cachet.subscriber.subscribe') }}</label>
<input class="form-control" type="text" name="username">
<label for="username">{{ trans('cachet.signup.username') }}</label>
<input class="form-control" type="text" name="username" value="{{ $username }}">
</div>
<div class="form-group">
<label for="email">{{ trans('cachet.subscriber.subscribe') }}</label>
<input class="form-control" type="email" name="email">
<label for="email">{{ trans('cachet.signup.email') }}</label>
<input class="form-control" type="email" name="email" value="{{ $email }}">
</div>
<div class="form-group">
<label for="password">{{ trans('cachet.subscriber.subscribe') }}</label>
<label for="password">{{ trans('cachet.signup.password') }}</label>
<input class="form-control" type="password" name="password">
</div>
<button type="submit" class="btn btn-success">{{ trans('cachet.subscriber.button') }}</button>
<button type="submit" class="btn btn-success">{{ trans('forms.signup') }}</button>
</form>
</div>
</div>