| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
| 17 |
#include "login.h" |
#include "login.h" |
|
#include "register.h" |
|
| 18 |
#include "bbs.h" |
#include "bbs.h" |
| 19 |
#include "user_priv.h" |
#include "user_priv.h" |
| 20 |
#include "common.h" |
#include "common.h" |
| 28 |
#include <regex.h> |
#include <regex.h> |
| 29 |
#include <unistd.h> |
#include <unistd.h> |
| 30 |
|
|
|
void login_fail() |
|
|
{ |
|
|
display_file_ex(DATA_LOGIN_ERROR, 1, 0); |
|
|
} |
|
|
|
|
| 31 |
int bbs_login(MYSQL *db) |
int bbs_login(MYSQL *db) |
| 32 |
{ |
{ |
| 33 |
char username[BBS_username_max_len + 1]; |
char username[BBS_username_max_len + 1]; |
| 55 |
|
|
| 56 |
if (strcmp(username, "new") == 0) |
if (strcmp(username, "new") == 0) |
| 57 |
{ |
{ |
| 58 |
if (user_register() == 0) |
display_file_ex(DATA_REGISTER, 1, 1); |
| 59 |
{ |
|
| 60 |
return 0; |
return 0; |
|
} |
|
|
else |
|
|
{ |
|
|
return -2; |
|
|
} |
|
| 61 |
} |
} |
| 62 |
|
|
| 63 |
if (username[0] != '\0') |
if (username[0] != '\0') |
| 71 |
} |
} |
| 72 |
|
|
| 73 |
ok = (check_user(db, username, password) == 0); |
ok = (check_user(db, username, password) == 0); |
| 74 |
|
iflush(); |
| 75 |
} |
} |
| 76 |
} |
} |
| 77 |
|
|
| 78 |
if (!ok) |
if (!ok) |
| 79 |
{ |
{ |
| 80 |
login_fail(); |
display_file_ex(DATA_LOGIN_ERROR, 1, 1); |
| 81 |
return -1; |
return -1; |
| 82 |
} |
} |
| 83 |
|
|
| 84 |
log_std("User \"%s\"(%ld) login from %s:%d\n", |
log_std("User \"%s\"(%ld) login from %s:%d\n", |
| 85 |
BBS_username, BBS_priv.uid, hostaddr_client, port_client); |
BBS_username, BBS_priv.uid, hostaddr_client, port_client); |
| 86 |
|
|
| 87 |
return 0; |
return 0; |
| 88 |
} |
} |
| 125 |
if (!ok) |
if (!ok) |
| 126 |
{ |
{ |
| 127 |
prints("\033[1;31m用户名或密码格式错误...\033[m\r\n"); |
prints("\033[1;31m用户名或密码格式错误...\033[m\r\n"); |
|
iflush(); |
|
| 128 |
return 1; |
return 1; |
| 129 |
} |
} |
| 130 |
|
|
| 167 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 168 |
|
|
| 169 |
prints("\033[1;31m来源存在多次失败登陆尝试,请稍后再试\033[m\r\n"); |
prints("\033[1;31m来源存在多次失败登陆尝试,请稍后再试\033[m\r\n"); |
|
iflush(); |
|
| 170 |
|
|
| 171 |
return 1; |
return 1; |
| 172 |
} |
} |
| 195 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 196 |
|
|
| 197 |
prints("\033[1;31m账户存在多次失败登陆尝试,请使用Web方式登录\033[m\r\n"); |
prints("\033[1;31m账户存在多次失败登陆尝试,请使用Web方式登录\033[m\r\n"); |
|
iflush(); |
|
| 198 |
|
|
| 199 |
return 1; |
return 1; |
| 200 |
} |
} |
| 247 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 248 |
|
|
| 249 |
prints("\033[1;31m您目前无权登陆...\033[m\r\n"); |
prints("\033[1;31m您目前无权登陆...\033[m\r\n"); |
|
iflush(); |
|
| 250 |
return 1; |
return 1; |
| 251 |
} |
} |
| 252 |
} |
} |
| 272 |
} |
} |
| 273 |
|
|
| 274 |
prints("\033[1;31m错误的用户名或密码...\033[m\r\n"); |
prints("\033[1;31m错误的用户名或密码...\033[m\r\n"); |
|
iflush(); |
|
| 275 |
return 1; |
return 1; |
| 276 |
} |
} |
| 277 |
|
|
| 290 |
break; |
break; |
| 291 |
case -1: // Load data error |
case -1: // Load data error |
| 292 |
prints("\033[1;31m读取用户数据错误...\033[m\r\n"); |
prints("\033[1;31m读取用户数据错误...\033[m\r\n"); |
|
iflush(); |
|
| 293 |
return -1; |
return -1; |
| 294 |
case -2: // Unused |
case -2: // Unused |
| 295 |
prints("\033[1;31m请通过Web登录更新用户许可协议...\033[m\r\n"); |
prints("\033[1;31m请通过Web登录更新用户许可协议...\033[m\r\n"); |
|
iflush(); |
|
| 296 |
return 1; |
return 1; |
| 297 |
case -3: // Dead |
case -3: // Dead |
| 298 |
prints("\033[1;31m很遗憾,您已经永远离开了我们的世界!\033[m\r\n"); |
prints("\033[1;31m很遗憾,您已经永远离开了我们的世界!\033[m\r\n"); |
|
iflush(); |
|
| 299 |
return 1; |
return 1; |
| 300 |
default: |
default: |
| 301 |
return -2; |
return -2; |