On the error handling do this
<?php
class AccountController extends BaseController{
//view form
public function getCreate(){
return View::make('account.create');
}
//get form information
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)
//saves input if redirect occurs because of error
->withInput();
}else{
$email = Input::get('email');
$username = Input::get('username');
$password = Input::get('email');
// Activation code
$code = str_random(60);
//make fields fillable in User Model
$user = User::create(array(
'email' => $email,
'username' => $username,
//generate 60 varchar password
'password' => Hash::make($password),
'code' => $code,
'active' => 0
));
if($user) {
//code is passed to route which is then passed back to this controller and getActivate method
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')
//global is message area on email template
->with('global', 'Your account has been created! We have sent you an email to activate your account.');
}
}
}
public function getActivate($code) {
return $code;
}
}
Check out these phpacademy videos. There are 16 lessons and they are up-to-date.
Here is the link. Hope this helps.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community