diff --git a/src/main/java/com/example/cosmos_serversb/models/Users.java b/src/main/java/com/example/cosmos_serversb/models/Users.java index 02e9dd8..ce99bd2 100644 --- a/src/main/java/com/example/cosmos_serversb/models/Users.java +++ b/src/main/java/com/example/cosmos_serversb/models/Users.java @@ -15,6 +15,8 @@ public class Users { private static Users theInstance = null; private static SessionFactory sessionFactory; + private static String baseURI = "http://nitta-lab-www.is.konan-u.ac.jp/"; + private static String AppName = "cosmos"; public static void setUp() { // A SessionFactory is set up once for an application! @@ -52,10 +54,16 @@ return theInstance; } - public static String createToken(String uId) { + public static Token createToken(String uId) { //Tokenを作成しuIdと関連付けしDBに保存し作成したTokenを返す String token = UUID.randomUUID().toString(); - return token; + Token testToken =new Token(token, uId); + Session session = sessionFactory.openSession(); + session.beginTransaction(); + session.save(testToken); + session.getTransaction().commit(); + session.close(); + return testToken; } public static String createUId() { @@ -65,10 +73,13 @@ } public static User createUser(String name, String pw, String iconImage) { + String uId = getInstance().createUId(); + String uri = baseURI + AppName +"/users/" +uId; + Session session = sessionFactory.openSession(); session.beginTransaction(); //名前、uId、ユーザーuri、パスワード、アイコンイメージを保存 - User testUser = new User(name,getInstance().createUId(), "http://nitta-lab-8080/cosmos/users/{uId}.com",iconImage); + User testUser = new User(name, uId, uri, iconImage); session.save(testUser); //出力 // List userResult = session.createQuery( "from User" ).list(); @@ -155,7 +166,7 @@ } public static Token login(String uId) { - Token testtoken = new Token(getInstance().createToken(uId)); + Token testtoken = getInstance().createToken(uId); //tokenを作成後値を返す return testtoken;//testToken }