手机号验证码登录
This commit is contained in:
@@ -11,4 +11,4 @@ public class DatingApplication {
|
||||
SpringApplication.run(DatingApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,8 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
.excludePathPatterns(
|
||||
"/user/login",
|
||||
"/user/sendCode",
|
||||
"/user/loginByCode"
|
||||
"/user/loginByCode",
|
||||
"/user/loginPhone"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,4 +90,23 @@ public class UserController {
|
||||
return ok ? Result.success(ResultCode.SUCCESS, "登录成功") : Result.error(ResultCode.SYSTEM_ERROR, "登录失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param body 登录参数
|
||||
*/
|
||||
@PostMapping("/loginPhone")
|
||||
public Result<?> loginPhone(@RequestBody Map<String, String> body) {
|
||||
String phone = body.get("phone");
|
||||
String code = body.get("code");
|
||||
|
||||
//校验验证码
|
||||
boolean verify = userService.verifyCode(phone, code);
|
||||
if (!verify){
|
||||
return Result.error(ResultCode.SYSTEM_ERROR, "验证码错误或已过期");
|
||||
}
|
||||
//登录
|
||||
UserLoginVO vo = userService.loginByPhone(phone);
|
||||
return Result.success(ResultCode.SUCCESS, "登录成功", vo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.bao.dating.mapper;
|
||||
import com.bao.dating.pojo.dto.UserInfoUpdateDTO;
|
||||
import com.bao.dating.pojo.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 用户Mapper
|
||||
@@ -33,4 +34,6 @@ public interface UserMapper {
|
||||
*/
|
||||
void updateUserInfoByUserId(UserInfoUpdateDTO userInfoUpdateDTO);
|
||||
|
||||
User selectByPhone(@Param("phone") String phone);
|
||||
|
||||
}
|
||||
|
||||
@@ -49,4 +49,6 @@ public interface UserService {
|
||||
void sendSmsCode(String phone);
|
||||
|
||||
boolean verifyCode(String phone, String code);
|
||||
|
||||
UserLoginVO loginByPhone(String phone);
|
||||
}
|
||||
|
||||
@@ -336,4 +336,18 @@ public class UserServiceImpl implements UserService {
|
||||
stringRedisTemplate.delete(key);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserLoginVO loginByPhone(String phone) {
|
||||
//根据手机号查询用户
|
||||
User user = userMapper.selectByPhone(phone);
|
||||
//创建token
|
||||
String token = JwtUtil.generateToken(user.getUserId().toString());
|
||||
//封装返回结果
|
||||
UserLoginVO VO = new UserLoginVO();
|
||||
VO.setUserId(user.getUserId());
|
||||
VO.setToken(token);
|
||||
return VO;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
signature,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM user WHERE user_id = #{userId}
|
||||
FROM dating.user WHERE user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<!--根据ID更新动态-->
|
||||
@@ -74,4 +74,8 @@
|
||||
</set>
|
||||
WHERE user_id = #{userId}
|
||||
</update>
|
||||
|
||||
<select id="selectByPhone" resultType="com.bao.dating.pojo.entity.User">
|
||||
select * from dating.user where user_phone =#{phone}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user