本文整理汇总了PHP中Auth::attempt方法的典型用法代码示例。如果您正苦于以下问题:PHP Auth::attempt方法的具体用法?PHP Auth::attempt怎么用?PHP Auth::attempt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Auth
的用法示例。
在下文中一共展示了Auth::attempt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created session in storage.
* POST /session
*
* @return Response
*/
public function store()
{
// Attempt to login
try {
// Login credentials
$credentials = array('email' => Input::get('email'), 'password' => Input::get('password'));
// Authenticate the user
if (Auth::attempt($credentials)) {
// Store Session values for user
Session::put('email', $credentials['email']);
Session::put('user_id', User::getIdFromEmail($credentials['email']));
// Redirect to dashboard with message
Session::flash('alert_success', 'Logged in successfully.');
return Redirect::intended('dashboard');
} else {
Session::flash('alert_warning', 'Unable to login. Please check your username and password, and try again.');
return Redirect::to(secure_url('/login'))->withInput();
}
} catch (\RuntimeException $e) {
// An unexpected error occurred.
Log::error(date("Y-m-d H:i:s") . '- RuntimeException in app/contorllers/SessionController: ' . '\\$data = ' . print_r($data) . $e);
Session::flash('alert_danger', 'An unexpected error occurred.');
return Redirect::to(secure_url('/login'))->withInput();
}
}
示例2: 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');
}
}
}
示例3: store
/**
* Store a newly created user in storage.
*
* @return Response
*/
public function store()
{
// create the validator
$validator = Validator::make(Input::all(), User::$rules);
// attempt validation
if ($validator->fails()) {
// validation failed, redirect to the index page with validation errors and old inputs
return Redirect::back()->withInput()->withErrors($validator);
} else {
// validation succeeded, create and save the user
$user = new User();
$user->first_name = Input::get('first_name');
$user->last_name = Input::get('last_name');
$user->username = Input::get('username');
$user->email = Input::get('email');
$user->password = Input::get('password');
$result = $user->save();
if ($result) {
Session::flash('successMessage', $user->first_name . ' Thank you for signing up at Park It');
Auth::attempt(array('email' => $user->email, 'password' => Input::get('password')));
return Redirect::action('HomeController@showIndex');
} else {
Session::flash('errorMessage', 'Please properly input all the required fields');
Log::warning('Post failed to save: ', Input::all());
return Redirect::back()->withInput();
}
}
}
示例4: againcrazy
function againcrazy()
{
$DEFusername = 'guest';
$DEFpassword = 'password';
$username = '';
$password = '';
Auth::attempt($username, $password);
if (Input::has('username') && Input::has('password')) {
var_dump($test);
$username = Input::get('username');
$password = Input::get('password');
if (Auth::attempt($username, $password)) {
header('Location: http://codeup.dev/authorized.php');
exit;
} else {
if (Input::get('username') == '' && Input::get('password') == '') {
echo "please enter a username and password";
} else {
echo "that is not the correct username or password";
}
}
}
// if (isset($_SESSION['logged_in_user']) && $_SESSION['logged_in_user']) {
// header('Location: http://codeup.dev/authorized.php');
// exit;
// }
$passme = ['password' => $password, 'username' => $username];
return $passme;
}
示例5: dologin
public function dologin()
{
$rules = array('username' => 'required', 'password' => 'required');
$message = array('required' => 'Data :attribute harus diisi', 'min' => 'Data :attribute minimal diisi :min karakter');
$validator = Validator::make(Input::all(), $rules, $message);
if ($validator->fails()) {
return Redirect::to('/')->withErrors($validator)->withInput(Input::except('password'));
} else {
$data = array('username' => Input::get('username'), 'password' => Input::get('password'));
if (Auth::attempt($data)) {
$data = DB::table('user')->select('user_id', 'level_user', 'username')->where('username', '=', Input::get('username'))->first();
//print_r($data);
//echo $data->id_users;
Session::put('user_id', $data->user_id);
Session::put('level', $data->level_user);
Session::put('username', $data->username);
//print_r(Session::all());
return Redirect::to("/admin/beranda");
} else {
Session::flash('messages', '
<div class="alert alert-danger alert-dismissable" >
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<strong>Peringatan...</strong><br>
Username dan password belum terdaftar pada sistem !
</div>
');
return Redirect::to('/')->withInput(Input::except('password'));
}
}
}
示例6: login
/**
* Log in to site.
*
* @return Response
*/
public function login()
{
if (Auth::attempt(array('email' => Input::get('email'), 'password' => Input::get('password')), true) || Auth::attempt(array('username' => Input::get('email'), 'password' => Input::get('password')), true)) {
return Redirect::intended('dashboard');
}
return Redirect::back()->withInput(Input::except('password'))->with('message', 'Wrong creadentials!');
}
示例7: doLogin
public function doLogin()
{
$rules = array('email' => 'required', 'password' => 'required');
$allInput = Input::all();
$validation = Validator::make($allInput, $rules);
//dd($allInput);
if ($validation->fails()) {
return Redirect::route('login')->withInput()->withErrors($validation);
} else {
$credentials = array('email' => Input::get('email'), 'password' => Input::get('password'));
if (Auth::attempt($credentials)) {
if (Auth::user()->access_level == '1') {
return Redirect::intended('dashboard');
} elseif (Auth::user()->access_level == '2') {
return Redirect::intended('doc_dashboard');
} elseif (Auth::user()->access_level == '4') {
return Redirect::intended('patient_dashboard');
} else {
return Redirect::intended('nurse_dashboard');
}
} else {
return Redirect::route('login')->withInput()->withErrors('Error in Email Address or Password.');
}
}
}
示例8: authenticate
/**
* Handle authentication attempts
*
* @return Response
*/
public function authenticate()
{
if (Auth::attempt(['username' => $username, 'password' => $password])) {
// Authentication was successful
return response('Authentication successful', 200);
}
}
示例9: login
/**
*
* @return nothing
* @author Tremor
*/
public function login()
{
if (Request::isMethod('post')) {
$post = Input::all();
$rules = ['email' => 'required|email', 'password' => 'required'];
$validator = Validator::make($post, $rules);
if ($validator->fails()) {
$this->setMessage($validator->messages()->all(), 'error');
return Redirect::route('login')->withInput();
} else {
$email = trim(Input::get('email'));
$password = trim(Input::get('password'));
$remember = Input::get('remember') == 1 ? true : false;
if (Auth::attempt(array('email' => $email, 'password' => $password, 'is_admin' => 1))) {
return Redirect::route('admin');
} elseif (Auth::attempt(array('email' => $email, 'password' => $password))) {
return Redirect::route('home');
} else {
$this->setMessage('failed login', 'error');
return Redirect::route('login')->withInput();
}
}
}
return View::make('auth.signin')->with($this->data);
}
示例10: processLogin
public function processLogin()
{
$validator = Validator::make(array('email' => Input::get('email'), 'password' => Input::get('password')), array('email' => 'required', 'password' => 'required'));
$email = Input::get('email');
$password = Input::get('password');
if ($validator->fails()) {
$errors = $validator->messages()->all();
return Redirect::back()->with('flash_errors', $errors);
} else {
if (Auth::attempt(array('email' => $email, 'password' => $password))) {
$user = Auth::user();
if ($user->role_id == 2) {
return Redirect::route('adminDashboard');
} elseif ($user->role_id == 1) {
if ($user->is_activated == 1) {
return Redirect::route('moderateDashboard');
} else {
return Redirect::back()->with('flash_error', "Please activate your account, Check your mail or contact admin");
}
} elseif ($user->role_id == 3) {
if ($user->is_activated == 1) {
return Redirect::route('contributorDashboard');
} else {
return Redirect::back()->with('flash_error', "Please activate your account, Check your mail or contact admin");
}
} else {
return Redirect::back()->with('flash_error', "something went wrong");
}
} else {
return Redirect::back()->with('flash_error', "Invalid Email and Password");
}
}
}
示例11: doRegister
public function doRegister()
{
$username = Input::get('username');
$password = Input::get('password');
$password = Hash::make($password);
if ($username != "" && $password != "") {
$users = User::all();
$usernames = array();
foreach ($users as $user) {
$usernames[] = $user->username;
}
if (!in_array($username, $usernames)) {
$user = new User();
$user->username = $username;
$user->password = $password;
$user->save();
$userdata = array('username' => Input::get('username'), 'password' => Input::get('password'));
if (Auth::attempt($userdata)) {
$user = Auth::user();
return Response::json(array('error' => false, 'userdata' => $user), 200);
} else {
return Response::json(array('error' => true, 'reason' => 'login failed'), 200);
}
} else {
return Response::json(array('error' => true, 'reason' => 'username not unique'), 200);
}
} else {
return Response::json(array('error' => true, 'reason' => 'username or password is empty'), 200);
}
}
示例12: login
public function login()
{
/* $user = array(
'name' => Input::get('name'),
'surname' => Input::get('surname'),
'mail' => Input::get('mail'),
'username' => Input::get('username'),
'password' => Input::get('password'),
're-password' => Input::get('re-password')
);*/
$gelen = Input::all();
// Kurallar
$rules = array('mail' => 'required|min:8|max:60', 'password' => 'required|min:8|max:20');
// Hata mesajları
$messages = array('mail.required' => 'Email Boş Geçmeyiniz..', 'mail.max' => 'Mail adresiniz azami :max Karakter Olmalıdır.', 'email.min' => 'Mail adresiniz asgari :min Karakter Olmalıdır.', 'password.required' => 'Lütfen Şifre Giriniz.', 'password.max' => 'Şifreniz en fazla :min karakterli olmalıdır.', 'password.min' => 'Şifreniz en az :max karakterli olmalıdır.');
// Validation
$validate = Validator::make($gelen, $rules, $messages);
if ($validate->fails()) {
return View::make('login.login')->withErrors($validate);
} else {
if (Auth::attempt(array('user_mail' => Input::get('mail'), 'password' => Input::get('password')))) {
}
if (Auth::check()) {
return Redirect::to('/');
} else {
return View::make('login.login')->with('hata', 'E-mail Veya Şifre Yanlış');
}
}
}
示例13: login
public function login(Request $data)
{
if ($data->isMethod('post')) {
$email = $data->input('email');
$password = $data->input('password');
$result['message'] = NULL;
if ($email) {
$obj = new User();
$checkIfEmailExists = $obj->getUserWhere($email, $password);
if ($checkIfEmailExists['status'] !== 200) {
$result['message'] = $checkIfEmailExists['message'];
return view('Auth.login', ['result' => $result]);
} else {
if (Auth::attempt(['email' => $email, 'password' => $password])) {
Session::put('email', $email);
return redirect()->intended('view');
} else {
$result['message'] = 'Password Incorrect';
return view('Auth.login', ['result' => $result]);
}
}
} else {
return view('auth.login', ['result' => $result]);
}
}
}
示例14: store
public function store()
{
$rules = array('name' => 'required|max:200', 'email' => 'required|email|unique:users|max:200|', 'password' => 'required|min:8|max:200');
$messages = array('email.unique' => "You have already registered with this email address. Sign in <a href=\"/login\">here</a>");
$input = Input::all();
$validator = Validator::make($input, $rules, $messages);
if ($validator->fails()) {
return Redirect::to('signup')->withInput()->withErrors($validator);
} else {
$password = Hash::make($input['password']);
//Validation passed -- Make a new user in the DB
$user = new User();
$user->name = $input['name'];
$user->password = $password;
$user->email = $input['email'];
$user->isActive = 1;
$user->save();
//Here we will send an email with the link to confirm .... https://github.com/Zizaco/confide
//We'll send the user an email thanking them for registering
$attempt = Auth::attempt(array('email' => $input['email'], 'password' => $input['password']));
if ($attempt) {
return Redirect::to('dashboard')->with('flash_message_good', 'Welcome to Open Source Collaborative Consumption Marketplace. You have been successfully signed up and logged in!');
} else {
Log::error('Trying to log user in straight after register failed. User redirected to login page');
return Redirect::to('login')->with('flash_message_good', "Your signup has been successfull, go ahead and log in here!");
}
}
}
示例15: userCheck
function userCheck($username, $password)
{
$log = new Log("log");
$array = fileOpen();
print_r($array);
$true = false;
$_SESSION['is-logged-in'] = $true;
for ($i = 0; $i < count($array); $i++) {
if (Auth::attempt($username, $password, $array[$i]["password"])) {
$true = true;
$log->logMessage("SWEET", "That password for {$username} was correct!, Logging {$username} in!");
$sessionuname = $array[$i]["username"];
$_SESSION["username"] = $sessionuname;
break;
} else {
$true = false;
$log->logMessage("HEY!", "That password for {$username} was incorrect!");
$sessionuname = "Guest";
$_SESSION["username"] = $sessionuname;
}
}
if ($true == true) {
return "You did it {$sessionuname}!";
} else {
return "You didn't say the magic word!";
}
}