set the branch at login

This commit is contained in:
Joshua Ferraro 2007-08-07 15:45:03 -05:00
parent dbdb7f4feb
commit bf1fd83d08
3 changed files with 8 additions and 36 deletions

View file

@ -114,7 +114,6 @@ C4::Auth - Authenticates Koha users
sub get_template_and_user { sub get_template_and_user {
my $in = shift; my $in = shift;
warn "GET Template";
my $template = my $template =
gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'} ); gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'} );
my ( $user, $cookie, $sessionID, $flags ) = checkauth( my ( $user, $cookie, $sessionID, $flags ) = checkauth(
@ -217,7 +216,8 @@ sub get_template_and_user {
} }
if ( $in->{'type'} eq "intranet" ) { if ( $in->{'type'} eq "intranet" ) {
$template->param( $template->param(
intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), intranetcolorstylesheet =>
C4::Context->preference("intranetcolorstylesheet"),
intranetstylesheet => C4::Context->preference("intranetstylesheet"), intranetstylesheet => C4::Context->preference("intranetstylesheet"),
IntranetNav => C4::Context->preference("IntranetNav"), IntranetNav => C4::Context->preference("IntranetNav"),
intranetuserjs => C4::Context->preference("intranetuserjs"), intranetuserjs => C4::Context->preference("intranetuserjs"),
@ -383,7 +383,7 @@ sub checkauth {
# state variables # state variables
my $loggedin = 0; my $loggedin = 0;
my %info; my %info;
my ( $userid, $cookie, $sessionID, $flags ); my ( $userid, $cookie, $sessionID, $flags, $envcookie );
my $logout = $query->param('logout.x'); my $logout = $query->param('logout.x');
if ( $userid = $ENV{'REMOTE_USER'} ) { if ( $userid = $ENV{'REMOTE_USER'} ) {
@ -545,14 +545,10 @@ sub checkauth {
# new op dev : # new op dev :
# launch a sequence to check if we have a ip for the branch, if we have one we replace the branchcode of the userenv by the branch bound in the ip. # launch a sequence to check if we have a ip for the branch, if we have one we replace the branchcode of the userenv by the branch bound in the ip.
my $ip = $ENV{'REMOTE_ADDR'}; my $ip = $ENV{'REMOTE_ADDR'};
# if they specify at login, use that
if ($query->param('branch')) {
$branchcode = $query->param('branch');
$branchname = GetBranchName($branchcode);
}
my $branches = GetBranches(); my $branches = GetBranches();
my @branchesloop; my @branchesloop;
foreach my $br ( keys %$branches ) { foreach my $br ( keys %$branches ) {
# now we work with the treatment of ip # now we work with the treatment of ip
my $domain = $branches->{$br}->{'branchip'}; my $domain = $branches->{$br}->{'branchip'};
if ( $domain && $ip =~ /^$domain/ ) { if ( $domain && $ip =~ /^$domain/ ) {
@ -591,17 +587,7 @@ sub checkauth {
$session->param('ip',$session->remote_addr()); $session->param('ip',$session->remote_addr());
$session->param('lasttime',time()); $session->param('lasttime',time());
} }
if ($session){
C4::Context::set_userenv(
$session->param('number'), $session->param('id'),
$session->param('cardnumber'), $session->param('firstname'),
$session->param('surname'), $session->param('branch'),
$session->param('branchname'), $session->param('flags'),
$session->param('emailaddress'), $session->param('branchprinter')
);
} }
}
else { else {
if ($userid) { if ($userid) {
$info{'invalid_username_or_password'} = 1; $info{'invalid_username_or_password'} = 1;
@ -631,16 +617,8 @@ sub checkauth {
my $value = $query->param($name); my $value = $query->param($name);
push @inputs, { name => $name, value => $value }; push @inputs, { name => $name, value => $value };
} }
# get the branchloop, which we need for authetication
use C4::Branch;
my $branches = GetBranches();
my @branch_loop;
for my $branch_hash (keys %$branches) {
push @branch_loop, {branchcode => "$branch_hash", branchname => $branches->{$branch_hash}->{'branchname'}, };
}
my $template = gettemplate( $template_name, $type, $query ); my $template = gettemplate( $template_name, $type, $query );
$template->param(branchloop => \@branch_loop,);
$template->param( $template->param(
INPUTS => \@inputs, INPUTS => \@inputs,
suggestion => C4::Context->preference("suggestion"), suggestion => C4::Context->preference("suggestion"),

View file

@ -91,7 +91,8 @@ foreach my $thisbranch (keys %$branches) {
=cut =cut
sub GetBranches { sub GetBranches {
my ($onlymine)=@_;
my $onlymine=@_;
# returns a reference to a hash of references to ALL branches... # returns a reference to a hash of references to ALL branches...
my %branches; my %branches;
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;

View file

@ -44,16 +44,9 @@
<label>Password:<br /> <label>Password:<br />
<input type="password" name="password" id="password" class="input" value="" size="20" tabindex="20" /></label> <input type="password" name="password" id="password" class="input" value="" size="20" tabindex="20" /></label>
</p> </p>
<p>
<label for="branch">Library:</label>
<select name="branch" id="branch" class="input">
<!-- TMPL_LOOP NAME="branchloop" -->
<option value="<!-- TMPL_VAR NAME='branchcode' -->"><!-- TMPL_VAR NAME='branchname' --></option>
<!-- /TMPL_LOOP -->
</select>
</p>
<p class="submit"><input type="submit" value="Login &raquo;" /></p> <p class="submit"><input type="submit" value="Login &raquo;" /></p>
</form> </form>
<!-- /TMPL_IF --> <!-- /TMPL_IF -->
<script type="text/javascript"> <script type="text/javascript">