Skip to content

Commit

Permalink
add activate / deactivate to the account
Browse files Browse the repository at this point in the history
Signed-off-by: Suhayb El Wardany <[email protected]>
  • Loading branch information
suwardany committed Mar 20, 2014
1 parent f9b3b2c commit 9513730
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 16 deletions.
12 changes: 11 additions & 1 deletion app/controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down
41 changes: 32 additions & 9 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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');
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 14 additions & 4 deletions app/views/sentry/account/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

@section('body')

<div class="container">

<div class="page-header">
<h1>My Account</h1>
</div>
Expand Down Expand Up @@ -36,8 +34,20 @@

{{ Carbon\Carbon::now() }}
</div>
</div>

</div>
<div class="col-md-6">
<h3>Activation</h3>

@if ($user->isActivated())

<a class="btn btn-danger" href="{{ URL::to('deactivate') }}">Deactivate</a>

@else

<a class="btn btn-default" href="{{ URL::to('reactivate') }}">Activate</a>

@endif
</div>


@stop
8 changes: 6 additions & 2 deletions app/views/template.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@
<li{{ Request::is('groups*') ? ' class="active"' : null }}><a href="{{ URL::to('groups') }}">Groups</a></li>
@endif
</ul>
@if (Sentry::check())
@if ($user = Sentry::check())
<ul class="nav navbar-nav pull-right">
<li{{ Request::is('account') ? ' class="active"' : null }}><a href="{{ URL::to('account') }}">Account</a></li>
<li{{ Request::is('account') ? ' class="active"' : null }}><a href="{{ URL::to('account') }}">Account
@if ( ! $user->isActivated())
<span class="label label-danger">Inactive</span>
@endif
</a></li>
<li><a href="{{ URL::to('logout') }}">Logout</a></li>
</ul>
@endif
Expand Down

0 comments on commit 9513730

Please sign in to comment.