Subversion Repositories RepoView

Rev

Rev 5 | Rev 7 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line 1... Line 1...
1
/* $Id: modern.c 5 2024-08-20 22:43:56Z nishi $ */
1
/* $Id: modern.c 6 2024-08-21 00:44:17Z nishi $ */
2
 
2
 
3
#include "rv_query.h"
3
#include "rv_query.h"
4
 
4
 
5
#include "rv_util.h"
5
#include "rv_util.h"
6
#include "rv_version.h"
6
#include "rv_version.h"
Line 17... Line 17...
17
void render_stuff();
17
void render_stuff();
18
 
18
 
19
char* title = NULL;
19
char* title = NULL;
20
char* desc = NULL;
20
char* desc = NULL;
21
char* page = NULL;
21
char* page = NULL;
-
 
22
extern char* user;
22
 
23
 
23
void render_page(void) {
24
void render_page(void) {
24
	rv_load_query('Q');
25
	rv_load_query('Q');
25
	char* query = rv_get_query("page");
26
	char* query = rv_get_query("page");
26
	if(query == NULL) query = "welcome";
27
	if(query == NULL) query = "welcome";
Line 61... Line 62...
61
		if(rv_get_query("username") == NULL || rv_get_query("password") == NULL) {
62
		if(rv_get_query("username") == NULL || rv_get_query("password") == NULL) {
62
			add_data(&page, "Invalid form.\n");
63
			add_data(&page, "Invalid form.\n");
63
		} else {
64
		} else {
64
			if(rv_has_user(rv_get_query("username"))) {
65
			if(rv_has_user(rv_get_query("username"))) {
65
				if(rv_check_password(rv_get_query("username"), rv_get_query("password"))) {
66
				if(rv_check_password(rv_get_query("username"), rv_get_query("password"))) {
-
 
67
					if(user != NULL) free(user);
-
 
68
					user = rv_strdup(rv_get_query("username"));
66
					add_data(&page, "Welcome back.\n");
69
					add_data(&page, "Welcome back.\n");
67
					rv_save_login(rv_get_query("username"));
70
					rv_save_login(rv_get_query("username"));
68
				} else {
71
				} else {
69
					add_data(&page, "Invalid password.");
72
					add_data(&page, "Invalid password.");
70
				}
73
				}
71
			} else {
74
			} else {
72
				add_data(&page, "User does not exist.");
75
				add_data(&page, "User does not exist.");
73
			}
76
			}
74
		}
77
		}
-
 
78
	} else if(strcmp(query, "mypage") == 0) {
-
 
79
		title = rv_strdup("My Page");
-
 
80
		desc = rv_strdup("You manage your information here.");
-
 
81
		if(user == NULL) {
-
 
82
			page = rv_strdup("It looks like you are not logged in.<br>Want to <a href=\"");
-
 
83
			add_data(&page, INSTANCE_ROOT);
-
 
84
			add_data(&page, "/?page=login\">log in</a>?\n");
-
 
85
		}
75
	}
86
	}
76
 
87
 
77
	if(title == NULL) title = rv_strdup("");
88
	if(title == NULL) title = rv_strdup("");
78
	if(desc == NULL) desc = rv_strdup("");
89
	if(desc == NULL) desc = rv_strdup("");
79
	if(page == NULL) page = rv_strdup("");
90
	if(page == NULL) page = rv_strdup("");
Line 107... Line 118...
107
	}
118
	}
108
	return r;
119
	return r;
109
}
120
}
110
 
121
 
111
void render_stuff(void) {
122
void render_stuff(void) {
112
	char* user = rv_logged_in();
-
 
113
	char* escaped;
123
	char* escaped;
114
	add_data(&buffer, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n");
124
	add_data(&buffer, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n");
115
	add_data(&buffer, "<html>\n");
125
	add_data(&buffer, "<html>\n");
116
	add_data(&buffer, "	<head>\n");
126
	add_data(&buffer, "	<head>\n");
117
	add_data(&buffer, "		<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">\n");
127
	add_data(&buffer, "		<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">\n");
Line 145... Line 155...
145
	add_data(&buffer, "	margin: 5px auto;\n");
155
	add_data(&buffer, "	margin: 5px auto;\n");
146
	add_data(&buffer, "	font-family: sans-serif;\n");
156
	add_data(&buffer, "	font-family: sans-serif;\n");
147
	add_data(&buffer, "}\n");
157
	add_data(&buffer, "}\n");
148
	add_data(&buffer, "#nav {\n");
158
	add_data(&buffer, "#nav {\n");
149
	add_data(&buffer, "	background-color: white;\n");
159
	add_data(&buffer, "	background-color: white;\n");
-
 
160
	add_data(&buffer, "	background-image: url('");
-
 
161
	add_data(&buffer, INSTANCE_NAVBAR);
-
 
162
	add_data(&buffer, "');\n");
150
	add_data(&buffer, "	height: 44px;\n");
163
	add_data(&buffer, "	height: 44px;\n");
151
	add_data(&buffer, "	padding: 8px;\n");
164
	add_data(&buffer, "	padding: 8px;\n");
152
	add_data(&buffer, "	padding-left: 32px;\n");
165
	add_data(&buffer, "	padding-left: 32px;\n");
153
	add_data(&buffer, "	font-size: 22px;\n");
166
	add_data(&buffer, "	font-size: 22px;\n");
154
	add_data(&buffer, "	font-weight: bold;\n");
167
	add_data(&buffer, "	font-weight: bold;\n");
Line 230... Line 243...
230
		add_data(&buffer, "				<a href=\"");
243
		add_data(&buffer, "				<a href=\"");
231
		add_data(&buffer, INSTANCE_ROOT);
244
		add_data(&buffer, INSTANCE_ROOT);
232
		add_data(&buffer, "/?page=login\">Login</a>\n");
245
		add_data(&buffer, "/?page=login\">Login</a>\n");
233
		add_data(&buffer, "			</div>\n");
246
		add_data(&buffer, "			</div>\n");
234
	}
247
	}
-
 
248
	if(user != NULL) {
-
 
249
		add_data(&buffer, "<div style=\"float: right;font-size: 10px;padding-top: 36px;padding-right: 0;font-style: italic;\">You have logged in as <a href=\"");
-
 
250
		add_data(&buffer, INSTANCE_ROOT);
-
 
251
		add_data(&buffer, "/?page=mypage\">");
-
 
252
		add_data(&buffer, user);
-
 
253
		add_data(&buffer, "</a></div>");
-
 
254
	}
235
	add_data(&buffer, "		</div>\n");
255
	add_data(&buffer, "		</div>\n");
236
	add_data(&buffer, "		<div id=\"desc\">\n");
256
	add_data(&buffer, "		<div id=\"desc\">\n");
237
	add_data(&buffer, "			<div id=\"descinside\">\n");
257
	add_data(&buffer, "			<div id=\"descinside\">\n");
238
	add_data(&buffer, "				<h1>");
258
	add_data(&buffer, "				<h1>");
239
	add_data(&buffer, title);
259
	add_data(&buffer, title);