本文整理汇总了PHP中Sentry::authenticate方法的典型用法代码示例。如果您正苦于以下问题:PHP Sentry::authenticate方法的具体用法?PHP Sentry::authenticate怎么用?PHP Sentry::authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sentry
的用法示例。
在下文中一共展示了Sentry::authenticate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticateUser
/**
* 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');
}
}
示例2: login
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' => '登录成功'));
}
示例3: login_post
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;
}
示例4: postLogin
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()));
}*/
}
示例5: user_login
/**
* 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);
}
示例6: getIndex
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');
}
}
}
示例7: loginTry
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.');
}
}
示例8: postLogin
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);
}
示例9: postLogon
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());
}
示例10: postLogin
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)));
}
示例11: postLogin
/**
* 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'));
}
}
}
示例12: postLogin
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();
}
示例13: login
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);
}
示例14: login
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.'));
}
}
示例15: loginUser
/**
* To Authenticate a user
*
* @usage loginUser("rain@walker.com", "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.';
}
}