/[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.5 - (show annotations)
Tue Nov 11 00:28:05 2025 UTC (4 months ago) by sysadm
Branch: MAIN
Changes since 1.4: +4 -0 lines
Content type: text/x-csrc
Use config.h

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

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