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::connect(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::stringstream sql; |
45 |
sql << "SELECT realname,useradmin FROM users WHERE username = '" << post_username << "' AND "; |
46 |
sql << "password = '" << post_password << "' AND enabled=true"; |
47 |
|
48 |
tntdb::Result res = conn.select(sql.str()); |
49 |
if (res.size() >0) |
50 |
{ |
51 |
tntdb::Row row = res[0]; |
52 |
userName = post_username; |
53 |
isAdmin = row.getBool(1); |
54 |
|
55 |
reply.setHeader("Location", "index"); |
56 |
return HTTP_MOVED_TEMPORARILY; //code 302 |
57 |
} |
58 |
else |
59 |
{ |
60 |
reply.out() << "<p><i>Login failed</i></p>\n"; |
61 |
} |
62 |
} |
63 |
}> |
64 |
|
65 |
|
66 |
|
67 |
|
68 |
<form method="post" action="login" name="loginform" onsubmit="encryptText()"> |
69 |
<table border="0"> |
70 |
<tr> |
71 |
<td>Username: </td> |
72 |
<td><input type="text" name="username"></td> |
73 |
</tr> |
74 |
<tr> |
75 |
<td>Password: </td> |
76 |
<td><input type="password" name="password"></td> |
77 |
</tr> |
78 |
<tr> |
79 |
<td> </td> |
80 |
<td><input type="submit"><input type="reset"></td> |
81 |
</table> |
82 |
</form> |
83 |
|
84 |
|
85 |
<&footer> |
86 |
</&footer> |