-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: redis 의존성 추가 * feat: 중복 로그인 예외 처리
- Loading branch information
1 parent
9b78ff1
commit 26cba54
Showing
10 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package yonseigolf.server.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.core.StringRedisTemplate; | ||
|
||
@Configuration | ||
public class RedisConfig { | ||
|
||
@Bean | ||
public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory connectionFactory) { | ||
return new StringRedisTemplate(connectionFactory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/yonseigolf/server/user/exception/DuplicatedLoginException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package yonseigolf.server.user.exception; | ||
|
||
public class DuplicatedLoginException extends RuntimeException { | ||
|
||
public DuplicatedLoginException(String message) { | ||
super(message); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/yonseigolf/server/user/service/PreventDuplicateLoginService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package yonseigolf.server.user.service; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@Service | ||
public class PreventDuplicateLoginService { | ||
|
||
private final RedisTemplate redisTemplate; | ||
|
||
@Autowired | ||
public PreventDuplicateLoginService(RedisTemplate redisTemplate) { | ||
this.redisTemplate = redisTemplate; | ||
} | ||
|
||
public void registerLogin(long userId, String token) { | ||
|
||
redisTemplate.opsForValue().getAndDelete(userId); | ||
redisTemplate.opsForValue().set(userId, token, 30, TimeUnit.MINUTES); | ||
} | ||
|
||
// 같으면 true, 다르면 false | ||
public boolean checkDuplicatedLogin(long userId, String token) { | ||
|
||
return redisTemplate.opsForValue().get(userId).equals(token); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters