/[LeafOK_CVS]/lbbs/src/user_info_update.c
ViewVC logotype

Contents of /lbbs/src/user_info_update.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations)
Sat Jan 3 10:27:14 2026 UTC (2 months, 1 week ago) by sysadm
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +1 -1 lines
Content type: text/x-csrc
Update copyright info

1 /* SPDX-License-Identifier: GPL-3.0-or-later */
2 /*
3 * user_info_update
4 * - update user information
5 *
6 * Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com>
7 *
8 * Co-author: 老黑噜 <2391669999@qq.com>
9 */
10
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14
15 #include "bbs.h"
16 #include "bwf.h"
17 #include "database.h"
18 #include "editor.h"
19 #include "io.h"
20 #include "lml.h"
21 #include "log.h"
22 #include "screen.h"
23 #include "str_process.h"
24 #include "user_info_update.h"
25 #include "user_list.h"
26 #include "user_priv.h"
27 #include <ctype.h>
28 #include <stdlib.h>
29 #include <sys/param.h>
30
31 enum bbs_user_sign_const_t
32 {
33 BBS_user_sign_max_len = 4096,
34 BBS_user_sign_max_line = 10,
35 BBS_user_sign_cnt = 3,
36 };
37
38 int user_intro_edit(int uid)
39 {
40 MYSQL *db = NULL;
41 MYSQL_RES *rs = NULL;
42 MYSQL_ROW row;
43 char sql_intro[SQL_BUFFER_LEN + 2 * BBS_user_intro_max_len + 1];
44 EDITOR_DATA *p_editor_data = NULL;
45 int ret = 0;
46 int ch = 0;
47 char intro[BBS_user_intro_max_len + 1];
48 char intro_f[BBS_user_intro_max_len * 2 + 1];
49 long len_intro = 0L;
50 long line_offsets[BBS_user_intro_max_line + 1];
51 long lines = 0L;
52
53 db = db_open();
54 if (db == NULL)
55 {
56 log_error("db_open() error: %s", mysql_error(db));
57 ret = -1;
58 goto cleanup;
59 }
60
61 snprintf(sql_intro, sizeof(sql_intro), "SELECT introduction FROM user_pubinfo WHERE UID=%d", uid);
62 if (mysql_query(db, sql_intro) != 0)
63 {
64 log_error("Query user_pubinfo error: %s", mysql_error(db));
65 ret = -2;
66 goto cleanup;
67 }
68 if ((rs = mysql_store_result(db)) == NULL)
69 {
70 log_error("Get user_intro data failed");
71 ret = -2;
72 goto cleanup;
73 }
74 if ((row = mysql_fetch_row(rs)))
75 {
76 p_editor_data = editor_data_load(row[0] ? row[0] : "");
77 }
78 else
79 {
80 log_error("mysql_fetch_row() failed");
81 ret = -2;
82 goto cleanup;
83 }
84 mysql_free_result(rs);
85 rs = NULL;
86 mysql_close(db);
87 db = NULL;
88
89 for (ch = 'E'; !SYS_server_exit;)
90 {
91 if (ch == 'E')
92 {
93 editor_display(p_editor_data);
94 }
95
96 clearscr();
97 moveto(1, 1);
98 prints("(S)保存, (C)取消 or (E)再编辑? [S]: ");
99 iflush();
100
101 ch = igetch_t(BBS_max_user_idle_time);
102 switch (toupper(ch))
103 {
104 case KEY_NULL:
105 case KEY_TIMEOUT:
106 goto cleanup;
107 case CR:
108 case 'S':
109 len_intro = editor_data_save(p_editor_data, intro, BBS_user_intro_max_len);
110 if (len_intro < 0)
111 {
112 log_error("editor_data_save() error");
113 ret = -3;
114 goto cleanup;
115 }
116
117 if (check_badwords(intro, '*') < 0)
118 {
119 log_error("check_badwords(introduction) error");
120 ret = -3;
121 goto cleanup;
122 }
123
124 lml_render(intro, intro_f, sizeof(intro_f), SCREEN_COLS, 0);
125
126 lines = split_data_lines(intro_f, SCREEN_COLS + 1, line_offsets, BBS_user_intro_max_line + 2, 1, NULL);
127 if (lines > BBS_user_intro_max_line)
128 {
129 clearscr();
130 moveto(1, 1);
131 prints("说明档长度超过限制 (%d行),请返回修改", BBS_user_intro_max_line);
132 press_any_key();
133
134 ch = 'E';
135 continue;
136 }
137 break;
138 case 'C':
139 clearscr();
140 moveto(1, 1);
141 prints("取消更改...");
142 press_any_key();
143 goto cleanup;
144 case 'E':
145 ch = 'E';
146 continue;
147 default: // Invalid selection
148 continue;
149 }
150
151 break;
152 }
153
154 db = db_open();
155 if (db == NULL)
156 {
157 log_error("db_open() error: %s", mysql_error(db));
158 ret = -1;
159 goto cleanup;
160 }
161
162 // Secure SQL parameters
163 mysql_real_escape_string(db, intro_f, intro, (unsigned long)len_intro);
164
165 // Update user intro
166 snprintf(sql_intro, sizeof(sql_intro),
167 "UPDATE user_pubinfo SET introduction = '%s' WHERE UID=%d",
168 intro_f, uid);
169
170 if (mysql_query(db, sql_intro) != 0)
171 {
172 log_error("Update user_pubinfo error: %s", mysql_error(db));
173 ret = -2;
174 goto cleanup;
175 }
176
177 mysql_close(db);
178 db = NULL;
179
180 clearscr();
181 moveto(1, 1);
182 prints("说明档修改完成,会在%d秒内生效", BBS_user_list_load_interval);
183 press_any_key();
184 ret = 1; // Success
185
186 cleanup:
187 mysql_free_result(rs);
188 mysql_close(db);
189
190 // Cleanup buffers
191 editor_data_cleanup(p_editor_data);
192
193 return ret;
194 }
195
196 int user_sign_edit(int uid)
197 {
198 MYSQL *db = NULL;
199 MYSQL_RES *rs = NULL;
200 MYSQL_ROW row;
201 char sql_sign[SQL_BUFFER_LEN + 2 * BBS_user_sign_max_len + 1];
202 EDITOR_DATA *p_editor_data = NULL;
203 int ret = 0;
204 int ch = 0;
205 char sign[BBS_user_sign_max_len + 1];
206 char sign_f[BBS_user_sign_max_len * 2 + 1];
207 long len_sign = 0L;
208 long line_offsets[BBS_user_sign_max_line + 1];
209 long lines = 0L;
210 char buf[2] = "";
211 int sign_id = 0;
212
213 clearscr();
214 get_data(1, 1, "请输入需要编辑的签名档编号(1-3): ", buf, sizeof(buf), 1);
215 sign_id = atoi(buf);
216 if (sign_id < 1 || sign_id > BBS_user_sign_cnt)
217 {
218 ret = -1;
219 goto cleanup;
220 }
221
222 db = db_open();
223 if (db == NULL)
224 {
225 log_error("db_open() error: %s", mysql_error(db));
226 ret = -1;
227 goto cleanup;
228 }
229
230 snprintf(sql_sign, sizeof(sql_sign), "SELECT sign_%d FROM user_pubinfo WHERE UID=%d", sign_id, uid);
231 if (mysql_query(db, sql_sign) != 0)
232 {
233 log_error("Query user_pubinfo error: %s", mysql_error(db));
234 ret = -2;
235 goto cleanup;
236 }
237 if ((rs = mysql_store_result(db)) == NULL)
238 {
239 log_error("Get user_sign data failed");
240 ret = -2;
241 goto cleanup;
242 }
243 if ((row = mysql_fetch_row(rs)))
244 {
245 p_editor_data = editor_data_load(row[0] ? row[0] : "");
246 }
247 else
248 {
249 log_error("mysql_fetch_row() failed");
250 ret = -2;
251 goto cleanup;
252 }
253 mysql_free_result(rs);
254 rs = NULL;
255
256 mysql_close(db);
257 db = NULL;
258
259 for (ch = 'E'; !SYS_server_exit;)
260 {
261 if (ch == 'E')
262 {
263 editor_display(p_editor_data);
264 }
265
266 clearscr();
267 moveto(1, 1);
268 prints("(S)保存, (C)取消 or (E)再编辑? [S]: ");
269 iflush();
270
271 ch = igetch_t(BBS_max_user_idle_time);
272 switch (toupper(ch))
273 {
274 case KEY_NULL:
275 case KEY_TIMEOUT:
276 goto cleanup;
277 case CR:
278 case 'S':
279 len_sign = editor_data_save(p_editor_data, sign, BBS_user_sign_max_len);
280 if (len_sign < 0)
281 {
282 log_error("editor_data_save() error");
283 ret = -3;
284 goto cleanup;
285 }
286
287 if (check_badwords(sign, '*') < 0)
288 {
289 log_error("check_badwords(sign) error");
290 ret = -3;
291 goto cleanup;
292 }
293
294 lml_render(sign, sign_f, sizeof(sign_f), SCREEN_COLS, 0);
295
296 lines = split_data_lines(sign_f, SCREEN_COLS + 1, line_offsets, BBS_user_sign_max_line + 2, 1, NULL);
297 if (lines > BBS_user_sign_max_line)
298 {
299 clearscr();
300 moveto(1, 1);
301 prints("签名档长度超过限制 (%d行),请返回修改", BBS_user_sign_max_line);
302 press_any_key();
303
304 ch = 'E';
305 continue;
306 }
307 break;
308 case 'C':
309 clearscr();
310 moveto(1, 1);
311 prints("取消更改...");
312 press_any_key();
313 goto cleanup;
314 case 'E':
315 ch = 'E';
316 continue;
317 default: // Invalid selection
318 continue;
319 }
320
321 break;
322 }
323
324 db = db_open();
325 if (db == NULL)
326 {
327 log_error("db_open() error: %s", mysql_error(db));
328 ret = -1;
329 goto cleanup;
330 }
331
332 // Secure SQL parameters
333 mysql_real_escape_string(db, sign_f, sign, (unsigned long)len_sign);
334
335 // Update user sign
336 snprintf(sql_sign, sizeof(sql_sign),
337 "UPDATE user_pubinfo SET sign_%d = '%s' WHERE UID=%d",
338 sign_id, sign_f, uid);
339
340 if (mysql_query(db, sql_sign) != 0)
341 {
342 log_error("Update user_pubinfo error: %s", mysql_error(db));
343 ret = -2;
344 goto cleanup;
345 }
346
347 mysql_close(db);
348 db = NULL;
349
350 clearscr();
351 moveto(1, 1);
352 prints("签名档修改完成");
353 press_any_key();
354 ret = 1; // Success
355
356 cleanup:
357 mysql_free_result(rs);
358 mysql_close(db);
359
360 // Cleanup buffers
361 editor_data_cleanup(p_editor_data);
362
363 return ret;
364 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1