New file |
| | |
| | | package com.whyc.controller; |
| | | |
| | | import io.swagger.annotations.Api; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | /** |
| | | * 人脸识别 |
| | | */ |
| | | @RequestMapping("face") |
| | | @RestController |
| | | @Api(tags = "人脸识别") |
| | | public class FaceController { |
| | | |
| | | |
| | | } |
| | |
| | | private LoginService service; |
| | | |
| | | @PostMapping("login") |
| | | @ApiOperation(value ="登录") |
| | | @ApiOperation(value ="登录-账号密码") |
| | | public Response login(@RequestParam String userName, String password,HttpServletRequest request){ |
| | | return service.login(userName,password,request); |
| | | } |
| | | |
| | | @PostMapping("loginWithUKey") |
| | | @ApiOperation(value ="登录-uKey-TODO") |
| | | public Response loginWithUKey(@RequestParam String userName, String password,HttpServletRequest request){ |
| | | return service.loginWithUKey(userName,password,request); |
| | | } |
| | | |
| | | @PostMapping("logout") |
| | | @ApiOperation(value ="退出登录") |
| | | public void logout(){ |
New file |
| | |
| | | package com.whyc.pojo; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import org.apache.ibatis.type.Alias; |
| | | |
| | | /** |
| | | * 人脸识别 |
| | | */ |
| | | @Alias("UserFace") |
| | | @TableName(value = "tb_user_face") |
| | | public class UserFace { |
| | | @TableId |
| | | private Integer id; |
| | | /**人脸图片路径,http*/ |
| | | private String url; |
| | | |
| | | public Integer getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Integer id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getUrl() { |
| | | return url; |
| | | } |
| | | |
| | | public void setUrl(String url) { |
| | | this.url = url; |
| | | } |
| | | } |
| | |
| | | //同一个账号,后面登录的,会挤掉之前登录的SessionId |
| | | System.out.println("全局存储中当前SessionId为:"+request.getSession().getId()); |
| | | request.getServletContext().setAttribute(userName,request.getSession().getId()); |
| | | return new Response<>().set(1,true,"登录成功"); |
| | | } |
| | | return new Response<>().set(1,false,"密码错误"); |
| | | } |
| | | |
| | | public Response loginWithUKey(String userName, String password, HttpServletRequest request) { |
| | | UsernamePasswordToken userToken = new UsernamePasswordToken(userName, password); |
| | | Subject subject = SecurityUtils.getSubject(); |
| | | try { |
| | | subject.login(userToken); |
| | | }catch (Exception e){ |
| | | String message = e.getMessage(); |
| | | if(message.contains("did not match the expected credentials")){ |
| | | return new Response<>().set(1,false,"密码错误"); |
| | | } |
| | | return new Response<>().set(1,false,message); |
| | | } |
| | | if (subject.isAuthenticated()){ |
| | | //每个登录的用户都有一个全局变量,里面存着对应的SessionId; |
| | | //同一个账号,后面登录的,会挤掉之前登录的SessionId |
| | | System.out.println("全局存储中当前SessionId为:"+request.getSession().getId()); |
| | | request.getServletContext().setAttribute(userName,request.getSession().getId()); |
| | | //uKey和人脸识别 TODO |
| | | return new Response<>().set(1,true,"登录成功"); |
| | | } |