I have a login function like this . i'm using two way to login 1st is submit and 2nd time i'm trying ajax . if (!empty($login)) { this condition is working with ajax .Auth::attempt is returing true and also saving session but when i refresh it again ask to sign in . but submit form option is working . laravel 4.4
public function login($login = '') {
if (!empty($login)) {
$email = $login['email'];
$password = $login['password'];
ob_start();
if (Auth::attempt(array('email' => $email, 'password' => $password, 'status' => 1), true)) {
print_r(Session::all());
die;
$resp['message'] = 'Login Successful!';
echo json_encode($resp);
exit();
} else {
$resp['message'] = 'Invalid account/login credentials';
echo json_encode($resp);
exit();
}
ob_end_clean(); // the buffer and never prints or returns anything.
} else {
$validator = Validator::make(
Input::all(), array(
'Username' => 'required|exists:tblusers,email',
'Password' => 'required'
), array(
'required' => 'This field is required.',
'exists' => 'Email not found in our database',
)
);
if ($validator->fails()) {
$resp['messages'] = Helper::errors($validator->messages());
return Redirect::to(URL::previous() . "#modalSignIn")->withErrors(['Invalid account/login credentials, please make sure you are using correct credentials or you\'re email is verfied.']);
} else {
$email = Input::get('Username');
$password = Input::get('Password');
if (Auth::attempt(array('email' => $email, 'password' => $password, 'status' => 1), true)) {
if (isset($_POST['designs'])) {
// return redirect()->action('DesignsController@index');
return Redirect::to("designs");
}
print_r(Session::all());
die;
return Redirect::back()->with('login_success_message', 'Login Successful!');
} else {
return Redirect::to(URL::previous() . "#modalSignIn")->withErrors(['Invalid account/login credentials, please make sure you are using correct credentials or you\'re email is verfied.']);
}
}
}
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Mrf2Lp
via IFTTT
Aucun commentaire:
Enregistrer un commentaire