完善登录注册逻辑

main
wangqing 1 year ago
parent 6c74c305c4
commit 8203992415

@ -7,14 +7,14 @@ spring:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://8.134.98.47:3307/indie_friend?characterEncoding=UTF8&useSSL=false
username: root
password: 47084735Abc@
password: 47084735abc
jpa:
database: MySQL
show-sql: true
jwt:
config:
key: luoo
ttl: 360000
ttl: 3600000
eureka:
client:
service-url:

@ -14,6 +14,6 @@ public class InterceptorConfig extends WebMvcConfigurationSupport {
protected void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(jwtInterceptor).
addPathPatterns("/**").
excludePathPatterns("/login/**");
excludePathPatterns("/**/login/**");
}
}

@ -1,8 +1,5 @@
package com.luoo.user.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@ -64,8 +61,9 @@ public class AdminController {
if (admin !=null) {
//生成token
String token = jwtUtil.createJWT(admin.getId(),admin.getLoginname(),"admin");
Map map = new HashMap();
Map<String, Object> map = new HashMap();
map.put("token",token);
map.put("roles","admin");
map.put("name",admin.getLoginname());
return new Result(true,StatusCode.OK,"登录成功",map);
} else {

@ -58,7 +58,7 @@ public class UserController {
@RequestMapping(value = "/login",method = RequestMethod.POST)
public Result login(@RequestBody User user){
user = userService.login(user.getLoginname(),user.getPassword());
user = userService.login(user.getMobile(),user.getPassword());
if (user == null) {
return new Result(false,StatusCode.LOGINERROR,"登录失败");
}

@ -11,6 +11,7 @@ import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@ -43,6 +44,9 @@ public class AdminService {
@Autowired
private BCryptPasswordEncoder encoder;
@Autowired
private HttpServletRequest request;
public Admin findByLoginnameAndPassword(String loginname,String password) {

@ -118,8 +118,8 @@ public class UserService {
user.setRegdate(new Date());
user.setUpdatedate(new Date());
user.setLastdate(new Date());
// String newPassword = encoder.encode(user.getPassword());
// user.setPassword(newPassword);
String newPassword = encoder.encode(user.getPassword());
user.setPassword(newPassword);
userDao.save(user);
}
@ -214,7 +214,7 @@ public class UserService {
Map<String,String> map = new HashMap<>();
map.put("mobile",mobile);
map.put("checkcode",checkcode);
rabbitTemplate.convertAndSend("sms",map);
// rabbitTemplate.convertAndSend("sms",map);
// 在控制台放一份(方便测试)
@ -222,9 +222,9 @@ public class UserService {
}
public User login(String loginname, String password) {
User user = userDao.findByLoginname(loginname);
// User user = userDao.findByMobile(mobile);
public User login(String mobile, String password) {
// User user = userDao.findByLoginname(loginname);
User user = userDao.findByMobile(mobile);
if (user!=null && encoder.matches(password,user.getPassword())) {
return user;
}
@ -235,4 +235,5 @@ public class UserService {
userDao.updatefanscount(x,friendid);
userDao.updatefollowcount(x,userid);
}
}

@ -18,7 +18,7 @@ spring:
jwt:
config:
key: luoo
ttl: 360000
ttl: 3600000
eureka:
client:
service-url:

Loading…
Cancel
Save