Mod aaa-12 修改用户认证接口,并移动.h文件到产品的common目录下
RCA: SOL: 修改人:zhouzian 检视人:zhouzian
This commit is contained in:
parent
d6d9c35eef
commit
653c06c16f
|
@ -202,7 +202,7 @@ static ret_code user_config_del_proc(uint source, uint config_type,
|
|||
// cJSON_AddItemToArray(user_id_del_success_json, cJSON_CreateNumber(user_id_del_success[j]));
|
||||
// }
|
||||
printf("需要下线的用户id:%s \n", cJSON_PrintUnformatted(user_id_del_success_json));
|
||||
offline_force_by_userid(cJSON_PrintUnformatted(user_id_del_success_json));
|
||||
//offline_force_by_userid(cJSON_PrintUnformatted(user_id_del_success_json));
|
||||
|
||||
/* 释放内存 */
|
||||
cJSON_Delete(root);
|
||||
|
|
|
@ -172,7 +172,7 @@ static ret_code usergroup_config_del_proc(uint source, uint config_type,
|
|||
cJSON_AddItemToArray(group_id_del_success_json, cJSON_CreateNumber(group_id_del_success[j]));
|
||||
}
|
||||
printf("需要下线的用户组id:%s \n", cJSON_PrintUnformatted(group_id_del_success_json));
|
||||
offline_force_by_groupid(cJSON_PrintUnformatted(group_id_del_success_json));
|
||||
//offline_force_by_groupid(cJSON_PrintUnformatted(group_id_del_success_json));
|
||||
|
||||
/* 处理返回结果 */
|
||||
ret_char = cJSON_PrintUnformatted(ret_json);
|
||||
|
|
|
@ -34,7 +34,7 @@ PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
|||
PLAT_ARM64_SRCS = $(COMMON_SRCS)
|
||||
|
||||
# gcc CFLAGS
|
||||
PLAT_ARM64_CFLAGS := -fPIC -I../../Common
|
||||
PLAT_ARM64_CFLAGS := -fPIC -I../../Common -I../common
|
||||
PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS)
|
||||
|
||||
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
#ifndef COMMON_USER_H_
|
||||
#define COMMON_USER_H_
|
||||
|
||||
#define SPECHAR(element) (strpbrk((element), "~!@#$%^&*()_+{}|:\"<>?\\,./;\'[]-=`")) //校验特殊字符
|
||||
#define GETID(ID, NAME1, NAME2) ((((ID) != 0) && (strcmp((NAME1), (NAME2)) == 0)) ? (ID) : 0) //根据name查询ID
|
||||
#define CHECKOUTARG(element) ((NULL == (element) || "" == (element) || SPECHAR(element)) ? true : false) //校验参数
|
||||
#define INVALID_INDEX (0)
|
||||
#define INIT_FAIL -1
|
||||
#define INIT_SUCCESS 0
|
||||
|
||||
#define TIME_T2STRING(time_int, time_char) (strftime((time_char), 20, "%Y-%m-%d %H:%M:%S", (localtime(&time_int))))
|
||||
#define STRING2TIME_T(time_char,time_int) \
|
||||
do { \
|
||||
struct tm tm_time; \
|
||||
int res = sscanf(time_char, "%4d-%2d-%2d %2d:%2d:%2d", \
|
||||
&tm_time.tm_year, &tm_time.tm_mon, &tm_time.tm_mday, \
|
||||
&tm_time.tm_hour, &tm_time.tm_min, &tm_time.tm_sec); \
|
||||
tm_time.tm_year -= 1900; \
|
||||
tm_time.tm_mon--; \
|
||||
tm_time.tm_isdst = -1; \
|
||||
time_int = mktime(&tm_time); \
|
||||
} while (0)
|
||||
|
||||
#define MULTI_MASK 0x0002
|
||||
#define VALID_MASK 0x0001
|
||||
|
||||
#define MULTI_GET(element) ((element) >> 1)
|
||||
#define MULTI_SET(element, value) (((element) & VALID_MASK) | (((value) << 1) & MULTI_MASK))
|
||||
#define VALID_GET(element) ((element) & VALID_MASK)
|
||||
#define VALID_SET(element, value) (((element) & MULTI_MASK) | ((value) & VALID_MASK))
|
||||
|
||||
#endif
|
|
@ -38,7 +38,8 @@ typedef struct user_auth_list
|
|||
|
||||
unsigned int online_num; //用户上线数量
|
||||
time_t lock_time; //用户锁定时间
|
||||
//unsigned int fail_num; //用户认证失败次数
|
||||
unsigned short group_id; //用户组id
|
||||
//unsigned int fail_num; //用户认证失败次数
|
||||
} USER_AUTH_LIST;
|
||||
|
||||
typedef struct user_auth_ret
|
||||
|
@ -50,9 +51,15 @@ typedef struct user_auth_ret
|
|||
} USER_AUTH_RET;
|
||||
|
||||
/* 用户认证 */
|
||||
void user_auth_login(char* username, char* password, time_t login_time, USER_AUTH_RET* auth_result);
|
||||
void user_auth_login(char* username, char* password, USER_AUTH_RET* auth_result);
|
||||
|
||||
/* 用户下线数-1 */
|
||||
/* 用户在线数-1 */
|
||||
void reduce_online_num(unsigned short user_id);
|
||||
|
||||
/* 用户在线节点重置-按用户id, num为user_ids数组长度 */
|
||||
void reset_online_by_userid(int *user_ids, int num);
|
||||
|
||||
/* 用户在线节点重置-按用户组id */
|
||||
void reset_online_by_groupid(int *group_ids);
|
||||
|
||||
#endif
|
|
@ -85,7 +85,10 @@ static int init_fail_time_queue(unsigned short user_id, int max_size)
|
|||
/* 清空认证失败时间队列,不释放内存 */
|
||||
static void empty_fail_time_queue(unsigned short user_id)
|
||||
{
|
||||
memset(AUTH_RECORD.fail_time, 0, sizeof(AUTH_RECORD.fail_time));
|
||||
if(NULL != AUTH_RECORD.fail_time)
|
||||
{
|
||||
memset(AUTH_RECORD.fail_time, 0, sizeof(AUTH_RECORD.fail_time));
|
||||
}
|
||||
AUTH_RECORD.front = 0;
|
||||
AUTH_RECORD.rear = 0;
|
||||
AUTH_RECORD.lock_time = 0;
|
||||
|
@ -227,7 +230,7 @@ static void get_from_json(char *user_name, USERACCOUNT *user_info)
|
|||
}
|
||||
|
||||
/* 用户认证 */
|
||||
void user_auth_login(char* username, char* password, time_t login_time, USER_AUTH_RET *auth_result)
|
||||
void user_auth_login(char* username, char* password, USER_AUTH_RET *auth_result)
|
||||
{
|
||||
unsigned short user_id, group_id;
|
||||
int init_queue_ret; //初始化循环列表的结果
|
||||
|
@ -235,10 +238,12 @@ void user_auth_login(char* username, char* password, time_t login_time, USER_AUT
|
|||
int config_lock_time = 0; //锁定后的锁定时间,锁定后
|
||||
int config_fail_num = 0; //规定时间内允许失败的次数,锁定次数,锁定前
|
||||
int config_fail_time = 0; //规定时间,失败的时间范围,锁定前
|
||||
time_t login_time; //登陆时间
|
||||
time_t remain_lock_time; //锁定剩余时间
|
||||
USERACCOUNT *user_info; //临时数据,存储登陆用户名对应的用户信息
|
||||
|
||||
memset(auth_result, 0, sizeof(USER_AUTH_RET));
|
||||
login_time = time(NULL);
|
||||
|
||||
//1、校验用户名和密码
|
||||
if (NULL == username || NULL == password || 0 == login_time)
|
||||
|
@ -279,6 +284,7 @@ void user_auth_login(char* username, char* password, time_t login_time, USER_AUT
|
|||
|
||||
user_id = user_info->ID;
|
||||
group_id = user_info->GID;
|
||||
AUTH_RECORD.group_id = group_id; //更新用户组id
|
||||
|
||||
/* 数据库查询 */
|
||||
/* SELECT id,group_id FROM `user` WHERE user_name = ""; */
|
||||
|
@ -393,3 +399,49 @@ void reduce_online_num(unsigned short user_id)
|
|||
AUTH_RECORD.online_num--;
|
||||
}
|
||||
}
|
||||
|
||||
/* 用户在线节点重置-按用户id */
|
||||
void reset_online_by_userid(int *user_ids, int num)
|
||||
{
|
||||
if(NULL == user_ids || 0 == num)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int user_id_temp = 0;
|
||||
for(int i = 0; i < num; i++)
|
||||
{
|
||||
user_id_temp = user_ids[i];
|
||||
if(0 != user_ids[i])
|
||||
{
|
||||
empty_fail_time_queue(user_id_temp);
|
||||
g_user_auth_ret_table[user_id_temp].fail_time = 0;
|
||||
g_user_auth_ret_table[user_id_temp].group_id = 0;
|
||||
g_user_auth_ret_table[user_id_temp].max_size = 0;
|
||||
g_user_auth_ret_table[user_id_temp].online_num = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 用户在线节点重置-按用户组id */
|
||||
void reset_online_by_groupid(int *group_ids)
|
||||
{
|
||||
if(NULL == group_ids)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned short group_id_temp = 0;
|
||||
for(int i = 0; i < AUTH_USER_INDEX_MAX; i++)
|
||||
{
|
||||
group_id_temp = g_user_auth_ret_table[i].group_id;
|
||||
if(0 != group_id_temp && group_id_temp == group_ids[group_id_temp])
|
||||
{
|
||||
empty_fail_time_queue(i);
|
||||
g_user_auth_ret_table[i].fail_time = 0;
|
||||
g_user_auth_ret_table[i].group_id = 0;
|
||||
g_user_auth_ret_table[i].max_size = 0;
|
||||
g_user_auth_ret_table[i].online_num = 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@
|
|||
#include "user.h"
|
||||
#include "user_account_config.h"
|
||||
#include "user_group_config.h"
|
||||
#include "../usermanager-auth/user_auth.h"
|
||||
#include "user_auth.h"
|
||||
|
||||
|
||||
extern USERGROUP g_group_table[GROUP_INDEX_MAX];
|
||||
|
@ -431,7 +431,7 @@ int main(void)
|
|||
printf("*******************************************************************************\n");
|
||||
UCHAR_FREE(output5);
|
||||
|
||||
USER_AUTH_RET* aret;
|
||||
USER_AUTH_RET *aret;
|
||||
aret = (USER_AUTH_RET*)malloc(sizeof(USER_AUTH_RET));
|
||||
if (NULL == aret)
|
||||
{
|
||||
|
@ -439,42 +439,61 @@ int main(void)
|
|||
}
|
||||
time_t t1 = time(NULL);
|
||||
|
||||
user_auth_login("用户05", "zhelishidenglumima", t1, aret);
|
||||
user_auth_login("用户05", "zhelishidenglumima", aret);
|
||||
printf("%d,%d,%d\n", aret->ret, aret->user_id, aret->group_id);
|
||||
|
||||
sleep(1);
|
||||
t1 = time(NULL);
|
||||
user_auth_login("用户05", "zhelishidenglumima", t1, aret);
|
||||
printf("%d,%d,%d\n", aret->ret, aret->user_id, aret->group_id);
|
||||
USER_AUTH_RET aret01;
|
||||
user_auth_login("用户05", "zhelishidenglumima", &aret01);
|
||||
printf("%d,%d,%d\n", aret01.ret, aret01.user_id, aret01.group_id);
|
||||
|
||||
sleep(1);
|
||||
t1 = time(NULL);
|
||||
user_auth_login("用户05", "zhelishidenglumima", t1, aret);
|
||||
user_auth_login("用户05", "zhelishidenglumima", aret);
|
||||
printf("%d,%d,%d\n",aret->ret,aret->user_id,aret->group_id);
|
||||
|
||||
sleep(1);
|
||||
t1 = time(NULL);
|
||||
user_auth_login("用户05", "zhelishidenglumima", t1, aret);
|
||||
user_auth_login("用户05", "zhelishidenglumima", aret);
|
||||
printf("%d,%d,%d\n", aret->ret, aret->user_id, aret->group_id);
|
||||
|
||||
sleep(1);
|
||||
t1 = time(NULL);
|
||||
user_auth_login("用户05", "zhelishidenglumima", t1, aret);
|
||||
user_auth_login("用户05", "zhelishidenglumima", aret);
|
||||
printf("%d,%d,%d\n", aret->ret, aret->user_id, aret->group_id);
|
||||
|
||||
sleep(1);
|
||||
t1 = time(NULL);
|
||||
user_auth_login("用户05", "zhelishidenglumima", t1, aret);
|
||||
user_auth_login("用户05", "zhelishidenglumima", aret);
|
||||
printf("%d,%d,%d\n", aret->ret, aret->user_id, aret->group_id);
|
||||
|
||||
mod_user_line("用户05", 6, "2020-03-03 15:04:23");
|
||||
sleep(4);
|
||||
sleep(1);
|
||||
t1 = time(NULL);
|
||||
user_auth_login("用户05", "zhelishidenglumima", t1, aret);
|
||||
user_auth_login("用户05", "zhelishidenglumima", aret);
|
||||
printf("%d,%d,%d\n", aret->ret, aret->user_id, aret->group_id);
|
||||
|
||||
|
||||
char * output6;
|
||||
output6 = malloc(100);
|
||||
if (NULL == output6)
|
||||
{
|
||||
printf("ulist fail");
|
||||
}
|
||||
char *testin6 = "{\"type\": 1,\"data\":[\"用户01\", \"用户02\", \"用户04\", \"用户05\"]}";
|
||||
int a6_01 = 1;
|
||||
int *a6 = &a6_01;;
|
||||
ret_code c6 = user_config_proc(1, 1, testin6, 1, output6, a6);
|
||||
|
||||
printf("*******************************************************************************\n");
|
||||
printf("这里是个测试第六次结果,删除用户05:%d\n", c4);
|
||||
printf("%s\n", output6);
|
||||
printf("*******************************************************************************\n");
|
||||
UCHAR_FREE(output6);
|
||||
|
||||
int user_ids[3] = {1,2,4};
|
||||
reset_online_by_userid(user_ids, 3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue