annotate usrlogin.php @ 306:6610311ac48e

Improve user login handling.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 26 Nov 2013 19:51:11 +0200
parents 7181350076c1
children 2f46b6254ff2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 <?
155
5b92f130ba87 Add copyright header blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
2 //
5b92f130ba87 Add copyright header blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
3 // FAPWeb Simple Demoparty System
5b92f130ba87 Add copyright header blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
4 // Administration interface session login handler
5b92f130ba87 Add copyright header blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
5 // (C) Copyright 2012-2013 Tecnic Software productions (TNSP)
5b92f130ba87 Add copyright header blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
6 //
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 $sessionType = "user";
175
8df523e6326a User require_once instead of require.
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
8 require_once "mconfig.inc.php";
8df523e6326a User require_once instead of require.
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
9 require_once "msite.inc.php";
8df523e6326a User require_once instead of require.
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
10 require_once "msession.inc.php";
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
156
fa7f3defffd0 Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
12 //
fa7f3defffd0 Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
13 // Initialize
fa7f3defffd0 Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
14 //
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 stSetupCacheControl();
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 if (!stConnectSQLDB())
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 die("Could not connect to SQL database.");
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 stReloadSettings();
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
156
fa7f3defffd0 Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
23 //
fa7f3defffd0 Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
24 // Authenticate
fa7f3defffd0 Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
25 //
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 $gotoPage = stGetRequestItem("goto", FALSE);
306
6610311ac48e Improve user login handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 304
diff changeset
27 $errorPage = stGetRequestItem("error", FALSE);
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 $password = stGetRequestItem("key", FALSE);
306
6610311ac48e Improve user login handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 304
diff changeset
29 $error = 0;
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 $sql = stPrepareSQL("SELECT id FROM votekeys WHERE key=%s", $password);
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 if (($votekey_id = stFetchSQLColumn($sql)) !== false)
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 {
129
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
34 if (!stSessionStart(SESS_USER, $password, "userTimeout"))
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 {
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 error_log("User session AUTH LOGIN failed (session setup)");
306
6610311ac48e Improve user login handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 304
diff changeset
37 $error = 2;
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 }
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 else
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 stSetSessionItem("mode", stGetRequestItem("mode", "error"));
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 }
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 else
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 {
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 error_log("User session AUTH LOGIN failed (password)");
306
6610311ac48e Improve user login handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 304
diff changeset
45 $error = 1;
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 }
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
306
6610311ac48e Improve user login handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 304
diff changeset
48 $nextPage = ($error != 0) ? $errorPage : $gotoPage;
6610311ac48e Improve user login handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 304
diff changeset
49
6610311ac48e Improve user login handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 304
diff changeset
50 header("Location: ".($nextPage !== FALSE ? $nextPage : stGetSetting("defaultPage"))
6610311ac48e Improve user login handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 304
diff changeset
51 ($error ? "?error=".$error : "");
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 ?>