diff --git a/app/controllers/AuthController.php b/app/controllers/AuthController.php index bffd4ae6..1dc807bb 100644 --- a/app/controllers/AuthController.php +++ b/app/controllers/AuthController.php @@ -97,7 +97,17 @@ public function processRegistration() { $code = Activation::create($user); - return Redirect::to("reactivate/{$user->getUserId()}/{$code}"); + $sent = Mail::send('sentry.emails.activate', compact('user', 'code'), function($m) use ($user) + { + $m->to($user->email)->subject('Activate Your Account'); + }); + + if ( ! $sent) + { + return Redirect::to('register')->withErrors('Failed to send activation email.'); + } + + return Redirect::to("login")->withSuccess('An activation email has been sent.')->with('userId', $user->getUserId()); } return Redirect::to('register')->withInput()->withErrors('Failed to register.'); diff --git a/app/routes.php b/app/routes.php index 47782cf7..0342de90 100644 --- a/app/routes.php +++ b/app/routes.php @@ -62,16 +62,23 @@ if ( ! Activation::complete($user, $code)) { - return Redirect::to("reactivate/{$user->getUserId()}/{$code}") + return Redirect::to("login") ->withErrors('Invalid or expired activation code.'); } return Redirect::to('login')->withSuccess('Account activated.'); })->where('id', '\d+'); -Route::get('reactivate/{id}/{code}', function($id, $code) +Route::get('reactivate', function() { - $user = Sentry::findById($id); + if ( ! $user = Sentry::check()) + { + return Redirect::to('login'); + } + + $activation = Activation::exists($user) ?: Activation::create($user); + + $code = $activation->code; $sent = Mail::send('sentry.emails.activate', compact('user', 'code'), function($m) use ($user) { @@ -84,9 +91,17 @@ } return Redirect::to('wait'); - })->where('id', '\d+'); +Route::get('deactivate', function() +{ + $user = Sentry::check(); + + Activation::remove($user); + + return Redirect::back(); +}); + Route::get('reset', function() { return View::make('sentry.reset.begin'); @@ -118,7 +133,9 @@ ->withErrors('No user with that email address belongs in our system.'); } - $code = Reminder::create($user); + $reminder = Reminder::exists($user) ?: Reminder::create($user); + + $code = $reminder->code; $sent = Mail::send('sentry.emails.reminder', compact('user', 'code'), function($m) use ($user) { @@ -169,22 +186,28 @@ if ( ! Reminder::complete($user, $code, Input::get('password'))) { return Redirect::to('login') - ->with('Invalid or expired reset code.'); + ->withErrors('Invalid or expired reset code.'); } - return Redirect::to('login'); + return Redirect::to('login')->withSuccess("Password Reset."); })->where('id', '\d+'); - Route::group(['prefix' => 'account', 'before' => 'auth'], function() { + Route::get('/', function() { $user = Sentry::getUser(); $persistence = Sentry::getPersistence(); + $activationCode = ''; + + if ( ! $user->isActivated()) + { + $activationCode = Activation::exists($user); + } - return View::make('sentry.account.home', compact('user', 'persistence')); + return View::make('sentry.account.home', compact('user', 'persistence', 'activationCode')); }); Route::get('kill/{code}', function($code) diff --git a/app/views/sentry/account/home.blade.php b/app/views/sentry/account/home.blade.php index 72bd5c09..88d0cb23 100644 --- a/app/views/sentry/account/home.blade.php +++ b/app/views/sentry/account/home.blade.php @@ -6,8 +6,6 @@ @section('body') -
- @@ -36,8 +34,20 @@ {{ Carbon\Carbon::now() }}
- - +
+

Activation

+ + @if ($user->isActivated()) + + Deactivate + + @else + + Activate + + @endif +
+ @stop diff --git a/app/views/template.blade.php b/app/views/template.blade.php index f67d2821..de4dc8c0 100644 --- a/app/views/template.blade.php +++ b/app/views/template.blade.php @@ -49,9 +49,13 @@ Groups @endif - @if (Sentry::check()) + @if ($user = Sentry::check()) @endif