Created
March 19, 2014 15:52
-
-
Save dannymichel/9644698 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AccountController extends BaseController { | |
public function getCreate(){ | |
return View::make('account.create'); | |
} | |
public function postCreate(){ | |
$validator = Validator::make(Input::all(), | |
array( | |
'email' => 'required|max:50|email|unique:users', | |
'username' => 'required|max:20|min:3|unique:users', | |
'password' => 'required|min:6', | |
'password_again' => 'required|same:password' | |
) | |
); | |
if($validator->fails()) { | |
return Redirect::route('account-create') | |
->withErrors($validator) | |
->withInput(); | |
} else { | |
$email = Input::get('email'); | |
$username = Input::get('username'); | |
$password = Input::get('password'); | |
$code = str_random(60); | |
$user = User::create(array( | |
'email' => $email, | |
'username' => $username, | |
'password' => Hash::make($password), | |
'code' => $code, | |
'active' => 0 | |
)); | |
if($user) { | |
Mail::send('emails.auth.activate', array('link' => URL::route('account-activate', $code), 'username' => $username), function($message) use ($user) { $message->to($user->email, $user->$username)->subject('Activate your account'); | |
}); | |
return Redirect::route('home') | |
->with('global', 'Your account has been created. We have sent you an e-mail to activate your account.'); | |
} | |
} | |
} | |
public function getActivate($code){ | |
$user = User::where('code', '=', $code)->where('active', '=', 0); | |
if($user->count()){ | |
$user = $user->first(); | |
$user->active = 1; | |
$user->code = ''; | |
if($user->save()){ | |
return Redirect::route('home') | |
->with('global', 'Activated. You can now sign in.'); | |
} | |
} | |
return Redirect::route('home') | |
->with('global', 'We could not activate your account. Try again later.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment