修改登录接口,返回json,补充V3.0beta接口文档
This commit is contained in:
71
API.md
Normal file
71
API.md
Normal file
@@ -0,0 +1,71 @@
|
||||
# V3.0 Beta API文档(不稳定)
|
||||
## 登录
|
||||
**请求URL:**
|
||||
- ` http://s4.fjy8018.top:8085/cms/login/dologin `
|
||||
|
||||
**请求方式:**
|
||||
- POST
|
||||
|
||||
**参数:**
|
||||
|
||||
| 参数名 | 必选 | 类型 | 说明 |
|
||||
| :---------- | :--- | :----- | ---- |
|
||||
| colname | 是 | string | 无 |
|
||||
| colpassword | 是 | string | 无 |
|
||||
|
||||
|
||||
**返回示例**
|
||||
|
||||
``` json
|
||||
{
|
||||
"code": 0,
|
||||
"message": "成功",
|
||||
"data": {
|
||||
"coluserid": 1,
|
||||
"colname": "root",
|
||||
"colpassword": null,
|
||||
"colemail": "root@gmail.com",
|
||||
"colstudentno": "00001",
|
||||
"colrealname": "admin"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 指定课程和作业名,返回未交人员名单
|
||||
|
||||
**请求URL:**
|
||||
|
||||
- ` http://s4.fjy8018.top:8085/cms/home/admin/findStudentInCourseFile?Folder=第一次作业&CourseName=信息安全 `
|
||||
|
||||
**请求方式:**
|
||||
- GET
|
||||
|
||||
**参数:**
|
||||
|
||||
| 参数名 | 必选 | 类型 | 说明 |
|
||||
| :---------- | :--- | :----- | ---- |
|
||||
| colname | 是 | string | 无 |
|
||||
| colpassword | 是 | string | 无 |
|
||||
|
||||
|
||||
**返回示例**
|
||||
|
||||
``` json
|
||||
[
|
||||
{
|
||||
"listid": 1,
|
||||
"colstudentno": "14251101208",
|
||||
"colrealname": "廖俊宝",
|
||||
"sex": "男",
|
||||
"registered": 1
|
||||
},
|
||||
{
|
||||
"listid": 2,
|
||||
"colstudentno": "15251101201",
|
||||
"colrealname": "麦贵淇",
|
||||
"sex": "男",
|
||||
"registered": 1
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
3
pom.xml
3
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>com.fjy</groupId>
|
||||
<artifactId>spring</artifactId>
|
||||
<version>V2.9.12</version>
|
||||
<version>V3.0.0 beta</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>spring</name>
|
||||
@@ -22,6 +22,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<skipTests>true</skipTests>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
package com.fjy.spring.controller;
|
||||
|
||||
import com.fjy.spring.domain.Result;
|
||||
import com.fjy.spring.domain.TbAdmin;
|
||||
import com.fjy.spring.domain.TbLog;
|
||||
import com.fjy.spring.domain.TbUser;
|
||||
import com.fjy.spring.enums.ResultEnum;
|
||||
import com.fjy.spring.properties.ServerProperties;
|
||||
import com.fjy.spring.service.AdminService;
|
||||
import com.fjy.spring.service.LogService;
|
||||
import com.fjy.spring.service.UserService;
|
||||
import com.fjy.spring.untils.CodingUtil;
|
||||
import com.fjy.spring.untils.GetIPAddrUtil;
|
||||
import com.fjy.spring.untils.ResultUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -27,7 +27,7 @@ import java.util.Optional;
|
||||
|
||||
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
|
||||
|
||||
@Controller
|
||||
@RestController
|
||||
public class LoginController {
|
||||
@Autowired
|
||||
private ServerProperties serverProperties;
|
||||
@@ -42,7 +42,7 @@ public class LoginController {
|
||||
HttpServletRequest request;
|
||||
|
||||
@PostMapping("/login/dologin")
|
||||
public String doLogin(TbUser tbUser)throws Exception{
|
||||
public Result doLogin(TbUser tbUser)throws Exception{
|
||||
//加密用户密码
|
||||
tbUser.setColpassword(new BigInteger(CodingUtil.encryptSHA(tbUser.getColpassword().getBytes())).toString(32));
|
||||
TbUser user = userService.doLoginService(tbUser.getColname(),tbUser.getColpassword());
|
||||
@@ -66,10 +66,9 @@ public class LoginController {
|
||||
log.setColip(GetIPAddrUtil.getIpAddr(request));
|
||||
logService.addLogRec(log);
|
||||
|
||||
return "redirect:" + request.getScheme() + "://" + request.getServerName() + ":"
|
||||
+ serverProperties.getPortNum() + request.getContextPath() + "/home";
|
||||
return ResultUtil.data(ResultEnum.SUCCESS,user);
|
||||
}
|
||||
return "login";
|
||||
return ResultUtil.error(ResultEnum.LOGIN_FAIL);
|
||||
}
|
||||
|
||||
@PostMapping("/beforeLogin")
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.fjy.spring.enums;
|
||||
|
||||
public enum ResultEnum {
|
||||
UNKOWN_ERROR(-1,"未知错误"),
|
||||
SUCCESS(0,"请求成功"),
|
||||
SUCCESS(0,"成功"),
|
||||
USER_NOTEXIST(601,"用户不存在"),
|
||||
UPDATE_ERROR(602,"更新失败"),
|
||||
DELETE_ERROR(603,"删除失败"),
|
||||
@@ -14,6 +14,7 @@ public enum ResultEnum {
|
||||
ID_NULLPOINT(609,"id为空"),
|
||||
EMPTY_QUESTION(610,"该用户未设置密保问题"),
|
||||
QUESTION_ERROR(611,"问题与答案不匹配"),
|
||||
LOGIN_FAIL(612,"登录失败")
|
||||
|
||||
;
|
||||
private Integer code;
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
//@Configuration
|
||||
public class WebAppConfig implements WebMvcConfigurer {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.fjy.spring.untils;
|
||||
|
||||
import com.fjy.spring.domain.Result;
|
||||
import com.fjy.spring.enums.ResultEnum;
|
||||
|
||||
public class ResultUtil {
|
||||
public static Result error(Integer code,String msg){
|
||||
@@ -16,4 +17,33 @@ public class ResultUtil {
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result error(ResultEnum resultEnum){
|
||||
Result result = new Result();
|
||||
result.setCode(resultEnum.getCode());
|
||||
result.setMessage(resultEnum.getMsg());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result error(String msg){
|
||||
Result result = new Result();
|
||||
result.setCode(-2);
|
||||
result.setMessage(msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result data(ResultEnum resultEnum,Object data){
|
||||
Result result = new Result();
|
||||
result.setCode(resultEnum.getCode());
|
||||
result.setMessage(resultEnum.getMsg());
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result success(ResultEnum resultEnum){
|
||||
Result result = new Result();
|
||||
result.setCode(resultEnum.getCode());
|
||||
result.setMessage(resultEnum.getMsg());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#控制配置文件调用
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
active: prod
|
||||
@@ -25,8 +25,8 @@
|
||||
<!--滚动策略-->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!--路径文件名,文件名包含时间-->
|
||||
<fileNamePattern>F:\JAVA Workspace\Temp\log\%d\info.%d.log</fileNamePattern>
|
||||
<!--<fileNamePattern>/www/cmsfile/%d/info.%d.log</fileNamePattern>-->
|
||||
<!--<fileNamePattern>F:\JAVA Workspace\Temp\log\%d\info.%d.log</fileNamePattern>-->
|
||||
<fileNamePattern>/www/cmsfile/%d/info.%d.log</fileNamePattern>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
@@ -44,8 +44,8 @@
|
||||
<!--滚动策略-->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!--路径文件名,文件名包含时间-->
|
||||
<fileNamePattern>F:\JAVA Workspace\Temp\log\error.%d.log</fileNamePattern>
|
||||
<!--<fileNamePattern>/www/cmsfile/%d/error.%d.log</fileNamePattern>-->
|
||||
<!--<fileNamePattern>F:\JAVA Workspace\Temp\log\error.%d.log</fileNamePattern>-->
|
||||
<fileNamePattern>/www/cmsfile/%d/error.%d.log</fileNamePattern>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user