1 |
<%pre> |
2 |
#include <tntdb/connect.h> |
3 |
#include <tntdb/connection.h> |
4 |
#include <tntdb/result.h> |
5 |
#include <tntdb/row.h> |
6 |
|
7 |
#include <sstream> |
8 |
</%pre> |
9 |
|
10 |
<%session scope="global"> |
11 |
std::string userName; |
12 |
bool isAdmin; |
13 |
</%session> |
14 |
|
15 |
<%config> |
16 |
dburl; |
17 |
</%config> |
18 |
|
19 |
|
20 |
<&header title="Login"> |
21 |
</&header> |
22 |
|
23 |
<h3>Login</h3> |
24 |
|
25 |
<script type="text/javascript" language="JavaScript" src="/md5.js"></script> |
26 |
<script type="text/javascript" language="javascript"> |
27 |
|
28 |
function encryptText() { |
29 |
document.loginform.password.value = hex_md5(document.loginform.password.value); |
30 |
} |
31 |
</script> |
32 |
|
33 |
<{ |
34 |
tntdb::Connection conn = tntdb::connectCached(dburl); |
35 |
|
36 |
|
37 |
std::string post_username = qparam.param("username"); |
38 |
std::string post_password = qparam.param("password"); |
39 |
|
40 |
|
41 |
if (post_username.size() > 0 || post_password.size() > 0) |
42 |
{ |
43 |
|
44 |
std::string sql; |
45 |
sql += "SELECT realname,useradmin FROM users WHERE username = :username AND "; |
46 |
sql += "password = :password AND enabled=true"; |
47 |
|
48 |
tntdb::Statement st = conn.prepare(sql); |
49 |
st.setString("username", post_username).setString("password", post_password); |
50 |
|
51 |
tntdb::Result res = st.select(); |
52 |
|
53 |
if (res.size() >0) |
54 |
{ |
55 |
tntdb::Row row = res[0]; |
56 |
userName = post_username; |
57 |
isAdmin = row.getBool(1); |
58 |
|
59 |
reply.setHeader("Location", "index"); |
60 |
return HTTP_MOVED_TEMPORARILY; //code 302 |
61 |
} |
62 |
else |
63 |
{ |
64 |
reply.out() << "<p><i>Login failed</i></p>\n"; |
65 |
} |
66 |
} |
67 |
}> |
68 |
|
69 |
|
70 |
|
71 |
|
72 |
<form method="post" action="login" name="loginform" onsubmit="encryptText()"> |
73 |
<table border="0"> |
74 |
<tr> |
75 |
<td>Username: </td> |
76 |
<td><input type="text" name="username"></td> |
77 |
</tr> |
78 |
<tr> |
79 |
<td>Password: </td> |
80 |
<td><input type="password" name="password"></td> |
81 |
</tr> |
82 |
<tr> |
83 |
<td> </td> |
84 |
<td><input type="submit"><input type="reset"></td> |
85 |
</table> |
86 |
</form> |
87 |
|
88 |
|
89 |
<&footer> |
90 |
</&footer> |