public function postSetInitial() { $session_id = Input::get('session_id'); $stream_id = Input::get('stream_id'); $class_id = Input::get('class_id'); $section_id = Input::get('section_id'); $users_to_class = new UsersToClass(); $users_to_class->session_id = $session_id; $users_to_class->stream_id = $stream_id; $users_to_class->class_id = $class_id; $users_to_class->section_id = $section_id; $users_to_class->user_id = Sentry::getUser()->id; if ($users_to_class->save()) { return Redirect::route('user-home')->with('global', 'You Have Been Successfully Registered for this session'); } else { return Redirect::route('user-class-set-initial')->with('global', 'You can not be registered this time. Please Try later.'); } }
public function postSignIn() { $inputs = array('identity' => Input::get('identity'), 'password' => Input::get('password')); //Since user can enter username,email we cannot have email validator $rules = array('identity' => 'required|min:4|max:32', 'password' => 'required|min:6'); //Find is that username or password and change identity validation rules //Lets use regular expressions if (filter_var(Input::get('identity'), FILTER_VALIDATE_EMAIL)) { //It is email $rules['identity'] = 'required|min:4|max:32|email'; } else { //It is username . Check if username exist in profile table if (UserDetails::where('username', Input::get('identity'))->count() > 0) { //User exist so get email address $user = UserDetails::where('username', Input::get('identity'))->first(); $inputs['identity'] = $user->email; } else { Session::flash('global', 'User does not exist'); return Redirect::to('/user/sign/in')->withInput(Input::except('password')); } } $v = Validator::make($inputs, $rules); if ($v->fails()) { return Redirect::to('/user/sign/in')->withErrors($v)->withInput(Input::except('password')); } else { try { //Try to authenticate user $user = Sentry::getUserProvider()->findByLogin(Input::get('identity')); $throttle = Sentry::getThrottleProvider()->findByUserId($user->id); $throttle->check(); //Authenticate user $credentials = array('email' => Input::get('identity'), 'password' => Input::get('password')); //For now auto activate users $user = Sentry::authenticate($credentials, false); //At this point we may get many exceptions lets handle all user management and throttle exceptions } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { Session::flash('global', 'Login field is required.'); return Redirect::to('/user/sign/in'); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { Session::flash('global', 'Password field is required.'); return Redirect::to('/user/sign/in'); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { Session::flash('global', 'Wrong password, try again.'); return Redirect::to('/user/sign/in'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { Session::flash('global', 'User was not found.'); return Redirect::to('/user/sign/in'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { Session::flash('global', 'User is not activated.'); return Redirect::to('/user/sign/in'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { Session::flash('global', 'User is suspended '); return Redirect::to('/user/sign/in'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { Session::flash('global', 'User is banned.'); return Redirect::to('/user/sign/in'); } $users_login_info = UsersLoginInfo::where('user_id', '=', $user->id)->get(); Session::flash('global', 'Loggedin Successfully'); if ($users_login_info->count() > 0) { $school_id = $user->school_id; $school_session = SchoolSession::where('school_id', '=', $school_id)->where('current_session', '=', 1)->get()->first(); $user_registered_to_session = UsersToClass::where('session_id', '=', $school_session->id)->where('user_id', '=', Sentry::getUser()->id)->get(); if ($user_registered_to_session->count() > 0) { return Redirect::to(route('user-home')); } else { Session::flash('global', 'Loggedin Successfully.<br>You Have to Register For new School Session first'); return Redirect::to(route('user-class-set-initial')); } } else { return Redirect::to(route('user-welcome-settings')); } } }