本文整理汇总了PHP中App\Http\Controllers\Auth::attempt方法的典型用法代码示例。如果您正苦于以下问题:PHP Auth::attempt方法的具体用法?PHP Auth::attempt怎么用?PHP Auth::attempt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Http\Controllers\Auth
的用法示例。
在下文中一共展示了Auth::attempt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postLogin
/**
* 动作:登录
*
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function postLogin(Request $request)
{
if (Auth::attempt(['username' => $request->input('username'), 'password' => $request->input('password')])) {
return redirect()->back();
}
return redirect()->intended('auth/login');
}
示例2: facebook
public function facebook()
{
$fb = new Facebook\Facebook(['app_id' => '144053429274589', 'app_secret' => '4ef6916e238aff3b6726dac08b853135', 'default_graph_version' => 'v2.4', 'default_access_token' => 'CAACDBA17B90BAKI0aOXR1vF5zDtZCOKPbWSXopnvvNpBTHZARXVhUVrZBAXn4CB1ZBgsyk13ZA38uZAWoffwchukfajiIOG7cYrNEEAm0CdlHgwDRWeBuD0OZCfT6PB6U2vsE3O45jTgx0YTc24TXEqyZC1ZBIjc9GxD3aSv6WAyIWsZCpAcbnxYPNCdL389FxaRsZD']);
try {
$response = $fb->get('/me?fields=id,name,email');
} catch (Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$me = $response->getGraphUser();
$name = $me['name'];
$email = $me['email'];
$u_name = preg_replace('/@.*$/', '', $me['email']);
$user = new User();
$user->name = $name;
$user->type = 'general';
$user->register_type = 'facebook';
$user->username = $u_name;
$user->email = $email;
$user->password = bcrypt($u_name);
$user->save();
$lastInsertedId = $user->id;
$profile = new Profile();
$profile = $user->profile()->save($profile);
$credentials = array('email' => $email, 'password' => $u_name);
if (Auth::attempt($credentials)) {
//return Redirect::to('home');
return redirect()->intended('home');
}
//echo '<pre>'; print_r($new_name);
//echo 'Logged in as ' . $me['email'];
}
示例3: doLogin
public function doLogin()
{
// validate the info, create rules for the inputs
$rules = array('email' => 'required|email', 'password' => 'required|alphaNum|min:3');
// run the validation rules on the inputs from the form
$validator = Validator::make(Input::all(), $rules);
// if the validator fails, redirect back to the form
if ($validator->fails()) {
return Redirect::to('login')->withErrors($validator)->withInput(Input::except('password'));
// send back the input (not the password) so that we can repopulate the form
} else {
// create our user data for the authentication
$userdata = array('email' => Input::get('email'), 'password' => Input::get('password'));
// attempt to do the login
if (Auth::attempt($userdata)) {
// validation successful!
// redirect them to the secure section or whatever
// return Redirect::to('secure');
// for now we'll just echo success (even though echoing in a controller is bad)
echo 'SUCCESS!';
} else {
// validation not successful, send back to form
return Redirect::to('login');
}
}
}
示例4: login
public static function login()
{
$ajaxRequest = \Request::ajax() && \Request::get('getIgnore_isAjax') ? true : false;
if (!empty($_POST) && $ajaxRequest) {
try {
$email = \Request::get('email');
$password = \Request::get('password');
if (\Auth::attempt(array('email' => $email, 'password' => $password))) {
$allowedUserRoles = config('gtcms.allowedUserRoles');
$user = \Auth::user();
$userRole = $user->role;
if (in_array($userRole, $allowedUserRoles)) {
$defaultModel = self::getDefaultModelForUser($user);
if ($defaultModel) {
return \Redirect::to("/admin/" . $defaultModel . "?getIgnore_loginRedirect=true&getIgnore_isAjax=true");
}
} else {
\Auth::logout();
}
}
$data = array('success' => false, 'message' => trans('gtcms.incorrectUsernameOrPassword'));
return \Response::json($data);
} catch (\Exception $e) {
return AdminHelper::handleException($e, trans('gtcms.errorHasOccurred') . ". " . trans('gtcms.pleaseRefresh') . ".");
}
}
return \View::make('gtcms.admin.templates.adminLogin')->with(array('active' => false));
}
示例5: postLogin
public function postLogin(Request $request)
{
if (\Auth::attempt(['email' => $input('email'), 'password' => $input('password')])) {
return Redirect::to('dadsadash');
} else {
return Redirect::to('/user/login')->withErrors();
}
}
示例6: login
/**
* Login
*
* @param Request $request
* @return Response
*/
public function login(Request $request)
{
if (\Auth::attempt(array('email' => $request->email, 'password' => $request->password))) {
return redirect()->intended('/profile');
} else {
return \Redirect::back();
}
}
示例7: authenticate
/**
* Authenticate user
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function authenticate(Request $request)
{
$this->validate($request, ['email' => 'required|email|max:255', 'password' => 'required|max:255']);
if (\Auth::attempt($request->only(['email', 'password'], $request->get('remember')))) {
return redirect('/');
}
return redirect('/login')->withInput($request->only('login'))->withErrors(['error' => 'The credentials you entered did not match our records. Try again?']);
}
示例8: login
public function login()
{
if (\Auth::attempt(['email' => Input::get('email'), 'password' => Input::get('password')])) {
return Response::json(\Auth::user());
} else {
return Response::json(['msg' => 'Invalid credentials!'], 500);
}
}
示例9: login
public function login()
{
$credentials = ['username' => \Input::get('username'), 'password' => \Input::get('password')];
if (\Auth::attempt($credentials)) {
return \Redirect::action('BackendController@index');
}
return \Redirect::action('LoginController@index')->with('error', 'Failed to login, invalid credentials.');
}
示例10: index
public function index(Request $request)
{
if (!\Auth::attempt($request->input())) {
return response()->json(['status' => 'failed'], 200);
} else {
return response()->json(['status' => 'succeed', 'token' => csrf_token()], 200);
}
}
示例11: loginPost
/**
* Login a user
*
* @return \Illuminate\Http\Response
*/
public function loginPost(Request $request)
{
$user = \Auth::attempt($request->only('username', 'password'));
if (!$user) {
return redirect('auth/login')->with('error', 'Incorrect Username/Password combination');
}
return redirect('/');
}
示例12: signin
public function signin(Requests\UserLoginRequest $request)
{
if (\Auth::attempt(['email' => $request->get('email'), 'password' => $request->get('password'), 'is_confirmed' => 1])) {
return redirect('/');
}
\Session::falsh('user_login_failed', '密码不正确或邮箱没验证');
return redirect('user/login')->withInput();
}
示例13: postLogin
public function postLogin(Request $request)
{
if (\Auth::attempt(['email' => $request->input('email'), 'password' => $request->input('password'), 'verified' => true])) {
session()->flash('message', 'logged In');
return redirect()->intendent('/');
}
session()->flash('message', 'Try Out');
return redirect()->back();
}
示例14: postIndex
public function postIndex()
{
$username = Input::get('username');
$password = Input::get('password');
if (Auth::attempt(['username' => $username, 'password' => $password])) {
return Redirect::intended('/user');
}
return Redirect::back()->withInput()->withErrors('That username/password combo does not exists');
}
示例15: authenticate
public function authenticate()
{
$data = \Input::all();
if (\Auth::attempt(['nick' => $data['login'], 'password' => $data['password']], true)) {
return \Redirect::back();
} else {
return \Redirect::back();
}
}