/** * This function is login the user in by taking the username and password. * * @param unknown $username * @param unknown $password * @return boolean */ public function authenticateUser($username, $password) { try { // Authenticate the user $credentials = array('email' => $username, 'password' => $password); $user = Sentry::authenticate($credentials, false); // calling the event of setting user session $subscriber = new SentryuserEventHandler(); Event::subscribe($subscriber); Event::fire('sentryuser.login', $user); return true; } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { SentryHelper::setMessage('Login field is required.', 'warning'); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { SentryHelper::setMessage('Password field is required.', 'warning'); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { SentryHelper::setMessage('Wrong password, try again.', 'warning'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { SentryHelper::setMessage('User was not found.', 'warning'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { SentryHelper::setMessage('User is not activated.', 'warning'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { SentryHelper::setMessage('User is suspended.', 'warning'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { SentryHelper::setMessage('User is banned.', 'warning'); } }
public function login() { $account = Input::get('account'); $password = Input::get('password'); if (!isset($account)) { return Response::json(array('error_code' => 1, 'message' => '请输入账户')); } if (!isset($password)) { return Response::json(array('error_code' => 2, 'message' => '请输入密码')); } $user = User::where('account', $account)->first(); if (!isset($user)) { return Response::json(array('error_code' => 3, 'message' => '用户名不存在')); } if (!($user->role & 0x2)) { return Response::json(array('error_code' => 4, 'message' => '无效用户')); } try { Sentry::authenticate(array('phone' => $user->phone, 'password' => $password)); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Response::json(array('error_code' => 5, 'message' => '用户名或密码错误')); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Response::json(array('error_code' => 5, 'message' => '用户名或密码错误')); } $doctor = Doctor::where('user_id', $user->id)->first(); Session::put('user.id', $user->id); Session::put('doctor.id', $doctor->id); Session::put('doctor.name', $doctor->name); Session::put('doctor.photo', $doctor->photo); return Response::json(array('error_code' => 0, 'message' => '登录成功')); }
public function login_post() { if (!Request::ajax()) { App::abort('401'); } $data = array('status' => 'success', 'message' => ''); try { // Set login credentials $credentials = array('email' => Input::get('email'), 'password' => Input::get('password')); $remember = Input::get('remember') ? Input::get('remember') : false; // Try to authenticate the user $user = Sentry::authenticate($credentials, $remember); $data['status'] = 'success'; $data['message'] = 'Login Success. Redirecting'; } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { $data['status'] = 'error'; $data['message'] = 'Login field is required.'; } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { $data['status'] = 'error'; $data['message'] = 'Password field is required.'; } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { $data['status'] = 'error'; $data['message'] = 'Wrong password, try again.'; } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { $data['status'] = 'error'; $data['message'] = 'User was not found.'; } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { $data['status'] = 'error'; $data['message'] = 'User is not activated.'; } $response = Response::make(json_encode($data), 200); $response->header('Content-Type', 'text/json'); return $response; }
public function postLogin() { $usuario = Input::get('usuario'); $credentials = array('usuario' => $usuario, 'password' => Input::get('password')); try { $user = Sentry::authenticate($credentials, false); if ($user) { return Redirect::route('admin.index'); } } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { return Redirect::route('login')->withErrors('Ingrese su usuario.'); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Redirect::route('login')->withErrors('Ingrese su contraseña.'); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return Redirect::route('login')->withErrors('Contraseña incorrecta, vuelva a intentar.'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Redirect::route('login')->withErrors('No se encontró el usuario [' . $usuario . ']'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Redirect::route('login')->withErrors('Usuario [' . $usuario . '] inactivo, no puede ingresar.'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { return Redirect::route('login')->withErrors('Usuario [' . $usuario . '] está suspendido.'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { return Redirect::route('login')->withErrors('El usuario [' . $usuario . '] ha sido baneado.'); } /*catch(\Exception $e) { return Redirect::route('login') ->withErrors(array('login' => $e->getMessage())); }*/ }
/** * Show the form for creating a new resource. * * @return Response */ public function user_login() { if (Session::token() !== Input::get('_token')) { $response = array('status' => 'fail', 'msg' => 'unauthorized login'); } try { // Set login credentials $credentials = array('email' => Input::get('username'), 'password' => Input::get('password')); // Try to authenticate the user $user = Sentry::authenticate($credentials, false); if ($user) { $response = array('status' => 'success', 'msg' => 'congratulations!!!!'); } } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { $response = array('status' => 'fail', 'msg' => 'Login field is required.'); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { $response = array('status' => 'fail', 'msg' => 'Password field is required.'); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { $response = array('status' => 'fail', 'msg' => 'Wrong password, try again.'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { $response = array('status' => 'fail', 'msg' => 'Agent was not found.'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { $response = array('status' => 'fail', 'msg' => 'Sorry!! seams you are not activated to use the system.. please visit the system administrator.'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { $response = array('status' => 'fail', 'msg' => 'Sorry!! seams you are suspended from using the system.. please visit the system administrator.'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { $response = array('status' => 'fail', 'msg' => 'Sorry!! seams you are baned from using the system.. please visit the system administrator.'); } return Response::json($response); }
public function getIndex() { if (Sentry::check()) { return View::make('account', ['title' => 'Settings']); } else { if (Input::has('username') && Input::has('password')) { $username = Input::get('username'); $password = Input::get('password'); $input_remember = Input::get('remember'); $remember = false; if (isset($input_remember) && $input_remember == true) { $remember = true; } try { // Login credentials $credentials = array('username' => $username, 'password' => $password); // Authenticate the user $user = Sentry::authenticate($credentials, $remember); return Redirect::to('account'); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return View::make('account')->nest('sign_in_form', 'child.signin')->nest('update_msg', 'child.alerts', array('msg_type' => 'warning', 'msg' => 'Wrong password, try again.')); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return View::make('account')->nest('sign_in_form', 'child.signin')->nest('update_msg', 'child.alerts', array('msg_type' => 'warning', 'msg' => 'User was not found.')); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return View::make('account')->nest('sign_in_form', 'child.signin')->nest('update_msg', 'child.alerts', array('msg_type' => 'warning', 'msg' => 'User is not activated.')); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { return View::make('account')->nest('sign_in_form', 'child.signin')->nest('update_msg', 'child.alerts', array('msg_type' => 'warning', 'msg' => 'User is suspended.')); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { return View::make('account')->nest('sign_in_form', 'child.signin')->nest('update_msg', 'child.alerts', array('msg_type' => 'warning', 'msg' => 'User is banned!')); } } else { return View::make('account', ['title' => 'Sign in'])->nest('sign_in_form', 'child.signin'); } } }
public function loginTry() { try { Input::only('email', 'password', 'remember_me'); // Set login credentials $credentials = array('email' => Input::get('email'), 'password' => Input::get('password')); // Try to authenticate the user if (Input::get('remember_me') == true) { $user = Sentry::authenticateAndRemember($credentials); } else { $user = Sentry::authenticate($credentials); } return Redirect::intended('/')->with('global_success', 'You are now logged in.'); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { return Redirect::to('/login')->with('login_error', 'Login field is required.'); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Redirect::to('/login')->with('login_error', 'Password field is required.'); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return Redirect::to('/login')->with('login_error', 'Your username/password combination was incorrect.'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Redirect::to('/login')->with('login_error', 'Your username/password combination was incorrect.'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Redirect::to('/login')->with('login_error', 'You need to activate your account before log in.'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { return Redirect::to('/')->with('global_error', 'Depends on violation, your account has been suspended or banned.'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { return Redirect::to('/')->with('global_error', 'Depends on violation, your account has been suspended or banned.'); } }
public function postLogin() { try { // Login credentials $credentials = array('email' => Input::get('username'), 'password' => Input::get('password')); // Authenticate the user $user = Sentry::authenticate($credentials, false); return Redirect::intended('/'); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { $msg = 'Login field is required.'; } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { $msg = 'Password field is required.'; } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { $msg = 'Wrong password, try again.'; } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { $msg = 'User was not found.'; } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { $msg = 'User is not activated.'; } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { $msg = 'User is suspended.'; } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { $msg = 'User is banned.'; } return Redirect::to('auth/login')->withInput()->with('exception', $msg); }
public function postLogon() { $valid = Validator::make(Input::all(), ['email' => 'required|email', 'password' => 'required'], ['password.required' => trans('larauth::larauth.password_required')]); if ($valid->fails()) { return Redirect::route('larauth.logon')->with('errors', $valid->errors())->with(Input::all()); } try { $user = Sentry::authenticate(['email' => Input::get('email'), 'password' => Input::get('password')], Input::get('remember')); // redirect to url before authetificate return Redirect::intended(); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { echo 'Login field is required.'; } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { echo 'Password field is required.'; } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { //echo 'Wrong password, try again.'; $valid->errors()->add('password', trans('larauth::larauth.wrong_password')); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { echo 'User was not found.'; } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { echo 'User is not activated.'; } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { //echo 'User is suspended.'; $valid->errors()->add('password', trans('larauth::larauth.user_suspended')); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { echo 'User is banned.'; } return Redirect::route('larauth.logon')->with('errors', $valid->errors())->with(Input::all()); }
public function postLogin() { $credentials = array('email' => Input::get('email'), 'password' => Input::get('password')); $rules = array('email' => 'required|min:4|max:254|email', 'password' => 'required|min:6'); $validator = Validator::make($credentials, $rules); if ($validator->passes()) { } $err_code = ""; try { $user = Sentry::authenticate($credentials, false); if ($user) { return Redirect::route('/'); } } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { $err_code = "login_field_is_required"; } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { $err_code = "password_field_is_required"; } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { $err_code = "wrong_password_exception"; } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { $err_code = "user_not_found"; } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { $err_code = "user_is_not_activated"; } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { $err_code = "user_is_suspended"; } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { $err_code = "user_is_banned"; } return Redirect::route('admin.login')->withErrors(array('login' => Lang::get("sentry." . $err_code))); }
/** * Login action * @return Redirect */ public function postLogin($target = 'admin') { $input = Input::all(); $credentials = array('login' => $input['username'], 'password' => $input['password']); $remember = isset($input['remember']) && $input['remember'] == 'checked' ? true : false; try { $user = Sentry::authenticate($credentials, $remember); if ($user) { if (isset($input['api'])) { return Response::json(array(), 200); } else { return Redirect::intended($target); } } } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { if (isset($input['api'])) { return Response::json(array('error' => trans('users.check_activation_email')), 200); } else { return Redirect::back()->withErrors(trans('users.check_activation_email')); } } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { if (isset($input['api'])) { return Response::json(array('error' => trans('users.account_suspended', array('minutes' => 10))), 200); } else { return Redirect::back()->withErrors(trans('users.account_suspended', array('minutes' => 10))); } } catch (Exception $e) { if (isset($input['api'])) { return Response::json(array('error' => trans('users.invalid_username_pw')), 200); } else { return Redirect::back()->withErrors(trans('users.invalid_username_pw')); } } }
public function postLogin() { /* * Validate */ $rules = array('email' => 'required|email', 'password' => 'required'); $validation = \Validator::make(\Input::all(), $rules); if ($validation->passes()) { $email = \Input::get('email'); $password = \Input::get('password'); try { $credentials = array('email' => $email, 'password' => $password); // Authenticate the user $user = \Sentry::authenticate($credentials, false); } catch (\Cartalyst\Sentry\Users\UserNotActivatedException $e) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('invalid', "This user hasn't been activated. Please contact us for support."); return \Redirect::to('admin')->withErrors($errors)->withInput(); } catch (\Exception $e) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('invalid', "Oops, your email or password is incorrect."); return \Redirect::to('admin')->withErrors($errors)->withInput(); } return \Redirect::to('admin'); } return \Redirect::to('admin')->withErrors($validation)->withInput(); }
public function login() { try { $user = Sentry::getUserProvider()->findByLogin(Input::json('email')); $throttle = Sentry::getThrottleProvider()->findByUserId($user->id); $throttle->setSuspensionTime(10); $throttle->setAttemptLimit(3); $throttle->check(); $credentials = ['email' => Input::json('email'), 'password' => Input::json('password')]; $user = Sentry::authenticate($credentials, false); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return Response::json(array('flash' => 'Invalid username or password'), 500); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { return Response::json(array('flash' => 'Login field is required'), 500); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Response::json(array('flash' => 'Password field is required'), 500); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Response::json(array('flash' => 'Invalid username or password'), 500); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Response::json(array('flash' => 'This account is inactive'), 500); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { $time = $throttle->getSuspensionTime(); return Response::json(array('flash' => 'This account is suspended for ' . $time . ' minutes'), 500); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { return Response::json(array('flash' => 'This account has been banned'), 500); } $user_details = User::join('users_groups', 'users.id', '=', 'users_groups.user_id')->join('groups', 'users_groups.group_id', '=', 'groups.id')->where('users.id', '=', $user->id)->select('users.id', 'users.email', 'users.first_name', 'users.last_name', 'groups.name as role', 'users.activated_at', 'users.last_login', 'users.created_at', 'users.updated_at')->get(); return Response::json($user_details[0], 200); }
public function login() { try { $credentials = array('email' => Input::get('email'), 'password' => Input::get('password')); if (Input::get('remember') == 1) { $user = Sentry::authenticateAndRemember($credentials); } else { $user = Sentry::authenticate($credentials); } $url = URL::to('dashboard'); return Response::json(array('success' => 'You have arrived! Hang on and we\'ll redirect you shortly', 'url' => $url)); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { return Response::json(array('message' => 'Login field is required')); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Response::json(array('message' => 'Password field is required.')); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return Response::json(array('message' => 'Wrong password, please try again.')); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Response::json(array('message' => 'User was not found.')); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Response::json(array('message' => 'User is not activated.')); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { return Response::json(array('message' => 'User is suspended.')); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { return Response::json(array('message' => 'User is banned.')); } }
/** * To Authenticate a user * * @usage loginUser("*****@*****.**", "123"); * * @return bool */ public function loginUser($email, $password) { /** * Validation for User Registration */ $validator = Validator::make(array('email' => $email, 'password' => $password), array('email' => array('email', 'required', 'min:5'), 'password' => array('required', 'min:5'))); // Validation did not pass if ($validator->fails()) { throw new Exception($validator->messages()); } // Authenticate try { // Login credentials $credentials = array('email' => $email, 'password' => $password); // Authenticate the user $user = Sentry::authenticate($credentials, true); return $user; } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { echo 'Login field is required.'; } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { echo 'Password field is required.'; } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { echo 'Wrong password, try again.'; } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { echo 'User was not found.'; } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { echo 'User is not activated.'; } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { echo 'User is suspended.'; } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { echo 'User is banned.'; } }
public function login() { if (Sentry::check()) { return Redirect::route('admin.dashboard'); } if (Request::isMethod('post')) { try { $rules = Validator::make(Input::all(), ['username' => 'required', 'password' => 'required']); if ($rules->fails()) { throw new Exception('Todos los campos son obligatorios'); } $usr = Sentry::findGroupByName('Usuario'); $data = ['username' => Input::get('username'), 'password' => Input::get('password')]; $user = Sentry::authenticate($data); if ($user->inGroup($usr)) { throw new Exception('Este usuario no tiene permisos para ingresar al administrador.'); } return Redirect::route('admin.dashboard'); } catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) { return Redirect::route('admin.login')->with('message', 'Usuario o Contaseña inconrrecta.'); } catch (\Cartalyst\Sentry\Throttling\UserSuspendedException $e) { return Redirect::route('admin.login')->with('message', 'Este usuario esta suspendido.'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { return Redirect::route('admin.login')->with('message', 'Este usuario ha sido desactivado, podra ingresar de nuevo en 5min.'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Redirect::route('admin.login')->with('message', 'Este usuario esta inactivo.'); } catch (Exception $e) { Sentry::logout(); return Redirect::route('admin.login')->with('message', $e->getMessage()); } } return View::make('administrator.login', ['title' => 'Iniciar Sesión']); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $this->layout->title = APPNAME; try { if (Input::has('id') && Input::has('password')) { $id = Input::get('id'); $pass = Input::get('password'); } $credentials = array('student_id' => $id, 'password' => $pass); $user = Sentry::authenticate($credentials, false); return Redirect::to('./'); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { echo "<meta http-equiv=\"refresh\" content=\"5\"; />"; $this->layout->content = View::make('login.error')->with('error', "Missing data... Redirecting in 5 seconds."); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { echo "<meta http-equiv=\"refresh\" content=\"5\"; />"; $this->layout->content = View::make('login.error')->with('error', "Missing data... Redirecting in 5 seconds."); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { echo "<meta http-equiv=\"refresh\" content=\"5\"; />"; $this->layout->content = View::make('login.error')->with('error', "Either the information you entered was incorrect or the user does not exist. Redirecting in 5 seconds."); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { echo "<meta http-equiv=\"refresh\" content=\"5\"; />"; $this->layout->content = View::make('login.error')->with('error', "Either the information you entered was incorrect or the user does not exist. Redirecting in 5 seconds."); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { echo "<meta http-equiv=\"refresh\" content=\"5\"; />"; $this->layout->content = View::make('login.error')->with('error', "Either the information you entered was incorrect or the user does not exist. Redirecting in 5 seconds."); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { $this->layout->content = View::make('login.error')->with('error', "User is suspended for too many login attempts. Redirecting in 5 seconds."); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { echo 'User is banned. Redirecting in 5 seconds.'; } }
/** * Logs the user in. * * @return Response */ public function store() { $input = Input::except('_token'); if (!isset($input['remember'])) { $input['remember'] = false; } if (!$this->validator->with($input)->passes()) { return Redirect::back()->withErrors($this->validator->errors())->withInput($input); } try { $credentials = array('username' => $input['username'], 'password' => $input['password']); Sentry::authenticate($credentials, $input['remember']); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { $messages = array('username' => 'Username and password do not match.'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { $messages = array('username' => 'Username and password do not match.'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { $messages = array('username' => 'This user is not activated.'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { $messages = array('username' => 'This user is suspended.'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { $messages = array('username' => 'This user is banned'); } if (!empty($messages)) { return Redirect::back()->withInput()->withErrors($messages); } return Redirect::intended(); }
public function do_login() { try { $credentials = array('email' => Input::get('email'), 'password' => Input::get('password')); if (Input::get('remember') == 1) { $user = Sentry::authenticateAndRemember($credentials); } else { $user = Sentry::authenticate($credentials); } $url = Session::get('originalRequest') ? Session::get('originalRequest') : URL::to('dashboard'); Session::forget('originalRequest'); return Response::json(['success' => 'Login successful. You will now be redirected to the admin dashboard', 'url' => $url]); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { return Response::json(['email' => 'Email is required']); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Response::json(['password' => 'Password is required.']); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return Response::json(['password' => 'Wrong password, please try again.']); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Response::json(['email' => 'User not found.']); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Response::json(['email' => 'User is not activated.']); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { return Response::json(['email' => 'User is suspended.']); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { return Response::json(['email' => 'User is banned.']); } }
/** * Loguea a un usuario a la cuenta del cliente al que pertenece, si los atributos * de autenticaci�n presentan algun error se reenvian al view de login con el error. * * @return Redirect::to */ public function postLogin() { try { // Set login credentials $credentials = array('email' => Input::get('email'), 'password' => Input::get('password')); // Try to authenticate the user $user = Sentry::authenticate($credentials, false); return Redirect::to('productos'); } catch (login $e) { return Redirect::to('admin/login')->with('sys-error', 'Debe llenar todos los campos.')->withInput(); } catch (password $e) { return Redirect::to('admin/login')->with('sys-error', 'Debe llenar todos los campos.')->withInput(); } catch (wrong $e) { return Redirect::to('admin/login')->with('sys-error', 'Clave o Usuario incorrecto, intente de nuevo.')->withInput(); } catch (user $e) { return Redirect::to('admin/login')->with('sys-error', 'Usuario no encontrado en nuestro sistema.')->withInput(); } catch (activated $e) { return Redirect::to('admin/login')->with('sys-error', 'Usuario no esta <b>activado</b>.')->withInput(); } catch (suspended $e) { return Redirect::to('admin/login')->with('sys-error', 'Usuario <b>suspendido</b>.')->withInput(); } catch (banned $e) { return Redirect::to('admin/login')->with('sys-error', 'Usuario <b>suspendido</b> por tiempo indefinido.')->withInput(); } catch (Exception $e) { // Maneja las exceptions que no esten previamente // TODO: crear exception global return Redirect::to('admin/login')->with('sys-error', 'Ups! Algo no salio bien.')->withInput(); } }
public function postLogin() { $data = Input::all(); try { // Login credentials $credentials = array('email' => Input::get('email'), 'password' => Input::get('password')); // Authenticate the user $user = Sentry::authenticate($credentials, Input::get('remember-me')); return Redirect::to('admin')->with('title', 'Administrator'); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { return Redirect::route('get_login')->with('error', 'Login field is required'); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Redirect::route('get_login')->with('error', 'Password field is required'); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return Redirect::route('get_login')->with('error', 'Wrong password, try again'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Redirect::route('get_login')->with('error', 'User was not found'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Redirect::route('get_login')->with('error', 'User is not activated'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { return Redirect::route('get_login')->with('error', 'User is suspended'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { return Redirect::route('get_login')->with('error', 'User is banned'); } }
/** * Handles POST requests from / * * @return redirect */ public function postLogin() { $input = Input::except('_token'); $response['error'] = true; try { $credentials = ['email' => isset($input['email']) ? $input['email'] : '', 'password' => isset($input['password']) ? $input['password'] : '']; $user = Sentry::authenticate($credentials, true); $response['error'] = false; } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { $response['message'] = Lang::get('auth.username'); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { $response['message'] = Lang::get('auth.password'); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { $response['message'] = Lang::get('auth.password'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { $response['message'] = Lang::get('auth.not_found'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { $response['message'] = Lang::get('auth.deactivated'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { $response['message'] = Lang::get('auth.suspended'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { $response['message'] = Lang::get('auth.banned'); } finally { if ($response['error']) { return Redirect::back()->with($response); } return Redirect::to('dashboard'); } }
/** * Account sign in form processing. * * @return Redirect */ public function postSignin() { $this->beforeFilter('csrf', array('on' => 'post')); // Declare the rules for the form validation $rules = array('email' => 'required|email', 'password' => 'required|between:3,32'); // Create a new validator instance from our validation rules $validator = Validator::make(Input::all(), $rules); // If validation fails, we'll exit the operation now. if ($validator->fails()) { // Ooops.. something went wrong return Redirect::route('signin')->withInput()->withErrors($validator); } try { // Try to log the user in $user = Sentry::authenticate(Input::only('email', 'password'), Input::get('remember-me', 0)); // Get the page we were before //$redirect = Session::get('loginRedirect', 'account'); // Unset the page we were before from the session //Session::forget('loginRedirect'); // Redirect to the users page return Redirect::route('signin')->with('success', Lang::get('auth/message.signin.success')); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { $this->messageBag->add('email', Lang::get('auth/message.account_not_found')); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { $this->messageBag->add('email', Lang::get('auth/message.account_not_activated')); } // Ooops.. something went wrong return Redirect::route('signin')->withInput()->withErrors($this->messageBag); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $this->loginForm->validate($input = Input::only('email', 'password')); try { Sentry::authenticate($input, true); } catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) { $mjs = array('success' => false, 'mgs' => trans('main.mgs_invalid_credential'), 'url' => ''); return Response::json($mjs); } catch (\Cartalyst\Sentry\Users\UserNotActivatedException $e) { $mjs = array('success' => false, 'mgs' => trans('main.user_not_activated'), 'url' => ''); return Response::json($mjs); } catch (\Cartalyst\Sentry\Throttling\UserSuspendedException $e) { $mjs = array('success' => false, 'mgs' => trans('main.user_suspended'), 'url' => ''); return Response::json($mjs); } // Logged in successfully - redirect based on type of user $user = Sentry::getUser(); $admin = Sentry::findGroupByName('Admins'); $users = Sentry::findGroupByName('Patients'); $doctors = Sentry::findGroupByName('Doctors'); $company = Sentry::findGroupByName('Clinics'); $recepcion = Sentry::findGroupByName('Receptionist'); if ($user->inGroup($admin)) { $mjs = array('success' => true, 'mgs' => trans('main.mgs_access'), 'url' => url() . '/admin'); return Response::json($mjs); } elseif ($user->inGroup($company) or $user->inGroup($recepcion)) { $mjs = array('success' => true, 'mgs' => trans('main.mgs_access'), 'url' => url() . '/clinic'); return Response::json($mjs); } elseif ($user->inGroup($doctors)) { $mjs = array('success' => true, 'mgs' => trans('main.mgs_access'), 'url' => url() . '/doctor'); return Response::json($mjs); } elseif ($user->inGroup($users)) { return Redirect::to(url()); } }
public function postLogin() { $input = Input::all(); $rules = array('username' => 'required', 'password' => 'required'); $validator = Validator::make($input, $rules); if ($validator->fails()) { return Redirect::to('account/login')->withErrors($validator); } try { // Set login credentials $credentials = array('username' => $input['username'], 'password' => $input['password']); // Try to authenticate the user $user = Sentry::authenticate($credentials, Input::get('remember', false)); Event::fire('user.login', array($user)); $redirect = Session::get('redirect'); if ($redirect) { return Redirect::to($redirect); } else { return Redirect::to('/'); } } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { dd($e); return Redirect::to('account/login')->withErrors(array('Login field is required.')); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Redirect::to('account/login')->withErrors(array('Password field is required.')); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Redirect::to('account/login')->withErrors(array('User was not found.')); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Redirect::to('account/login')->withErrors(array('User is not activated.')); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { return Redirect::to('account/login')->withErrors(array('User is suspended.')); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { return Redirect::to('account/login')->withErrors(array('User is banned.')); } }
/** * Store a newly created resource in storage. * POST /sessions/store. * * @return Response */ public function store() { // Set login credentials $input = array('email' => Input::get('email'), 'password' => Input::get('password')); // Try to authenticate the user try { Sentry::authenticate($input, Input::has('remember')); } catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) { return Redirect::back()->withInput()->withErrorMessage('Invalid credentials provided'); } catch (\Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Redirect::back()->withInput()->withErrorMessage('User Not Activated.'); } // Logged in successfully - redirect based on type of user $user = Sentry::getUser(); $adminsGroup = Sentry::findGroupByName('Admins'); $usersGroup = Sentry::findGroupByName('Users'); if ($user->inGroup($adminsGroup)) { return Redirect::intended('admin'); } elseif ($user->inGroup($usersGroup)) { if (!stripos(Session::get('url.intended', '/'), '/admin')) { return Redirect::intended('/'); } else { return Redirect::to('/'); } } }
public function post_login() { $credentials = array('email' => Input::get('username'), 'password' => Input::get('password')); $remember = Input::has('remember') ? true : false; $rules = array('email' => array('required', 'min:2'), 'password' => array('required', 'min:6')); $messages = array('email.required' => 'È necessario specificare il proprio username e la propria password per accedere', 'email.min' => 'Lo username deve essere lungo almeno 2 caratteri', 'password.required' => 'È necessario specificare il proprio username e la propria password per accedere', 'password.min' => 'La password deve essere lunga almeno 6 caratteri'); $validator = Validator::make($credentials, $rules, $messages); if ($validator->passes()) { try { $user = Sentry::findUserByCredentials($credentials); $groups = Group::all(); if ($user) { foreach ($groups as $group) { if ($user->inGroup($group->name)) { $userAuth = Sentry::authenticate($credentials, $remember); if ($userAuth) { return $this->make_response($credentials, false, array($user->first_name . ' ' . $user->first_last . ', Accesso ' . $group->name . ' consentito'), URL::to('admin/dashboard')); } } } } } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return $this->make_response($credentials, true, array('Non hai inserito la password')); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return $this->make_response($credentials, true, array('Utente non trovato')); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return $this->make_response($credentials, true, array('Password o nome utente non corretti')); } catch (\Exception $e) { return $this->make_response($credentials, true, array("errore non previsto: " . $e->getMessage())); } } else { $errors = $validator->messages; return $this->make_response($credentials, true, $errors); } }
public function postLogin() { $param = Input::all(); try { // Login credentials $credentials = array('email' => $param['email'], 'password' => $param['password']); // Authenticate the user $user = Sentry::authenticate($credentials, false); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { echo 'Login field is required.'; } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { echo 'Password field is required.'; } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { echo 'Wrong password, try again.'; } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { echo 'User was not found.'; } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { echo 'User is not activated.'; } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { echo 'User is suspended.'; } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { echo 'User is banned.'; } return Redirect::to('dashboard'); }
/** * Process Login */ public function doLogin() { $rules = array('email' => 'required|email', 'password' => 'required'); $validator = Validator::make(Input::all(), $rules); //validate the input if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } try { $data = array('email' => Input::get('email'), 'password' => Input::get('password')); $user = Sentry::authenticate($data, false); //check group and redirect to group page return Redirect::route('users.index'); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { return Redirect::route('users.login')->withInput(Input::except('password'))->withErrors("Login required"); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Redirect::route('users.login')->withInput(Input::except('password'))->withErrors("Password required"); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return Redirect::route('users.login')->withInput(Input::except('password'))->withErrors("Wrong Password"); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Redirect::route('users.login')->withInput(Input::except('password'))->withErrors("Email not found"); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Redirect::route('users.login')->withInput(Input::except('password'))->withErrors("Not activated"); } }
public function postIndex() { try { $credentials = array('email' => strtolower(Input::get('email')), 'password' => Input::get('password')); if (Input::has('mantener')) { Sentry::authenticateAndRemember($credentials); } else { Sentry::authenticate($credentials, false); } } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { return Redirect::back()->withInput()->withErrors('El usuario es requerido.'); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Redirect::back()->withInput()->withErrors('La contraseña es obligatoria.'); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return Redirect::back()->withInput()->withErrors('Contraseña incorrecta, intente nuevamente.'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Redirect::back()->withInput()->withErrors('Este usuario no existe.'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Redirect::back()->withInput()->withErrors('Este usuario no esta activado.'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { return Redirect::back()->withInput()->withErrors('Este usuario se encuentra suspendido.'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { return Redirect::back()->withInput()->withErrors('Este usuario esta bloqueado.'); } return Redirect::intended(''); }