parent
adc2c45b9d
commit
b3f42d1247
@ -0,0 +1,9 @@
|
|||||||
|
package top.lejings.demo.filter;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 监听需要登录的行为
|
||||||
|
* */
|
||||||
|
public class LoginCheckFilter {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package top.lejings.demo.mapper;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Insert;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
import top.lejings.demo.pojo.Users;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface UsersMapper {
|
||||||
|
@Select("select * from Users where username=#{username} and password=#{password}")
|
||||||
|
Users getByUsernameAndPassword(Users users) ;
|
||||||
|
|
||||||
|
@Select("select username,password from users where email=#{email}")
|
||||||
|
Users findPassword(String email);
|
||||||
|
|
||||||
|
@Select("select * from users where email=#{email}")
|
||||||
|
Users findById(Users users);
|
||||||
|
|
||||||
|
@Insert("INSERT INTO users (username, email, password) VALUES (#{username}, #{email}, #{password})")
|
||||||
|
void registered(Users users);
|
||||||
|
|
||||||
|
@Update("UPDATE users SET username = #{username},password = #{password} where user_id = #{user_id}")
|
||||||
|
void revise(Users users);
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package top.lejings.demo.service;
|
||||||
|
|
||||||
|
import top.lejings.demo.pojo.Users;
|
||||||
|
|
||||||
|
public interface UsersService {
|
||||||
|
Users login(Users users) ;
|
||||||
|
|
||||||
|
boolean registered(Users users);
|
||||||
|
|
||||||
|
boolean findPassword(String email);
|
||||||
|
|
||||||
|
void revise(Users users);
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package top.lejings.demo.utils;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class Email {
|
||||||
|
|
||||||
|
private final JavaMailSender sender;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public Email(JavaMailSender sender) {
|
||||||
|
this.sender = sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendSimpleMail(String to, String subject, String text) {
|
||||||
|
SimpleMailMessage message = new SimpleMailMessage();
|
||||||
|
message.setFrom("bloglejingstop@126.com");
|
||||||
|
message.setTo(to);
|
||||||
|
message.setSubject(subject);
|
||||||
|
message.setText(text);
|
||||||
|
sender.send(message);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package top.lejings.demo.utils;
|
||||||
|
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import io.jsonwebtoken.Jwts;
|
||||||
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class JwtUtils {
|
||||||
|
|
||||||
|
//签名秘钥 和 过期时间
|
||||||
|
private static String signKey = "lejings";
|
||||||
|
private static Long expire = 43200000L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成JWT令牌
|
||||||
|
* @param claims JWT第二部分负载 payload 中存储的内容
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String generateJwt(Map<String, Object> claims){
|
||||||
|
String jwt = Jwts.builder()
|
||||||
|
.addClaims(claims)
|
||||||
|
.signWith(SignatureAlgorithm.HS256, signKey)
|
||||||
|
.setExpiration(new Date(System.currentTimeMillis() + expire))
|
||||||
|
.compact();
|
||||||
|
return jwt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析JWT令牌
|
||||||
|
* @param jwt JWT令牌
|
||||||
|
* @return JWT第二部分负载 payload 中存储的内容
|
||||||
|
*/
|
||||||
|
public static Claims parseJWT(String jwt){
|
||||||
|
Claims claims = Jwts.parser()
|
||||||
|
.setSigningKey(signKey)
|
||||||
|
.parseClaimsJws(jwt)
|
||||||
|
.getBody();
|
||||||
|
return claims;
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue