<font size=2 face="sans-serif">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:</font>
<br>
<br><font size=2 face="sans-serif">if ($username && $password)
{</font>
<br><font size=2 face="sans-serif"> #
Attempt to log the user in</font>
<br><font size=2 face="sans-serif"> if ($c->authenticate({
username => $username,</font>
<br><font size=2 face="sans-serif">
password
=> $password, } )) {</font>
<br><font size=2 face="sans-serif">
# If successful, check the user table to see if they are there already</font>
<br><font size=2 face="sans-serif">
if (!
$c->model('authdb::User')->search( { 'username' => $username },
{})) { </font>
<br><font size=2 face="sans-serif">
# If not add the user to the user table and
the default role to the UserRole table</font>
<br><font size=2 face="sans-serif">
$c->model('authdb::User')->create({
username => $username });</font>
<br><font size=2 face="sans-serif">
$c->model('authid::User')->create_related('user_roles',
{</font>
<br><font size=2 face="sans-serif">
user =>
'user.id',</font>
<br><font size=2 face="sans-serif">
role =>
'1',</font>
<br><font size=2 face="sans-serif">
});</font>
<br><font size=2 face="sans-serif">
}</font>
<br><font size=2 face="sans-serif">
# Then
send them to the home page</font>
<br><font size=2 face="sans-serif">
$c->response->redirect($c->uri_for($c->controller('Search')->action_for('search')));</font>
<br><font size=2 face="sans-serif">
return;</font>
<br><font size=2 face="sans-serif">
} else {</font>
<br><font size=2 face="sans-serif">
# Set an error message</font>
<br><font size=2 face="sans-serif">
$c->stash(error_msg => "Bad username or password.");</font>
<br><font size=2 face="sans-serif">
};</font>
<br><font size=2 face="sans-serif"> } else {</font>
<br><font size=2 face="sans-serif"> # Set an
error message</font>
<br><font size=2 face="sans-serif"> $c->stash(error_msg
=> "Empty username or password.")</font>
<br><font size=2 face="sans-serif"> unless ($c->user_exists);</font>
<br><font size=2 face="sans-serif"> }</font>
<br><font size=2 face="sans-serif"> </font>
<br><font size=2 face="sans-serif"> #
If either of above don't work out, send to the login page</font>
<br><font size=2 face="sans-serif"> $c->stash(template
=> 'login.tt2'); </font>
<br><font size=2 face="sans-serif">} </font>
<br>
<br><font size=2 face="sans-serif">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.<br>
</font>
<br><font size=2 face="sans-serif">I know I'm getting closer, but I would
appreciate some pointers to where I'm off here.</font>