Procházet zdrojové kódy

添加会员登录接口

macro před 5 roky
rodič
revize
3ce81d9c75

+ 22 - 1
mall-portal/src/main/java/com/macro/mall/portal/controller/UmsMemberController.java

@@ -5,12 +5,16 @@ import com.macro.mall.portal.service.UmsMemberService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * 会员登录注册管理Controller
  * Created by macro on 2018/8/3.
@@ -19,10 +23,12 @@ import org.springframework.web.bind.annotation.ResponseBody;
 @Api(tags = "UmsMemberController", description = "会员登录注册管理")
 @RequestMapping("/sso")
 public class UmsMemberController {
+    @Value("${jwt.tokenHead}")
+    private String tokenHead;
     @Autowired
     private UmsMemberService memberService;
 
-    @ApiOperation("注册")
+    @ApiOperation("会员注册")
     @RequestMapping(value = "/register", method = RequestMethod.POST)
     @ResponseBody
     public CommonResult register(@RequestParam String username,
@@ -32,6 +38,21 @@ public class UmsMemberController {
         return memberService.register(username, password, telephone, authCode);
     }
 
+    @ApiOperation("会员登录")
+    @RequestMapping(value = "/login", method = RequestMethod.POST)
+    @ResponseBody
+    public CommonResult login(@RequestParam String username,
+                              @RequestParam String password) {
+        String token = memberService.login(username, password);
+        if (token == null) {
+            return CommonResult.validateFailed("用户名或密码错误");
+        }
+        Map<String, String> tokenMap = new HashMap<>();
+        tokenMap.put("token", token);
+        tokenMap.put("tokenHead", tokenHead);
+        return CommonResult.success(tokenMap);
+    }
+
     @ApiOperation("获取验证码")
     @RequestMapping(value = "/getAuthCode", method = RequestMethod.GET)
     @ResponseBody