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