[Catalyst] Need help inserting
Theodore Katseres
tedkat at gmail.com
Wed May 30 20:26:48 GMT 2012
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 =3D $c->model('authdb::User')->create({ username =3D> $username });
$user->create_related('user_roles', {role=3D>'1'});
On Wed, May 30, 2012 at 3:09 PM, Kenneth S Mclane <ksmclane at us.ibm.com>wrot=
e:
> 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 a=
dd
> 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 =3D> $username,
> password =3D> $password, } )) {
> # If successful, check the user table to see if they are there
> already
> if (! $c->model('authdb::User')->search( {
> 'username' =3D> $username }, {})) {
> # If not add the user to the user table
> and the default role to the UserRole table
> $c->model('authdb::User')->create({
> username =3D> $username });
>
> $c->model('authid::User')->create_related('user_roles', {
> user =3D> 'user.id',
> role =3D> '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 =3D> "Bad username or password.");
> };
> } else {
> # Set an error message
> $c->stash(error_msg =3D> "Empty username or password.")
> unless ($c->user_exists);
> }
>
> # If either of above don't work out, send to the login page
> $c->stash(template =3D> '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 at 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
||=3DO=3D||
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20120530/efc69=
e3a/attachment.htm
More information about the Catalyst
mailing list