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

Annotation of /lbbs/src/user_info_update.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Fri Nov 7 06:46:44 2025 UTC (4 months, 1 week ago) by sysadm
Branch: MAIN
Changes since 1.1: +8 -0 lines
Content type: text/x-csrc
Apply BWF to user_intro_edit()

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

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