
@PostMapping("/login") public ResponseEntity loginUser(@RequestBody LoginRequest loginRequest, HttpServletRequest request) { // 从数据库获取用户信息 User user = userService.getUserByUsername(loginRequest.getUsername()); if (user == null) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("用户名不存在"); } // 校验密码 if (!encoder.matches(loginRequest.getPassword(), user.getPassword())) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("密码错误"); } // 生成Token String token = jwtTokenUtils.generateToken(user); response.addCookie(jwtTokenUtils.createCookie(token));
// 记录登录日志
LoginLog loginLog = new LoginLog();
loginLog.setUserId(user.getId());
loginLog.setUsername(user.getUsername());
loginLog.setIp(request.getRemoteAddr());
loginLog.setLoginTime(new Date());
loginLog.setBrowser(request.getHeader("User-Agent"));
loginLogService.saveLoginLog(loginLog);
return ResponseEntity.ok(new LoginResponse("登录成功", token));
}
@GetMapping("/logout") public ResponseEntity logoutUser(HttpServletRequest request) { Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals(jwtTokenUtils.getTokenName())) { cookie.setMaxAge(0); response.addCookie(cookie); break; } } } return ResponseEntity.ok("注销成功"); }
@GetMapping("/refresh") public ResponseEntity refreshAccessToken(HttpServletRequest request) { Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals(jwtTokenUtils.getTokenName())) { String token = cookie.getValue(); try { Claims claims = jwtTokenUtils.parseToken(token); String username = claims.getSubject(); User user = userService.getUserByUsername(username); if (user == null) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("用户不存在"); } String newToken = jwtTokenUtils.generateToken(user); response.addCookie(jwtTokenUtils.createCookie(newToken)); return ResponseEntity.ok(new LoginResponse("令牌刷新成功", newToken)); } catch (Exception e) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("无效的令牌"); } } } } return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("令牌不存在"); }
我也不记得具体怎么配置,你就自己找个例子学习一下吧。
宿迁河东站街:感受城市的活力与魅力
✨宿迁河东站街是一个充满活力的地方,这里不仅交通便利,还汇聚了众多美食和商业设施,是 locals 和游客 alike 的热门去处。无论是购物、美食还是散步,宿迁河东站街都能满足你的需求。周边的绿化和设施让站街成为一个宜人的好去处,每次来这里都能感受到城市的脉动。
自 from 站街出发,你可以方便地前往宿迁的各个角落, public transport 是这里的一大亮点。无论是公交、地铁还是出租车, 宿迁河东站街 都是交通枢纽,方便快捷。如果你是第一次来这里,建议提前规划好路线,以免错过任何 interesting spots。站街周围还有许多餐馆和商店,供你在此期间轻松打发时间。
说到站街的美食,宿迁河东站街 到处都是诱人的小吃和餐馆。从当地的特色小吃到国际化的餐饮选择,总有一款适合你的 taste。你可以尝试当地的美食,也可以品尝到来自世界各地的 cuisines。站街的夜市更是热闹非凡,各类美食摊位琳琅满目,是体验宿迁夜生活的绝佳去处。不要 forget to try 一下当地的特色美食,绝对是让你流连忘返的经历。
station 街不仅是一个交通 hub,更是宿迁的一个 cultural hub。这里定期会有一些 cultural events 和 exhibitions,吸引了很多 locals 和 visitors。如果你对宿迁的文化感兴趣,不妨参加一些 local events,亲身体验宿迁的传统文化和 modern 创新。站街周围还有许多 historical sites,可以让你更深入了解宿迁的历史和 culture。
overall,宿迁河东站街 是一个值得一游的地方,无论你是来宿迁出差还是旅游,这里都是一个理想的 stopover。你可以在这里放松身心,享受美食,或者参与各种 cultural activities。下次来宿迁的时候,一定要把这个地方列入你的行程中哦!vascular
宿迁 #河东站街 #宿迁美食 #宿迁旅游 #宿迁文化
国家电影局发布!《哪吒2》22日起在港澳地区上映
央视新闻客户端
花粉过敏高发季来了!专家:提前2到4周开始用药预防
央视财经
市场监管总局:鼓励、支持、保护民营企业加快发展
央视新闻
人少景美价优,春节后“错峰游”性价比凸显:机票酒店价格“省一半”
澎湃新闻
京东推出“打车服务”,此前上线京东外卖
九派新闻综合
2024年生成式AI专利调查:中国新增量全球第一
澎湃新闻
有网友自称“6万买饺子导演高仿号”,抖音副总裁回应
九派新闻综合
“投入5000元月入过万” 低成本家庭咖啡馆创业是商机还是泡沫?
封面新闻
春雨贵如油为何多下农民愁?原来是这个原因
中国天气网
7天瘦10斤?直播间疯狂带货“小粉豆”,多名主播已被抓
北京日报客户端