[Catalyst] Need help inserting

Kenneth S Mclane ksmclane at us.ibm.com
Wed May 30 20:09:32 GMT 2012


I have my authentication working through the company LDAP server. I am 
attempting to check for the existence of the user in a sqlite table and 
add them and their role if they are not found. I do this during the login:

if ($username && $password) {
        # Attempt to log the user in
        if ($c->authenticate({ username => $username,
                               password => $password,  } )) {
            # If successful, check the user table to see if they are there 
already
                        if (! $c->model('authdb::User')->search( { 
'username' => $username }, {})) { 
                                # If not add the user to the user table 
and the default role to the UserRole table
                                $c->model('authdb::User')->create({ 
username => $username });
 $c->model('authid::User')->create_related('user_roles', {
                                        user => 'user.id',
                                        role => '1',
                                });
                        }
                        # Then send them to the home page
 
$c->response->redirect($c->uri_for($c->controller('Search')->action_for('search')));
            return;
                } else {
            # Set an error message
            $c->stash(error_msg => "Bad username or password.");
                };
    } else {
        # Set an error message
        $c->stash(error_msg => "Empty username or password.")
        unless ($c->user_exists);
    }
 
        # If either of above don't work out, send to the login page
        $c->stash(template => 'login.tt2'); 
} 

I have a couple of things I'm having trouble with, the user doesn't get 
created, I'm not sure I'm doing this correctly. Plus I had a co-worker log 
into the app on my computer and it picked up the session ID from  the 
cookie. So I obviously need to do something about that, although normally 
anyone else would be logging in from a different system, right now it's in 
a vm on my computer.

I know I'm getting closer, but I would appreciate some pointers to where 
I'm off here.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20120530/5f875385/attachment.htm


More information about the Catalyst mailing list