Ejemplo n.º 1
0
 /**
  * This class implements the Singleton pattern. There is only ever
  * one instance of the this class and it is accessed only via the 
  * ClassName::instance() method.
  *
  * After access by a client, state will be destroyed at shutdown.
  * 
  * @return object 
  * @access public
  * @since 5/26/05
  * @static
  */
 public static function instance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new PolyphonyLogin();
     }
     return self::$instance;
 }
Ejemplo n.º 2
0
 /**
  * Answer the login HTML
  * 
  * @return string
  * @access public
  * @since 6/5/08
  */
 public function getLoginForm()
 {
     ob_start();
     $harmoni = Harmoni::instance();
     $authN = Services::getService("AuthN");
     $agentM = Services::getService("Agent");
     $idM = Services::getService("Id");
     $authTypes = $authN->getAuthenticationTypes();
     $users = '';
     while ($authTypes->hasNext()) {
         $authType = $authTypes->next();
         $id = $authN->getUserId($authType);
         if (!$id->isEqual($idM->getId('edu.middlebury.agents.anonymous'))) {
             $agent = $agentM->getAgent($id);
             $exists = false;
             foreach (explode("+", $users) as $user) {
                 if ($agent->getDisplayName() == $user) {
                     $exists = true;
                 }
             }
             if (!$exists) {
                 if ($users == '') {
                     $users .= $agent->getDisplayName();
                 } else {
                     $users .= " + " . $agent->getDisplayName();
                 }
             }
         }
     }
     if ($users != '') {
         print "\n<div class='' style='margin-top: 10px;'>";
         print "<strong>" . dgettext("polyphony", "Logged in as:") . "</strong> &nbsp;";
         if (count(explode("+", $users)) == 1) {
             print $users . "\t";
         } else {
             print dgettext("polyphony", "Users: ") . $users . "\t";
         }
         print " | <a href='" . $harmoni->request->quickURL("auth", "logout") . "'>" . dgettext("polyphony", "Log Out") . "</a></div>";
     } else {
         if (PolyphonyLogin::instance()->hasLoginFailed()) {
             $message = "<span class='error'>" . _("Login Failed") . "</span> &nbsp; &nbsp;";
         } else {
             $message = "";
         }
         // set bookmarks for success and failure
         $harmoni->history->markReturnURL("polyphony/display_login", $harmoni->request->quickURL($harmoni->config->get('defaultModule'), $harmoni->config->get('defaultAction')));
         $harmoni->history->markReturnURL("polyphony/login_fail", $harmoni->request->quickURL("user", "main", array('login_failed' => 'true')));
         $harmoni->request->startNamespace("harmoni-authentication");
         $usernameField = $harmoni->request->getName("username");
         $passwordField = $harmoni->request->getName("password");
         $harmoni->request->endNamespace();
         $harmoni->request->startNamespace("polyphony");
         $visitorAuthType = new Type("Authentication", "edu.middlebury.harmoni", "Visitors");
         print "\n<div style='margin-top: 10px;'>" . "\n\t<strong>Visitor Login:</strong>" . "\n<form action='" . $harmoni->request->quickURL("auth", "login_type", array('type' => $visitorAuthType->asString())) . "' style='' method='post'>" . $message . "\n\t" . dgettext("polyphony", "Username (email address):") . " <input class='' type='text' size='8' \n\t\t\t\t\tname='{$usernameField}'/>" . "\n\t" . dgettext("polyphony", "Password:"******" <input class='' type='password' size ='8' \n\t\t\t\t\tname='{$passwordField}'/>" . "\n\t <input class='button' type='submit' value='Log in' />" . "\n</form></div>\n";
         $harmoni->request->endNamespace();
     }
     return ob_get_clean();
 }
Ejemplo n.º 3
0
 /**
  * Answer the HTML string for the login form.
  * 
  * @return string
  * @access public
  * @since 2/23/09
  */
 public function getLoginFormHtml()
 {
     if (defined('LOGIN_FORM_CALLBACK')) {
         return call_user_func(LOGIN_FORM_CALLBACK);
     } else {
         $harmoni = Harmoni::instance();
         $harmoni->history->markReturnURL("polyphony/login_fail", $harmoni->request->mkURLWithPassthrough());
         $harmoni->request->startNamespace("harmoni-authentication");
         $usernameField = $harmoni->request->getName("username");
         $passwordField = $harmoni->request->getName("password");
         $harmoni->request->endNamespace();
         $harmoni->request->startNamespace("polyphony");
         if (PolyphonyLogin::instance()->hasLoginFailed()) {
             $message = "<span class='error'>" . _("Login Failed") . "</span> &nbsp; &nbsp;";
         } else {
             $message = "";
         }
         $html = "\n<form action='" . $harmoni->request->quickURL("auth", "login") . "' method='post'>" . $message . "\n\t" . _("Username/email:") . " <input class='small' type='text' size='8' \n\t\t\t\t\tname='{$usernameField}'/>" . "\n\t" . _("Password:"******" <input class='small' type='password' size ='8' \n\t\t\t\t\tname='{$passwordField}'/>" . "\n\t <input class='button small' type='submit' value='Log in' />" . "\n</form>";
         $harmoni->request->endNamespace();
         return $html;
     }
 }