#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include"Account.h"
#include"../Common/List.h"
#include"../Persistence/EntityKey_Persist.h"
#include"../Persistence/Account_Persist.h"
#include"../Common/passwd.h"
static const char*accountfile="Account.dat";
static const char *keyname="Account";
void Account_Srv_FirstLogIn(){//第一次登陆,要求用户申请管理员帐号
if(access(accountfile,0)){
printf("\n\t\t======================================================================================");
printf("\n\t\t*****************************Welcome to use the system********************************");
printf("\n\n\n\t\tYou are the first time to come in this system!Please apply a account number!\n");
account_node_t*p,*h;
List_Init(h,account_node_t);
p=NULL;
p=(account_node_t*)malloc(sizeof(account_node_t));
p->data.type=9;
p->data.id=EntKey_Perst_GetNewKeys(keyname);
while(1){
printf("\n\n\t\tPlease input you phone number:");
scanf("%[^\n]",p->data.phoneNum);
while('\n'!=getchar());
if(strlen(p->data.phoneNum)==11){
break;
}
printf("\n\t\tPlease input correct phone number!\n");
}
printf("\n\t\tPlease input user name:");
scanf("%[^\n]",p->data.username);
while('\n'!=getchar());
while(strlen(p->data.username)<2){
printf("\n\t\tPlease Input again!\n\n");
scanf("%[^\n]",p->data.username);
while('\n'!=getchar());
}
char* ps;
set_disp_mode(STDIN_FILENO,0);
getpasswd(p->data.password, sizeof(p->data.password));
ps=p->data.password;
while(*ps!='\n')
ps++;
*ps='\0';
set_disp_mode(STDIN_FILENO,1);
List_AddTail(h,p);
if(Account_Perst_Insert(h)==0){
printf("\n\t\tAdd administritor failed!\n");
remove("account.dat");
return;
}
printf("\n\t\tCongratulation!You are the first [adminastrater] in this system!\n");
printf("\n\t\tPress [Enter] to return ......");
while('\n'!=getchar());
return ;
}else{
return;
}
}
int Account_Srv_SearchPass(account_node_t*p){//验证用户信息
if(Account_Perst_SearchInfo(p)==0){
return 0;
}
printf("\n\t\tVirified succeed!\n");
printf("\n\t\tPress [Enter] to return.....");
while('\n'!=getchar());
char* ps;
set_disp_mode(STDIN_FILENO,0);
getpasswd(p->data.password, sizeof(p->data.password));
ps=p->data.password;
while(*ps!='\n')
ps++;
*ps='\0';
set_disp_mode(STDIN_FILENO,1);
if(Account_Perst_Modify(p)==0){
return 0;
}
return 1;
}
int Account_Srv_LogIn(){//用户登录
account_node_t *p=NULL;
p=(account_node_t*)malloc(sizeof(account_node_t));
printf("\n\t\t=====================================================================================");
printf("\n\n\t\tInput user number:");
scanf("%[^\n]",p->data.username);
while('\n'!=getchar());
while(1){
char* ps;
set_disp_mode(STDIN_FILENO,0);
getpasswd(p->data.password, sizeof(p->data.password));
ps=p->data.password;
while(*ps!='\n')
ps++;
*ps='\0';
set_disp_mode(STDIN_FILENO,1);
if(strlen(p->data.password)<6){
printf("\n\t\tThe password is too short!\n");
}
else{
break;
}
}
if(Account_Perst_JudgeInfo(p)==0){
printf("\n\t\tLog Fail!\n");
return 0;
}
return 1;
}
int Account_Srv_Add(){//添加用户信息
account_node_t *h,*p,*testHead,*temp;
char choice;
List_Init(testHead,account_node_t);
List_Init(h,account_node_t);
while(1){
p=(account_node_t*)malloc(sizeof(account_node_t));
printf("\n\t\tInput user username:");
scanf("%[^\n]",p->data.username);
while('\n'!=getchar());
while(strlen(p->data.username)<2){
printf("\n\t\tUser name is too short,try again!");
printf("\n");
printf("\n\t\tInput user name:");
scanf("%[^\n]",p->data.username);
while('\n'!=getchar());
}
if(Account_Perst_FetchAll(testHead)){
temp=testHead->next;
while(temp!=testHead){
if(strcmp(temp->data.username,p->data.username)==0){
printf("\n\n\t\tThis user has exist!");
printf("\n\n\t\tPress [Enter] to return.....");
while('\n'!=getchar());
return 0;
}
temp=temp->next;
}
}
printf("\n\n\t\t User_Type:[M]Manager [A]Administrater [S]Salesman [O]Other user\n");
printf("\n\n\t\tInput user type:");
choice=getchar();
while('\n'!=getchar());
if(choice=='o'||choice=='O')p->data.type=USR_ANOMY;
else if(choice=='M'||choice=='m')p->data.type=USR_MANG;
else if(choice=='s'||choice=='S')p->data.type=USR_CLERK;
else if(choice=='A'||choice=='a')p->data.type=USR_ADMIN;
else {
printf("\n\t\tChoice is not exsist!");
return 0;
}
p->data.id=EntKey_Perst_GetNewKeys(keyname);
while(1){
printf("\n\t\tPlease input user phone number:");
scanf("%[^\n]",p->data.phoneNum);
while('\n'!=getchar());
if(strlen(p->data.phoneNum)==11){
break;
}
printf("\n\t\tPlease input correct number!\n");
}
while(1){
char* ps;
set_disp_mode(STDIN_FILENO,0);
getpasswd(p->data.password, sizeof(p->data.password));
ps=p->data.password;
while(*ps!='\n')
ps++;
*ps='\0';
set_disp_mode(STDIN_FILENO,1);
if(strlen(p->data.password)<6){
printf("\n\t\tThe password is too short!\n");
}
else{
break;
}
}
List_AddTail(h,p);
printf("\n\t\t[E]Exit [C]Continue\n");
printf("\n\n\t\tInput you choice:");
choice=getchar();
while('\n'!=getchar());
if(choice=='e'||choice=='E')break;
}
if(Account_Perst_Insert(h)==0){
return 0;
}
printf("\n\t\tAdd user successfully!Press [Enter] to return......");
while('\n'!=getchar());
return 1;
}
int Account_Srv_Delete(){//删除用户信息
if(Account_Perst_Delete()==0){
return 0;
}
return 1;
}
int Account_Srv_UserLogIn1(account_node_t* temp){//分类,用户登陆
printf("\n\t\t============================================================================================");
printf("\n\t\t**************************************User log in*******************************************");
printf("\n\t\t============================================================================================");
account_node_t* h;
List_Init(h,account_node_t);
if(Account_Perst_FetchAll(h)==0){
printf("\n\t\tNo user,press [Enter] to return.....");
while('\n'!=getchar());
return 0;
}
int ch;
printf("\n\t\t============================================================================================");
printf("\n\t\t\t0.Others 1.Salesman 2.Manager 9.Administrater");
printf("\n\t\t============================================================================================");
printf("\n\n\t\tChoose user type:");
scanf("%d",&ch);
while('\n'!=getchar());
temp->data.type=ch;
printf("\n\t\tInput user number:");
scanf("%[^\n]",temp->data.username);
while('\n'!=getchar());
while(1){
char* ps;
set_disp_mode(STDIN_FILENO,0);
getpasswd(temp->data.password, sizeof(temp->data.password));
ps=temp->data.password;
while(*ps!='\n')
ps++;
*ps='\0';
set_disp_mode(STDIN_FILENO,1);
if(strlen(temp->data.password)<6){
printf("\n\t\tThe password is too short!\n");
}
else{
break;
}
}
account_node_t* p;
p=h->next;
while(p!=h){
if(strcmp(p->data.username,temp->data.username)==0&&strcmp(p->data.password,temp->data.password)==0&&(temp->data.type==p->data.type)){
temp->data.id=p->data.id;
strcpy(temp->data.phoneNum,p->data.phoneNum);
return 1;
}
p=p->next;
}
free(temp);
printf("\n\t\tLog fail!");
while('\n'!=getchar());
system("clear");
return 0;
}
int Account_Srv_UserLogIn(account_node_t* temp){//用户登录
printf("\n\t\t=====================================
猰貐的新时代
- 粉丝: 1w+
- 资源: 2886
最新资源
- 蚁群算法小程序-matlab
- 粒子群算法小程序-matlab
- 《新能源接入的电力市场主辅联合出清》 出清模型以考虑安全约束的机组组合模型(SCUC)和经济调度模型(SCED)组成 程序基于IEEE30节点编写,并接入风电机组参与电力市场,辅助服务市场为备用市场
- 个人创作原画作品,禁止盗用
- 遗传算法程序-matlab
- 游戏人物检测15-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- Windows 7安装NET补丁
- 高动态导航技术全套技术资料.zip
- cms测试练习项目(linux系统部署)
- 游戏人物检测15-YOLO(v5至v9)、COCO、CreateML、Darknet、Paligemma、TFRecord数据集合集.rar
- 名城小区物业管理-JAVA-基于Spring boot的名城小区物业管理系统设计实现(毕业论文+开题)
- 多媒体素材库-JAVA-基于springboot的多媒体素材库的开发与应用(毕业论文)
- 大学生心理健康管理-JAVA-基于springBoot大学生心理健康管理系统的设计与实现(毕业论文)
- 论坛系统-JAVA-基于SpringBoot的论坛系统设计与实现(毕业论文+开题+PPT)
- 游戏人物检测17-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- 大学生智能消费记账-JAVA-springboot205大学生智能消费记账系统的设计与实现(毕业论文)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈