提交 3a6b1b8e 编写于 作者: 小刘28's avatar 小刘28 💬

feat:完成登录功能;

上级 a2fbd646
......@@ -4,7 +4,9 @@ import com.ubitgroup.data.AccountT;
import com.ubitgroup.model.bean.Account;
import com.ubitgroup.model.bean.Result;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.UUID;
/*
* 登录页面控制器
......@@ -15,7 +17,7 @@ public class LoginC {
* */
public Result login(Account account){
AccountT accountT = AccountT.getInstance();
Integer type = accountT.login(account);
Integer type = accountT.getByAccoPass(account);
String data;
switch (type){
case 0:
......@@ -41,8 +43,30 @@ public class LoginC {
* 注册处理
* */
public Result regi(Account account){
return Result.success(null);
AccountT accountT = AccountT.getInstance();
Integer count = accountT.getByAcco(account);
String data;
switch (count){
case 0:
// 插入数据
account.setId(UUID.randomUUID().toString());
account.setCreateTime(LocalDateTime.now());
account.setUpdateTime(LocalDateTime.now());
if (accountT.add(account)) {
return Result.success(null);
}else{
data = "注册出错了,请联系管理员!";
return Result.error(500,data);
}
case 1:
// 提示账号已存在
data = "账号已存在,请重新输入!";
return Result.error(1,data);
default:
// 系统出错了
data = "注册出错了,请联系管理员!";
return Result.error(500,data);
}
}
/*
* 找回密码处理
......
......@@ -81,25 +81,6 @@ public class AccountT {
return count;
}
/*
* 登录
* */
public Integer login(Account account){
int type = 1; // 0:账号和密码都正确,1:账号不存在,2:密码错误
for (int i = 0; i < arrayList.size(); i++) {
Account accountTemp = arrayList.get(i);
if(accountTemp.getAccount().equals(account.getAccount())){
if (accountTemp.getPassword().equals(account.getPassword())){
type = 0;
}else{
type = 2;
}
return type;
}
}
return type;
}
/*
* 获取账号通过参数
* 未排除禁用的和已被删除的
......@@ -138,4 +119,37 @@ public class AccountT {
return arrayListTemp;
}
/*
* 通过账号和密码查找
* */
public Integer getByAccoPass(Account account){
int type = 1; // 0:账号和密码都正确,1:账号不存在,2:密码错误
for (int i = 0; i < arrayList.size(); i++) {
Account accountTemp = arrayList.get(i);
if(accountTemp.getAccount().equals(account.getAccount())){
if (accountTemp.getPassword().equals(account.getPassword())){
type = 0;
}else{
type = 2;
}
return type;
}
}
return type;
}
/*
* 通过账号查找
* */
public Integer getByAcco(Account account){
int count = 0; // 0:账号和密码都正确,1:账号不存在,2:密码错误
for (int i = 0; i < arrayList.size(); i++) {
Account accountTemp = arrayList.get(i);
if(accountTemp.getAccount().equals(account.getAccount())){
return ++count;
}
}
return count;
}
}
......@@ -4,7 +4,7 @@ package com.ubitgroup.model.bean;
* 响应类
* */
public class Result {
// 响应状态码,0:成功,1:失败
// 响应状态码,0:成功,1:失败,...
private Integer code;
// 响应信息
private String msg;
......@@ -73,10 +73,17 @@ public class Result {
}
/*
* 成功的结果
* 成功的结果,data
* */
public static Result success(Object data){
return new Result(0,"success",data);
return new Result(0,"成功!",data);
}
/*
* 成功的结果,msg,data
* */
public static Result success(String msg,Object data){
return new Result(0,msg,data);
}
/*
......
......@@ -97,8 +97,20 @@ public class LoginV {
if (inteOper(password)){
break;
}
System.out.println("账号:" + account);
System.out.println("密码:" + password);
Account accountTemp = new Account();
accountTemp.setAccount(account);
accountTemp.setPassword(password);
LoginC loginC = new LoginC();
Result result = loginC.regi(accountTemp);
if (result.getCode() == 0){
System.out.println("注册成功,请登录!");
break;
// CurrAcc currAcc = CurrAcc.getInstance();
// currAcc.setAccount((Account)result.getData());
// new MainV().init();
}else{
System.out.println(result.getMsg());
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册