From fb7d26e26b671287aff7ee497859dee6db19eb52 Mon Sep 17 00:00:00 2001 From: moec42frf <3378620026@qq.com> Date: Sun, 30 Apr 2023 09:23:25 +0800 Subject: [PATCH] ADD file via upload --- .../sang/controller/LoginRegController.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 blogserver/src/main/java/org/sang/controller/LoginRegController.java diff --git a/blogserver/src/main/java/org/sang/controller/LoginRegController.java b/blogserver/src/main/java/org/sang/controller/LoginRegController.java new file mode 100644 index 0000000..39cc23c --- /dev/null +++ b/blogserver/src/main/java/org/sang/controller/LoginRegController.java @@ -0,0 +1,53 @@ +package org.sang.controller; + +import org.sang.bean.RespBean; +import org.sang.bean.User; +import org.sang.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +@RestController +public class LoginRegController { + + @Autowired + UserService userService; + + @RequestMapping("/login_error") + public RespBean loginError() { + return new RespBean("error", "登录失败!"); + } + + @RequestMapping("/login_success") + public RespBean loginSuccess() { + return new RespBean("success", "登录成功!"); + } + + /** + * 如果自动跳转到这个页面,说明用户未登录,返回相应的提示即可 + *

+ * 如果要支持表单登录,可以在这个方法中判断请求的类型,进而决定返回JSON还是HTML页面 + * + * @return + */ + @RequestMapping("/login_page") + public RespBean loginPage() { + return new RespBean("error", "尚未登录,请登录!"); + } + + @PostMapping("/reg") + public RespBean reg(User user) { + int result = userService.reg(user); + if (result == 0) { + //成功 + return new RespBean("success", "注册成功!"); + } else if (result == 1) { + return new RespBean("error", "用户名重复,注册失败!"); + } else { + //失败 + return new RespBean("error", "注册失败!"); + } + } +}