Thanks n0xie, I just pushed your code.
And also thanks Bernd, pushing your fix now.
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
February 10, 2010 7:00pm
Subscribe [287]#151 / Apr 10, 2010 6:02pm
Thanks n0xie, I just pushed your code.
And also thanks Bernd, pushing your fix now.
#152 / Apr 11, 2010 7:17pm
Hallo, first of all, thx for a very nice library !
But there was one thing i just got me wandering.
I got this site im making, and i would like to make it so ppl are able to login on every page, therefore ive made a loginbox in my left side. but then i also would like that ppl get redirected back to the page they came from, either with an error message or with an success message. the thing is, that i don’t know how to get the error messages to come on the page they logged in, in a smart way. I tried to have the $this->data[‘message’] set with either the validation_errors or the flash_data set in the constructor but that didn’t seem to work out.
So, hopefully someone can help me out here with this problem 😊.. before i knew of the auth lib i used to use form_validation callback_ functions do to the check against the database so all my errors was in the validation_errors.
Hope you got some ideers :p
#153 / Apr 11, 2010 9:12pm
InsiteFX
#154 / Apr 12, 2010 2:37am
Schumacher,
If you’re still having issues let me know. You should be able to just use session flashdata to store the errors/messages.
#155 / Apr 12, 2010 8:53am
Yes i know about the flash data .
But the issue is that i want to have every controller to be able to handle these. Because the user can be redirect back to that page(with another controller) from the auth controller.
so in the example you’ve made with it, to have an else on the from_validation->run which sends back the login page. But here i want to have the that it redirects the user back to the page he was on before. So that he stays on the same site during the login atempts.
ive tried to have a hidden post comming along in the form with the url and then i redirect the person back to that page via the value of the hidden.
hopefully it makes sense.
#156 / Apr 12, 2010 9:09am
You could do the login via Ajax: that way the user never leaves the current page, saving you a lot of hassle, trying to implement some kind of ‘redirect back to current page’ logic.
#157 / Apr 12, 2010 9:37am
n0xie that is a great ideer, but the issue is that i dont know ajax that well. Ive tried to learn some Jquery, but to mix it with the php.. that dosn’t seem clear to me, how to do it.
#158 / Apr 12, 2010 10:23am
Schumacher,
This jQuery code should get you started:
var email = $('#loginForm input[name|=email]').val();
var password = $('#loginForm input[name|=password]').val();
$.post('auth/login', {email: email, password: password}, function(data) {
obj = $.parseJSON(data);
});You would then create a JSON response from auth/login and process it with JS.
#159 / Apr 12, 2010 10:59am
any place its good to get this to know? ive seen some jquery tuts about it, but not gone further down into it. 😊?
#160 / Apr 12, 2010 11:01am
Schumacher,
I usually learn something new best by reading a couple of tutorials and then just jumping into the API docs and trying things out.
Everyone learns differently though.
#161 / Apr 12, 2010 3:58pm
Hi all, just getting started with CI and enjoying it (been years since i’ve done web stuff ).
I have been tasked with creating a simple web based employee management system for the HR department, and people need to be logged in at all times to view information. Ion_Auth seems to fit that need well.
Where would be the best place to put a kind of ‘global’ logged_in() check?
Is my understanding correct that extending the Controller with MY_Controller will provide that check every time any controller is called with something like this?
<?php
class MY_Controller extends Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('ion_auth');
$this->load->library('session');
if (!$this->ion_auth->logged_in()) {
//redirect them to the login page
redirect('auth/login', 'refresh');
}
}
}Thanks in advance,
Kyle.
#162 / Apr 12, 2010 4:03pm
Kyle,
That is the correct way to do it.
Good job man, hope you continue to enjoy working with CI and Ion Auth.
#163 / Apr 12, 2010 7:36pm
Thanks for the quick reply Ben, great community here from what i’ve seen 😊
One other quick question for you, how can I use Ion to display User ID and first/last name.
(Sorry if this is a simple one, still getting up to speed on php and CI)
Thanks,
Kyle
#164 / Apr 12, 2010 8:02pm
Kyle,
You can just do
$user = $this->ion_auth->get_user();To get the user object and then you can access the properties like so
echo $user->id .' - '. $user->first_name .' '. $user->last_name;and of course you can pass the $user object to your view and echo the properties there.
#165 / Apr 12, 2010 8:05pm
thanks Ben. much appreciated.