package com.example.cosmos_serversb.models; import java.util.UUID; import javax.inject.Singleton; import com.example.cosmos_serversb.entities.*; @Singleton public class Users { private static Users theInstance = null; private Users() { } public static Users getInstance() { if (theInstance == null) { theInstance = new Users(); } return theInstance; } public static String createToken(String uId) { //Tokenを作成しuIdと関連付けしDBに保存し作成したTokenを返す String token = UUID.randomUUID().toString(); return token; } public static String createUId() { //uIdを作成し既存していないかチェック後DBに保存し作成したuIdを返す String uId = UUID.randomUUID().toString(); return uId; } public static User createUser(String name, String pw, String iconImage) { User testUser = new User("test", getInstance().createUId(), "http://test.com", "testpw", null, "http://localhost:8080/iconImage/b4bb7db0-cc0c-4ee1-816f-8304add12da8.jpg"); testUser.token.add(getInstance().createToken(testUser.uId)); testUser.token.add(getInstance().createToken(testUser.uId)); return testUser; } public static User setUser(String uId, String name, String pw, String iconImage) { User testUser = new User("test", getInstance().createUId(), "http://test.com", "testpw", null, "http://localhost:8080/iconImage/b4bb7db0-cc0c-4ee1-816f-8304add12da8.jpg"); testUser.token.add(getInstance().createToken(testUser.uId)); testUser.token.add(getInstance().createToken(testUser.uId)); return testUser; } public static User getUserById(String uId) { //与えられたuIdのUser情報を返す User testUser = new User("test", getInstance().createUId(), "http://test.com", "testpw", null, "http://localhost:8080/iconImage/b4bb7db0-cc0c-4ee1-816f-8304add12da8.jpg"); testUser.token.add(getInstance().createToken(testUser.uId)); testUser.token.add(getInstance().createToken(testUser.uId)); return testUser; } public static User getUserByToken(String token) { //与えられたTokenに紐づくUser情報を返す User testUser = new User("test", getInstance().createUId(), "http://test.com", "testpw", null, "http://localhost:8080/iconImage/b4bb7db0-cc0c-4ee1-816f-8304add12da8.jpg"); testUser.token.add(getInstance().createToken(testUser.uId)); testUser.token.add(getInstance().createToken(testUser.uId)); return testUser; } public static DeleteResult deleteUser(String uId) { return DeleteResult.SUCCESS; } public static Token login(String uId) { Token testtoken = new Token(getInstance().createToken(uId)); //tokenを作成後値を返す return testtoken;//testToken } public static DeleteResult logout(String token) { if(Users.getInstance().getUserByToken(token).uId == null) { return DeleteResult.FAILURE; }else{ Users.getInstance().getUserByToken(token).token.remove(Users.getInstance().getUserByToken(token).token.indexOf(token)); return DeleteResult.SUCCESS; } } public static boolean checkToken(String uId, String token) { //与えられたtokenとUserのtokenを比較し結果を返す return true; } public static boolean checkPassword(String uId, String pw) { //与えられたパスワードとUserのパスワードを比較し結果を返す return true; } }