/[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.4 - (show annotations)
Sat Nov 8 10:01:47 2025 UTC (4 months, 1 week ago) by sysadm
Branch: MAIN
Changes since 1.3: +0 -2 lines
Content type: text/x-csrc
Remove unused macro definition

1 /* SPDX-License-Identifier: GPL-3.0-or-later */
2 /*
3 * user_info_update
4 * - update user information
5 *
6 * Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com>
7 *
8 * Author: ytht <2391669999@qq.com>
9 */
10
11 #include "bbs.h"
12 #include "bwf.h"
13 #include "database.h"
14 #include "editor.h"
15 #include "io.h"
16 #include "lml.h"
17 #include "log.h"
18 #include "screen.h"
19 #include "str_process.h"
20 #include "user_list.h"
21 #include "user_priv.h"
22 #include <ctype.h>
23 #include <stdlib.h>
24 #include <sys/param.h>
25
26 int user_intro_edit(int uid)
27 {
28 MYSQL *db = NULL;
29 MYSQL_RES *rs = NULL;
30 MYSQL_ROW row;
31 char sql_intro[SQL_BUFFER_LEN + 2 * BBS_user_intro_max_len + 1];
32 EDITOR_DATA *p_editor_data = NULL;
33 int ret = 0;
34 int ch = 0;
35 char intro[BBS_user_intro_max_len + 1];
36 char intro_f[BBS_user_intro_max_len * 2 + 1];
37 long len_intro = 0L;
38 long line_offsets[BBS_user_intro_max_line + 1];
39 long lines = 0L;
40
41 db = db_open();
42 if (db == NULL)
43 {
44 log_error("db_open() error: %s\n", mysql_error(db));
45 ret = -1;
46 goto cleanup;
47 }
48
49 snprintf(sql_intro, sizeof(sql_intro), "SELECT introduction FROM user_pubinfo WHERE UID=%d", uid);
50 if (mysql_query(db, sql_intro) != 0)
51 {
52 log_error("Query user_pubinfo error: %s\n", mysql_error(db));
53 ret = -2;
54 goto cleanup;
55 }
56 if ((rs = mysql_store_result(db)) == NULL)
57 {
58 log_error("Get user_intro data failed\n");
59 ret = -2;
60 goto cleanup;
61 }
62 if ((row = mysql_fetch_row(rs)))
63 {
64 p_editor_data = editor_data_load(row[0] ? row[0] : "");
65 }
66 else
67 {
68 log_error("mysql_fetch_row() failed\n");
69 ret = -2;
70 goto cleanup;
71 }
72 mysql_free_result(rs);
73 rs = NULL;
74 mysql_close(db);
75 db = NULL;
76
77 for (ch = 'E'; !SYS_server_exit;)
78 {
79 if (ch == 'E')
80 {
81 editor_display(p_editor_data);
82 }
83
84 clearscr();
85 moveto(1, 1);
86 prints("(S)保存, (C)取消 or (E)再编辑? [S]: ");
87 iflush();
88
89 ch = igetch_t(BBS_max_user_idle_time);
90 switch (toupper(ch))
91 {
92 case KEY_NULL:
93 case KEY_TIMEOUT:
94 goto cleanup;
95 case CR:
96 case 'S':
97 len_intro = editor_data_save(p_editor_data, intro, BBS_user_intro_max_len);
98 if (len_intro < 0)
99 {
100 log_error("editor_data_save() error\n");
101 ret = -3;
102 goto cleanup;
103 }
104
105 if (check_badwords(intro, '*') < 0)
106 {
107 log_error("check_badwords(introduction) error\n");
108 ret = -3;
109 goto cleanup;
110 }
111
112 lml_render(intro, intro_f, sizeof(intro_f), SCREEN_COLS, 0);
113
114 lines = split_data_lines(intro_f, SCREEN_COLS + 1, line_offsets, BBS_user_intro_max_line + 2, 1, NULL);
115 if (lines > BBS_user_intro_max_line)
116 {
117 clearscr();
118 moveto(1, 1);
119 prints("说明档长度超过限制 (%d行),请返回修改", BBS_user_intro_max_line);
120 press_any_key();
121
122 ch = 'E';
123 continue;
124 }
125 break;
126 case 'C':
127 clearscr();
128 moveto(1, 1);
129 prints("取消更改...");
130 press_any_key();
131 goto cleanup;
132 case 'E':
133 ch = 'E';
134 continue;
135 default: // Invalid selection
136 continue;
137 }
138
139 break;
140 }
141
142 db = db_open();
143 if (db == NULL)
144 {
145 log_error("db_open() error: %s\n", mysql_error(db));
146 ret = -1;
147 goto cleanup;
148 }
149
150 // Secure SQL parameters
151 mysql_real_escape_string(db, intro_f, intro, (unsigned long)len_intro);
152
153 // Update user intro
154 snprintf(sql_intro, sizeof(sql_intro),
155 "UPDATE user_pubinfo SET introduction = '%s' WHERE UID=%d",
156 intro_f, uid);
157
158 if (mysql_query(db, sql_intro) != 0)
159 {
160 log_error("Update user_pubinfo error: %s\n", mysql_error(db));
161 ret = -2;
162 goto cleanup;
163 }
164
165 mysql_close(db);
166 db = NULL;
167
168 clearscr();
169 moveto(1, 1);
170 prints("说明档修改完成,会在%d秒内生效", BBS_user_list_load_interval);
171 press_any_key();
172 ret = 1; // Success
173
174 cleanup:
175 mysql_free_result(rs);
176 mysql_close(db);
177
178 // Cleanup buffers
179 editor_data_cleanup(p_editor_data);
180
181 return ret;
182 }

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