Umfragen
login.php
Go to the documentation of this file.
1 <?php
2 /*
3  * login.php
4  *
5  * Copyright 2012 Johannes <jojo@jojo-42>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301, USA.
21  *
22  *
23  */
24 
25 require_once("config.php");
26 require_once("inc/tools.php");
27 require_once("inc/messages.class.php");
28 require_once("inc/html.class.php");
29 require_once("inc/db.class.php");
30 require_once("inc/config.class.php");
31 require_once("inc/user.class.php");
32 require("inc/auth.class.php");
33 require_once("inc/user.class.php");
34 
35 $db = new db( DB_USER, DB_PASS, DB_DATABASE, DB_HOST );
37 $config->load();
38 
39 if( !isset($_SESSION)){
40  session_start();
41 }
42 session_regenerate_id();
43 
45 
46 if( (isset($_SESSION["previous_url"])) AND ($_SESSION["previous_url"] != "") ){
47  define("LOCATION_AUTH_SUCCESS",$_SESSION["previous_url"]);
48 }else{
49  define("LOCATION_AUTH_SUCCESS","page.php");
50 }
51 
52 //define("LOCATION_AUTH_RETRY",$_SERVER["SCRIPT_NAME"]);
53 
54 
55 function print_form(){
56  $user = "jojo";
57  $pass = "isabelle";
58  echo "
59  <div id='form_div'>
60  <form method='POST' id='login_form'>
61  <table><tr>
62  <td> <img src='icons/256/dialog-password.png' alt='' style='height:80px'/> </td>
63  <td>
64  <table>
65  <tr>
66  <td>Username:</td>
67  <td><input type='text' id='uname' name='uname' value='$user'/> </td>
68  </tr>
69  <tr>
70  <td>Password:</td>
71  <td><input type='password' id='pass' name='pass' value='$pass'/></td>
72  </tr>
73  <tr>
74  <td></td>
75  <td style='text-align:left;padding-top:10px'><input type='submit' name='login' value='Login' style='width:10em;height:2em'/></td>
76  </tr>
77  </table>
78  </td>
79  </tr></table>
80  </form>
81  </div>
82  ";
83 }
84 
85 
86 
87 
88 if ( isset($_POST["logout"]) ){
89  /*unset($_SESSION["auth"]);
90  unset($_SESSION["user"]);
91  unset($_SESSION["fullName"]);
92  unset($_SESSION["userID"]);
93  unset($_SESSION["group"]);
94  unset($_SESSION["groupName"]);*/
95  if( isset($_SESSION["projects"]) ){
96  unset($_SESSION["projects"]);
97  }
98  unset($_SESSION["user"]);
99  session_destroy();
100  // redirect to self because of post-redirect-get
101  header("Location: {$_SERVER["SCRIPT_NAME"]}");
102  exit();
103 }
104 
105 if ( isset($_POST["login"]) ){
106  $au = make_auth_object();
107  $group_mapping = $au->get_gid_to_name_mapping( $groups_whitelist );
108  if ($au->auth($_POST["uname"],$_POST["pass"]) ){
109 
110 
111  $user = new user();
112  $user->ID = $au->userID;
113  $user->name = $_POST["uname"];
114  $user->fullName = $au->userFullName;
115  $user->givenName = $au->userGivenName;
116  $user->surName = $au->userSurName;
117  $user->group = $au->userGroupID;
118  $user->groupName = $group_mapping[$au->userGroupID];;
119  $user->is_auth = true;
120 
121  /*$_SESSION["auth"] = true;
122  //$_SESSION["user"] = $_POST["uname"];
123  $_SESSION["userID"] = $au->userID;
124  $_SESSION["fullName"] = $au->userFullName;
125  $_SESSION["group"] = $au->userGroupID;
126  $_SESSION["groupName"] = $group_mapping[$au->userGroupID];*/
127  if( isset($au->projects) ){
128  $_SESSION["projects"] = $au->projects;
129  }
130  $user->load_config($db,$_POST["uname"]);
131  /*$_SESSION["userObj"] = $user;*/
132  $_SESSION["user"] = $user;
133  header("location:".LOCATION_AUTH_SUCCESS);
134  } else{
135  $messages->add_message( new errorMessage("Login fehlgeschlagen. Bitte Benutzername und Passwort überprüfen. Ist die Feststelltaste aktiviert?") );
136  }
137 
138 }
139 
140 $extra = '
141  <style>
142  #user_table{
143  box-shadow:0px 0px 10px #FFFBE1;
144  padding:15px;
145  margin:0px auto;
146 
147  }
148 
149  #user_table table{
150  border-collapse:collapse;
151  border:1px solid black;
152  background-color:#FFF;
153  width:80%;
154  margin:0px auto;
155  }
156  #user_table td, #user_table th{
157  /*border:1px solid black;*/
158  padding: 1px 5px 1px 5px;
159  }
160 
161  #user_table th{
162  background-color:#FFEBBD;
163  }
164 
165  #user_table a{
166  color:#2469B1;
167  text-decoration:none;
168  }
169 
170  #form_div{
171  border:2px dotted gray;
172  box-shadow:0px 0px 10px #BFBFBF;
173  background-color:#FFF;
174 
175  padding:10px;
176  text-align:center;
177  margin:0px auto;
178  margin-top:50px;
179  width:400px;
180  }
181 
182  #content{
183  background-color:#F3F3F3
184  }
185  </style>
186 
187  <script type="text/javascript">
188  function login( name , pass ){
189  document.getElementById("uname").value = name;
190  document.getElementById("pass").value = pass;
191  document.getElementsByName("login")[0].click();
192  }
193  </script>
194 ';
195 
196 HTML::doctype();
197 HTML::head($extra);
198 
199 echo '<h1 class="first_h1" id="login_header"> <img src="fcs-logo.png" style="height:1em"/> Willkommen auf der Umfragenseite <img src="fcs-logo.png" style="height:1em"/> </h1>';
200 
201 // error message handling
202 $messages->display_messages();
203 $messages->del_all_messages();
204 
205 // loginform
206 print_form();
207 
208 ?>
209 
210 <br/> <br/> <br/> <hr/>
211 <div id="user_table">
212 
213 <table>
214 <tr><th>FullName</th><th>login</th><th>pass</th><th>group</th></tr>
215  <tr style='background-color:#F1F1F1'>
216  <td> <a href='#' onClick='login("adm","adm");'> admin </a> </td>
217  <td><b>adm</b> (1000)</td>
218  <td>adm</td>
219  <td>admins (500)</td>
220  </tr>
221  <tr>
222  <td> <a href='#' onClick='login("jojo","isabelle");'> Johannes th </a> </td>
223  <td><b>jojo</b> (1001)</td>
224  <td>isabelle</td>
225  <td>teachers (501)</td>
226  </tr>
227  <tr style='background-color:#F1F1F1'>
228  <td> <a href='#' onClick='login("ndr","ndr");'> Natsu Dragneel </a> </td>
229  <td><b>ndr</b> (1002)</td>
230  <td>ndr</td>
231  <td>teachers (501)</td>
232  </tr>
233  <tr>
234  <td> <a href='#' onClick='login("lhe","lhe");'> Lucy Heartfilia </a> </td>
235  <td><b>lhe</b> (1003)</td>
236  <td>lhe</td>
237  <td>teachers (501)</td>
238  </tr>
239  <tr style='background-color:#F1F1F1'>
240  <td> <a href='#' onClick='login("esc","esc");'> Erza Scarlet </a> </td>
241  <td><b>esc</b> (1004)</td>
242  <td>esc</td>
243  <td>teachers (501)</td>
244  </tr>
245  <tr>
246  <td> <a href='#' onClick='login("gfu","gfu");'> Gray Fullbuster </a> </td>
247  <td><b>gfu</b> (1005)</td>
248  <td>gfu</td>
249  <td>teachers (501)</td>
250  </tr>
251  <tr style='background-color:#F1F1F1'>
252  <td> <a href='#' onClick='login("wma","wma");'> Wendy Marvell </a> </td>
253  <td><b>wma</b> (1006)</td>
254  <td>wma</td>
255  <td>class1 (502)</td>
256  </tr>
257  <tr>
258  <td> <a href='#' onClick='login("gre","gre");'> Gajeel Redfox </a> </td>
259  <td><b>gre</b> (1007)</td>
260  <td>gre</td>
261  <td>class1 (502)</td>
262  </tr>
263  <tr style='background-color:#F1F1F1'>
264  <td> <a href='#' onClick='login("mdr","mdr");'> Makarov Dreyar </a> </td>
265  <td><b>mdr</b> (1008)</td>
266  <td>mdr</td>
267  <td>class1 (502)</td>
268  </tr>
269  <tr>
270  <td> <a href='#' onClick='login("mst","mst");'> Mirajane Strauss </a> </td>
271  <td><b>mst</b> (1009)</td>
272  <td>mst</td>
273  <td>class2 (503)</td>
274  </tr>
275  <tr style='background-color:#F1F1F1'>
276  <td> <a href='#' onClick='login("est","est");'> Elfman Strauss </a> </td>
277  <td><b>est</b> (1010)</td>
278  <td>est</td>
279  <td>class2 (503)</td>
280  </tr>
281  <tr>
282  <td> <a href='#' onClick='login("lst","lst");'> Lisanna Strauss </a> </td>
283  <td><b>lst</b> (1011)</td>
284  <td>lst</td>
285  <td>class2 (503)</td>
286  </tr>
287  <tr style='background-color:#F1F1F1'>
288  <td> <a href='#' onClick='login("cal","cal");'> Cana Alberona </a> </td>
289  <td><b>cal</b> (1012)</td>
290  <td>cal</td>
291  <td>class2 (503)</td>
292  </tr>
293  <tr>
294  <td> <a href='#' onClick='login("jlo","jlo");'> Juvia Lockser </a> </td>
295  <td><b>jlo</b> (1013)</td>
296  <td>jlo</td>
297  <td>class3 (504)</td>
298  </tr>
299  <tr style='background-color:#F1F1F1'>
300  <td> <a href='#' onClick='login("fju","fju");'> Freed Justine </a> </td>
301  <td><b>fju</b> (1014)</td>
302  <td>fju</td>
303  <td>class3 (504)</td>
304  </tr>
305  <tr>
306  <td> <a href='#' onClick='login("gcl","gcl");'> Gildarts Clive </a> </td>
307  <td><b>gcl</b> (1015)</td>
308  <td>gcl</td>
309  <td>class3 (504)</td>
310  </tr>
311  <tr style='background-color:#F1F1F1'>
312  <td> <a href='#' onClick='login("mco","mco");'> Macao Conbolt </a> </td>
313  <td><b>mco</b> (1016)</td>
314  <td>mco</td>
315  <td>class3 (504)</td>
316  </tr>
317  <tr>
318  <td> <a href='#' onClick='login("hap","hap");'> Happy </a> </td>
319  <td><b>hap</b> (1017)</td>
320  <td>hap</td>
321  <td>class4 (505)</td>
322  </tr>
323  <tr style='background-color:#F1F1F1'>
324  <td> <a href='#' onClick='login("car","car");'> Carla </a> </td>
325  <td><b>car</b> (1018)</td>
326  <td>car</td>
327  <td>class4 (505)</td>
328  </tr>
329  <tr>
330  <td> <a href='#' onClick='login("pan","pan");'> Pantherlily </a> </td>
331  <td><b>pan</b> (1019)</td>
332  <td>pan</td>
333  <td>class4 (505)</td>
334  </tr>
335 </table>
336 
337 
338 </div>
339 
340 
341 <?php HTML::foot(); ?>