changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / auth / auth_method_form.php
1 <?php
2
3 /*
4    This plugin provides a login <form>, and after verification stores
5    username and password into a browser Cookie.
6
7    To use this, you'll also need a user database plugin and a ewiki
8    auth_perm plugin in the _PROTECTED_MODE.
9
10 */
11
12
13 #-- glue
14 $ewiki_plugins["auth_query"][0] = "ewiki_auth_query_form";
15 define("EWIKI_AUTH_QUERY_SAFE", "eventually");
16
17
18 #-- login form text
19 $ewiki_t["en"]["LOGIN_QUERY"] = "Please log in to use this function:";
20 $ewiki_t["en"]["LOGIN_QUERY_2"] = "";
21 $ewiki_t["de"]["LOGIN_QUERY"] = "Bitte log dich ein, um diese Funktion zu verwenden:";
22 $ewiki_t["de"]["LOGIN_QUERY_2"] = "";
23 #-- text snippet translations
24 $ewiki_t["de"]["user"] = "Nutzer";
25 $ewiki_t["de"]["password"] = "Paßwort";
26 $ewiki_t["de"]["login"] = "Einloggen";
27
28
29 #-- code
30 function ewiki_auth_query_form(&$data, $force_query=0) {
31
32    global $ewiki_plugins, $ewiki_config, $ewiki_errmsg, $ewiki_id,
33           $ewiki_action, $ewiki_author, $ewiki_ring;
34    $o = &$ewiki_errmsg;
35
36    #-- get user/pw from POST or COOKIE
37    if ($_POST["login_user"]) {
38       $_user = $_REQUEST["login_user"];
39       $_pw = $_REQUEST["login_pw"];
40    }
41    elseif ($_COOKIE["ewiki_login"]) {
42       list($_user,$_pw) = explode(":", base64_decode($_COOKIE["ewiki_login"]));
43    }
44
45    #-- check password
46    $_success=0;
47    if (strlen($_user) && strlen($_pw)) {
48       $_success = ewiki_auth_user($_user, $_pw);
49    }
50   
51    #-- store login data as Cookie
52    if ($_success && $_POST["login_user"]) {
53       setcookie("ewiki_login", base64_encode("$_user:$_pw"), time()+7*24*3600);
54    }
55
56    #-- login form
57    if ($force_query && !$_success || ($force_query >= 2)) {
58
59       #-- it's safe to call this plugin for interception of running submits
60       $_REPOST = "";
61       if (defined("EWIKI_AUTH_QUERY_SAFE")) {
62          foreach($_POST as $i=>$v) {
63             if ($i=="login_name" || $i=="login_pw") {  continue;  }
64             $_REPOST .= '<input type="hidden" name="'.$i.'" value="'
65                      . preg_replace('/([^\w\d\260-\377])/e', '"&#".ord("$1").";"', $v)
66                      . '">'."\n";
67          }
68          $_REPOST = '<!-- $_REPOST -->'."\n".$_REPOST.'<!-- $_END -->'."\n";
69       }
70
71       #-- print
72       $o = '<div class="login-form auth-login">'
73          . ewiki_make_title($ewiki_id, "Login", $_title_class=4, $ewiki_action, $_go_action="info")
74          . ewiki_t("LOGIN_QUERY") . "\n<br /><br />\n"
75          . '<form action="'.$_SERVER["REQUEST_URI"].'" method="POST">' . "\n"
76          . ewiki_t(
77                '_{user} <input type="text" size="14" name="login_user"><br />' . "\n"
78              . '_{password} <input type="password" size="10" maxsize="12" name="login_pw"><br /><br />' . "\n"
79              . '<input type="submit" value="_{login}"><br /><br />' . "\n"
80            )
81          . $_REPOST
82          . "</form><br /><br />\n"
83          . ewiki_t("LOGIN_QUERY_2")
84          . '</div>';
85    }
86
87    #-- end
88    return($_success);
89 }
90
91
92
93 ?>