I'm not an expert but your check for existing user in the database should be ->find; ->search will return a resultset unless there is an exception.
Also, you may want this instead. my $user = $c->model('authdb::User')->create({ username => $username }); $user->create_related('user_roles', {role=>'1'}); On Wed, May 30, 2012 at 3:09 PM, Kenneth S Mclane <ksmcl...@us.ibm.com>wrote: > 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. > _______________________________________________ > List: Catalyst@lists.scsys.co.uk > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > Searchable archive: > http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ > Dev site: http://dev.catalyst.perl.org/ > > -- Ted Katseres ||=O=||
_______________________________________________ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/