1 |
torben |
78 |
<%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; |
35 |
|
|
|
36 |
|
|
conn = tntdb::connect(dburl); //letting exceptions flow up and to tntnet and let it display an error message |
37 |
|
|
|
38 |
|
|
|
39 |
|
|
std::string post_username = qparam.param("username"); |
40 |
|
|
std::string post_password = qparam.param("password"); |
41 |
|
|
bool showForm = true; |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
if (post_username.size() > 0 || post_password.size() > 0) |
45 |
|
|
{ |
46 |
|
|
|
47 |
|
|
std::stringstream sql; |
48 |
|
|
sql << "SELECT realname,useradmin FROM users WHERE username = '" << post_username << "' AND "; |
49 |
|
|
sql << "password = '" << post_password << "' AND enabled=true"; |
50 |
|
|
|
51 |
|
|
tntdb::Result res = conn.select(sql.str()); |
52 |
|
|
if (res.size() >0) |
53 |
|
|
{ |
54 |
|
|
tntdb::Row row = res[0]; |
55 |
|
|
userName = post_username; |
56 |
|
|
isAdmin = row.getBool(1); |
57 |
|
|
reply.setHeader("Location", "/dynamic/index"); |
58 |
|
|
reply.setHeader("Refresh", "0;/dynamic/index"); |
59 |
|
|
} |
60 |
|
|
else |
61 |
|
|
{ |
62 |
|
|
reply.out() << "<p><i>Login failed</i></p>\n"; |
63 |
|
|
} |
64 |
|
|
} |
65 |
|
|
}> |
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
<{ |
70 |
|
|
if (showForm) { |
71 |
|
|
}> |
72 |
|
|
|
73 |
|
|
<form method="post" action="login" name="loginform" onsubmit="encryptText()"> |
74 |
|
|
<table border="0"> |
75 |
|
|
<tr> |
76 |
|
|
<td>Username: </td> |
77 |
|
|
<td><input type="text" name="username"></td> |
78 |
|
|
</tr> |
79 |
|
|
<tr> |
80 |
|
|
<td>Password: </td> |
81 |
|
|
<td><input type="password" name="password"></td> |
82 |
|
|
</tr> |
83 |
|
|
<tr> |
84 |
|
|
<td> </td> |
85 |
|
|
<td><input type="submit"><input type="reset"></td> |
86 |
|
|
</table> |
87 |
|
|
</form> |
88 |
|
|
|
89 |
|
|
<{ |
90 |
|
|
} // end if (showForm) |
91 |
|
|
}> |
92 |
|
|
|
93 |
|
|
<&footer> |
94 |
|
|
</&footer> |