Added refresh token endpoint
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
@ -28,6 +29,7 @@ public class User {
|
||||
private String usosId;
|
||||
private UserRoles role;
|
||||
private String token;
|
||||
private String refreshToken;
|
||||
private Timestamp tokenUsageDate;
|
||||
|
||||
public User() {
|
||||
@ -105,6 +107,13 @@ public class User {
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return token needed to call refresh token after it expired
|
||||
*/
|
||||
public String getRefreshToken() {
|
||||
return refreshToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* token seter. Sets token and automaticly set time when was set
|
||||
*
|
||||
@ -113,6 +122,7 @@ public class User {
|
||||
public void setToken(String token) {
|
||||
this.tokenUsageDate = new Timestamp(System.currentTimeMillis());
|
||||
this.token = token;
|
||||
this.refreshToken = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,6 +38,9 @@ public interface UserRepository extends JpaRepository<User, Long> {
|
||||
@Query("FROM User WHERE email = ?1")
|
||||
Optional<User> getByAuthority(@Param("authority") String authority);
|
||||
|
||||
@Query("FROM User WHERE refreshToken = ?1")
|
||||
Optional<User> getByRefreshToken(@Param("refreshToken") String refreshToken);
|
||||
|
||||
@Query("FROM User WHERE token = ?1")
|
||||
Optional<User> getByToken(@Param("token") String token);
|
||||
|
||||
|
@ -1,22 +1,17 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
// import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class EventService {
|
||||
|
||||
@Autowired
|
||||
private EmailService emailService;
|
||||
// @Autowired
|
||||
// private EmailService emailService;
|
||||
|
||||
@Scheduled(cron = "0 2 17 * * *")
|
||||
public void collectGroupLosses() {
|
||||
System.out.println("Checking for groups");
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 5 18 * * *")
|
||||
public void testMail() {
|
||||
this.emailService.sendMail("kaczor982@gmail.com", "Cześć. Jestem Tomek.");
|
||||
}
|
||||
}
|
||||
|
@ -81,4 +81,8 @@ public class UserService {
|
||||
return this.repo.getAllByRole(UserRoles.STUDENT);
|
||||
}
|
||||
|
||||
public Optional<User> getUserByRefreshToken(String refreshToken) {
|
||||
return this.repo.getByRefreshToken(refreshToken);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user