aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service/UserServiceImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/service/UserServiceImpl.java')
-rw-r--r--src/main/java/com/juick/service/UserServiceImpl.java24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java
index d19af067..7f73e6d1 100644
--- a/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/src/main/java/com/juick/service/UserServiceImpl.java
@@ -523,10 +523,24 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
@Transactional
@Override
public boolean linkTwitterAccount(
- final User user, final String accessToken, final String accessTokenSecret, final String screenName) {
- return getJdbcTemplate().update("INSERT INTO twitter(user_id,access_token,access_token_secret,uname) " +
- "VALUES (?,?,?,?)",
- user.getUid(), accessToken, accessTokenSecret, screenName) > 0;
+ final User user, final String accessToken, final String refreshToken, final String screenName) {
+ return getJdbcTemplate().update("INSERT INTO twitter(user_id,access_token,access_token_secret,refresh_token,uname) " +
+ "VALUES (?,?,'',?,?)",
+ user.getUid(), accessToken, refreshToken, screenName) > 0;
+ }
+
+ @Transactional
+ @Override
+ public boolean refreshTwitterToken(
+ final User user, final String accessToken, final String refreshToken) {
+ return getJdbcTemplate().update("UPDATE twitter SET access_token=?, refresh_token=?" +
+ " WHERE user_id=?",
+ accessToken, refreshToken, user.getUid()) > 0;
+ }
+ @Transactional(readOnly = true)
+ @Override
+ public boolean isTwitter1User(User user) {
+ return jdbcTemplate.queryForList("SELECT user_id FROM twitter WHERE user_id=? AND refresh_token=''", Integer.class, user.getUid()).size() > 0;
}
@Transactional(readOnly = true)
@@ -612,7 +626,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
@Override
public Optional<ExternalToken> getTwitterToken(final int uid) {
List<ExternalToken> list = getJdbcTemplate().query(
- "SELECT uname, access_token, access_token_secret FROM twitter WHERE user_id = ? AND crosspost = true",
+ "SELECT uname, access_token, refresh_token FROM twitter WHERE user_id = ? AND crosspost = true",
(rs, num) -> new ExternalToken(rs.getString(1), "twitter",
rs.getString(2), rs.getString(3)),
uid);