public function loginCandidate() { // return Redirect::to('')->withInfo('Your details weren’t accepted – please register for access to a candidate portal'); $validator = Validator::make(Input::all(), array('email' => 'required|email', 'password' => 'required')); if ($validator->fails()) { return Redirect::back()->withErrors($validator->messages()); } $email = Input::get('email'); $password = Input::get('password'); if ($candidate = Candidate::where('email', '=', $email)->first()) { if (Hash::check($password, $candidate->password)) { if ($candidate->active == 1) { $candidate->last_login = new Datetime(); $candidate->save(); Session::put('candidate', $candidate); // take them back to the page they just logged in from, now with a session to their name return Redirect::to('candidate'); } else { Candidate::sendActivation($candidate->id); return Redirect::back()->withInfo('You must activate your account before logging in. We have resent the email for your convenience.'); } } } $messageBag = new Illuminate\Support\MessageBag(); $messageBag->add('candidateLogin', "The username and password did not match"); return Redirect::back()->withErrors($messageBag); }