/[H9]/trunk/tntnet/dynamic/login.ecpp
ViewVC logotype

Contents of /trunk/tntnet/dynamic/login.ecpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 80 - (show annotations) (download)
Wed Nov 28 14:27:51 2007 UTC (16 years, 5 months ago) by torben
File size: 1775 byte(s)
A little more work on the login system

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;
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("Refresh", "0; url=/dynamic/index");
58 }
59 else
60 {
61 reply.out() << "<p><i>Login failed</i></p>\n";
62 }
63 }
64 }>
65
66
67
68 <{
69 if (showForm) {
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>&nbsp;</td>
84 <td><input type="submit"><input type="reset"></td>
85 </table>
86 </form>
87
88 <{
89 } // end if (showForm)
90 }>
91
92 <&footer>
93 </&footer>

  ViewVC Help
Powered by ViewVC 1.1.20