<<

Note: This block was commented out with improperly formatted POD. It was not interpreted by perl, but not properly handled by POD formatters. I fixed the POD syntax error so this code is now obviously a comment and not code. The code has been extracted to the login_core sub and is called above. -- amoore Aug 12, 2008

    if (!exists($server->{config}->{accounts}->{$uid})) {
                syslog("LOG_WARNING", "MsgType::handle_login: Unknown login '$uid'");
                $status = 0;
    } elsif ($server->{config}->{accounts}->{$uid}->{password} ne $pwd) {
                syslog("LOG_WARNING", "MsgType::handle_login: Invalid password for login '$uid'");
                $status = 0;
    } else {
        # Store the active account someplace handy for everybody else to find.
                $server->{account} = $server->{config}->{accounts}->{$uid};
                $inst = $server->{account}->{institution};
                $server->{institution} = $server->{config}->{institutions}->{$inst};
                $server->{policy} = $server->{institution}->{policy};
                $server->{sip_username} = $uid;
                $server->{sip_password} = $pwd;

                my $auth_status = api_auth($uid,$pwd);
                if (!$auth_status or $auth_status !~ /^ok$/i) {
                        syslog("LOG_WARNING", "api_auth failed for SIP terminal '%s' of '%s': %s",
                                                $uid, $inst, ($auth_status||'unknown'));
                        $status = 0;
                } else {
                        syslog("LOG_INFO", "Successful login/auth for '%s' of '%s'", $server->{account}->{id}, $inst);
                        #
                        # initialize connection to ILS
                        #
                        my $module = $server->{config}->{institutions}->{$inst}->{implementation};
                        syslog("LOG_DEBUG", 'handle_login: ' . Dumper($module));
                        $module->use;
                        if ($@) {
                                syslog("LOG_ERR", "%s: Loading ILS implementation '%s' for institution '%s' failed",
                                                $server->{service}, $module, $inst);
                                die("Failed to load ILS implementation '$module' for $inst");
                        }

                        # like   ILS->new(), I think.
                        $server->{ils} = $module->new($server->{institution}, $server->{account});
                        if (!$server->{ils}) {
                            syslog("LOG_ERR", "%s: ILS connection to '%s' failed", $server->{service}, $inst);
                            die("Unable to connect to ILS '$inst'");
                        }
                }
        }

<<