[Catalyst] How to use and maintain sessions in catalyst...please check out my code...

Vidya Sagar vsagarkola at gmail.com
Wed Jan 4 08:03:05 CET 2006


Hi all,


This is how i have set seessions to usrid and password.....

        $c->session->{youser} = $c->req->params->{usrid};
        $c->session->{youpass} = $c->req->params->{password};
        my ($uusr) = TMS::Model::Emp->search({ usrid =>
$c->session->{youser}, password => $c->session->{youpass} });
                if ($uusr){
                         $c->session->{gole}= $uusr->role;
                }

I didnt maintain any roles table....I have just 3 columns in my
emp........1.usrid 2.password 3.role(admin,user)
And this is how i m retrieving session and using it for further
programming.......


sub add :  Local {
        my ( $self, $c ) = @_;
        unless($c->gole(qw/admin/))  {
                $c->stash->{template} = 'restrict.tt';
                return;
        }
        $c->stash->{template} = 'add.tt';

        if($c->req->params->{submit}) {
                my $nuser = $c->req->params->{nusrid};
                my $psw = $c->req->params->{npassword};
                my $role = $c->req->params->{nrole};
                if (($nuser eq '') || ($psw eq '') || ($role eq '')) {
                        $c->stash->{template} = 'edit1.tt';
                        $c->stash->{error} = 1;
                }
                else {
                        print $nuser;
                        my ($cd) = TMS::Model::Emp->create({usrid => $nuser,
password => $psw, role => $role});
                        $c->stash->{template} = 'useradded.tt';
                }

                if($@) {
                        $c->stash->{error} = $@;
                        return;
                }

        }

}


Can i write the code in the above pattern to check the authentication and
whether the user is admin or not.......waiting for the reply thanks in
advance......
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060104/71f2d432/attachment-0001.htm


More information about the Catalyst mailing list