From 5ec828b377b18d6cf56643796de8fdd44e8f1091 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Tue, 26 Nov 2013 15:57:46 +0700 Subject: getSignUpHashByJID --- src/com/juick/server/UserQueries.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java index b1198e4d..716f8f0f 100644 --- a/src/com/juick/server/UserQueries.java +++ b/src/com/juick/server/UserQueries.java @@ -24,6 +24,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Random; +import java.util.UUID; /** * @@ -33,6 +34,27 @@ public class UserQueries { static final String ABCDEF = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + public static String getSignUpHashByJID(Connection sql, String jid) { + String hash = SQLHelpers.getString(sql, "SELECT loginhash FROM jids WHERE jid=? AND user_id IS NULL", jid); + + if (hash == null) { + hash = UUID.randomUUID().toString(); + PreparedStatement stmt = null; + try { + stmt = sql.prepareStatement("INSERT INTO jids(jid,loginhash) VALUES (?,?)"); + stmt.setString(1, jid); + stmt.setString(2, hash); + stmt.executeUpdate(); + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(null, stmt); + } + } + + return hash; + } + public static int createUser(Connection sql, String username, String password, String lang) { int uid = 0; -- cgit v1.2.3