From 8e4ab831c7342d3fc4a7829c10152d41c3e61f1e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 13 May 2016 16:21:57 +0300 Subject: telegram login --- src/main/java/com/juick/http/www/SignUp.java | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/main/java/com/juick/http') diff --git a/src/main/java/com/juick/http/www/SignUp.java b/src/main/java/com/juick/http/www/SignUp.java index 2fae9b69..64b62e48 100644 --- a/src/main/java/com/juick/http/www/SignUp.java +++ b/src/main/java/com/juick/http/www/SignUp.java @@ -52,6 +52,8 @@ public class SignUp { account = getVKNameByHash(sql, hash); } else if (type.equals("xmpp")) { account = getJIDByHash(sql, hash); + } else if (type.equals("durov")) { + account = getTelegramNameByHash(sql, hash); } if (account == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); @@ -73,6 +75,8 @@ public class SignUp { out.print("\"VKontakte\"/"); } else if (type.charAt(0) == 'x') { out.print("\"XMPP\"/"); + } else if (type.charAt(0) == 'd') { + out.print("\"Telegram\"/"); } out.println(account + ""); @@ -144,6 +148,7 @@ public class SignUp { if (!(type.charAt(0) == 'f' && setFacebookUser(sql, hash, uid)) && !(type.charAt(0) == 'v' && setVKUser(sql, hash, uid)) + && !(type.charAt(0) == 'd' && setTelegramUser(sql, hash, uid)) && !(type.charAt(0) == 'x' && setJIDUser(sql, hash, uid))) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; @@ -167,6 +172,7 @@ public class SignUp { if (!(type.charAt(0) == 'f' && setFacebookUser(sql, hash, uid)) && !(type.charAt(0) == 'v' && setVKUser(sql, hash, uid)) + && !(type.charAt(0) == 'd' && setTelegramUser(sql, hash, uid)) && !(type.charAt(0) == 'x' && setJIDUser(sql, hash, uid))) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; @@ -235,6 +241,26 @@ public class SignUp { return ret; } + private String getTelegramNameByHash(Connection sql, String hash) { + String ret = null; + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT tg_name FROM telegram WHERE loginhash=?"); + stmt.setString(1, hash); + rs = stmt.executeQuery(); + if (rs.first()) { + ret = "" + rs.getString(1) + ""; + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + + return ret; + } private boolean setFacebookUser(Connection sql, String hash, int uid) { boolean ret = false; @@ -290,6 +316,22 @@ public class SignUp { } return ret; } + private boolean setTelegramUser(Connection sql, String hash, int uid) { + boolean ret = false; + PreparedStatement stmt = null; + try { + stmt = sql.prepareStatement("UPDATE telegram SET user_id=?,loginhash=NULL WHERE loginhash=?"); + stmt.setInt(1, uid); + stmt.setString(2, hash); + stmt.executeUpdate(); + ret = true; + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(null, stmt); + } + return ret; + } private String getJIDByHash(Connection sql, String hash) { String ret = null; -- cgit v1.2.3