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

Diff of /lbbs/src/user_info_update.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.5 by sysadm, Tue Nov 11 00:28:05 2025 UTC Revision 1.8 by sysadm, Sat Jan 3 10:27:14 2026 UTC
# Line 3  Line 3 
3   * user_info_update   * user_info_update
4   *   - update user information   *   - update user information
5   *   *
6   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>   * Copyright (C) 2004-2026  Leaflet <leaflet@leafok.com>
7   *   *
8   * Author:                  ytht <2391669999@qq.com>   * Co-author:               老黑噜 <2391669999@qq.com>
9   */   */
10    
11  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
# Line 21  Line 21 
21  #include "log.h"  #include "log.h"
22  #include "screen.h"  #include "screen.h"
23  #include "str_process.h"  #include "str_process.h"
24    #include "user_info_update.h"
25  #include "user_list.h"  #include "user_list.h"
26  #include "user_priv.h"  #include "user_priv.h"
27  #include <ctype.h>  #include <ctype.h>
28  #include <stdlib.h>  #include <stdlib.h>
29  #include <sys/param.h>  #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)  int user_intro_edit(int uid)
39  {  {
40          MYSQL *db = NULL;          MYSQL *db = NULL;
# Line 45  int user_intro_edit(int uid) Line 53  int user_intro_edit(int uid)
53          db = db_open();          db = db_open();
54          if (db == NULL)          if (db == NULL)
55          {          {
56                  log_error("db_open() error: %s\n", mysql_error(db));                  log_error("db_open() error: %s", mysql_error(db));
57                  ret = -1;                  ret = -1;
58                  goto cleanup;                  goto cleanup;
59          }          }
# Line 53  int user_intro_edit(int uid) Line 61  int user_intro_edit(int uid)
61          snprintf(sql_intro, sizeof(sql_intro), "SELECT introduction FROM user_pubinfo WHERE UID=%d", uid);          snprintf(sql_intro, sizeof(sql_intro), "SELECT introduction FROM user_pubinfo WHERE UID=%d", uid);
62          if (mysql_query(db, sql_intro) != 0)          if (mysql_query(db, sql_intro) != 0)
63          {          {
64                  log_error("Query user_pubinfo error: %s\n", mysql_error(db));                  log_error("Query user_pubinfo error: %s", mysql_error(db));
65                  ret = -2;                  ret = -2;
66                  goto cleanup;                  goto cleanup;
67          }          }
68          if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
69          {          {
70                  log_error("Get user_intro data failed\n");                  log_error("Get user_intro data failed");
71                  ret = -2;                  ret = -2;
72                  goto cleanup;                  goto cleanup;
73          }          }
# Line 69  int user_intro_edit(int uid) Line 77  int user_intro_edit(int uid)
77          }          }
78          else          else
79          {          {
80                  log_error("mysql_fetch_row() failed\n");                  log_error("mysql_fetch_row() failed");
81                  ret = -2;                  ret = -2;
82                  goto cleanup;                  goto cleanup;
83          }          }
# Line 101  int user_intro_edit(int uid) Line 109  int user_intro_edit(int uid)
109                          len_intro = editor_data_save(p_editor_data, intro, BBS_user_intro_max_len);                          len_intro = editor_data_save(p_editor_data, intro, BBS_user_intro_max_len);
110                          if (len_intro < 0)                          if (len_intro < 0)
111                          {                          {
112                                  log_error("editor_data_save() error\n");                                  log_error("editor_data_save() error");
113                                  ret = -3;                                  ret = -3;
114                                  goto cleanup;                                  goto cleanup;
115                          }                          }
116    
117                          if (check_badwords(intro, '*') < 0)                          if (check_badwords(intro, '*') < 0)
118                          {                          {
119                                  log_error("check_badwords(introduction) error\n");                                  log_error("check_badwords(introduction) error");
120                                  ret = -3;                                  ret = -3;
121                                  goto cleanup;                                  goto cleanup;
122                          }                          }
# Line 146  int user_intro_edit(int uid) Line 154  int user_intro_edit(int uid)
154          db = db_open();          db = db_open();
155          if (db == NULL)          if (db == NULL)
156          {          {
157                  log_error("db_open() error: %s\n", mysql_error(db));                  log_error("db_open() error: %s", mysql_error(db));
158                  ret = -1;                  ret = -1;
159                  goto cleanup;                  goto cleanup;
160          }          }
# Line 161  int user_intro_edit(int uid) Line 169  int user_intro_edit(int uid)
169    
170          if (mysql_query(db, sql_intro) != 0)          if (mysql_query(db, sql_intro) != 0)
171          {          {
172                  log_error("Update user_pubinfo error: %s\n", mysql_error(db));                  log_error("Update user_pubinfo error: %s", mysql_error(db));
173                  ret = -2;                  ret = -2;
174                  goto cleanup;                  goto cleanup;
175          }          }
# Line 175  int user_intro_edit(int uid) Line 183  int user_intro_edit(int uid)
183          press_any_key();          press_any_key();
184          ret = 1; // Success          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:  cleanup:
357          mysql_free_result(rs);          mysql_free_result(rs);
358          mysql_close(db);          mysql_close(db);


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

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