From c353de926747cc59b3eefd4880d104f5991e29a9 Mon Sep 17 00:00:00 2001
From: Gravit <gravit.min@ya.ru>
Date: Tue, 26 May 2020 04:42:31 +0700
Subject: [PATCH] [FEATURE][EXPERIMENTAL] AuthProviderDAOResult

---
 .../auth/provider/AuthProviderDAOResult.java  | 21 +++++++++++++++++++
 .../auth/provider/HibernateAuthProvider.java  |  2 +-
 .../socket/response/auth/AuthResponse.java    |  5 +++++
 3 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderDAOResult.java

diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderDAOResult.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderDAOResult.java
new file mode 100644
index 00000000..debb953d
--- /dev/null
+++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderDAOResult.java
@@ -0,0 +1,21 @@
+package pro.gravit.launchserver.auth.provider;
+
+import pro.gravit.launcher.ClientPermissions;
+import pro.gravit.launchserver.dao.User;
+
+public class AuthProviderDAOResult extends AuthProviderResult {
+    public User daoObject;
+
+    public AuthProviderDAOResult(String username, String accessToken) {
+        super(username, accessToken);
+    }
+
+    public AuthProviderDAOResult(String username, String accessToken, ClientPermissions permissions) {
+        super(username, accessToken, permissions);
+    }
+
+    public AuthProviderDAOResult(String username, String accessToken, ClientPermissions permissions, User daoObject) {
+        super(username, accessToken, permissions);
+        this.daoObject = daoObject;
+    }
+}
diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java
index 8ce22cef..ef68d6ae 100644
--- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java
+++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java
@@ -26,7 +26,7 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p
             if (user == null) throw new AuthException("Username incorrect");
             else throw new AuthException("Username or password incorrect");
         }
-        return new AuthProviderResult(login, SecurityHelper.randomStringToken(), user.getPermissions());
+        return new AuthProviderDAOResult(login, SecurityHelper.randomStringToken(), user.getPermissions(), user);
     }
 
     @Override
diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java
index 520d6675..15667812 100644
--- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java
+++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java
@@ -8,6 +8,7 @@
 import pro.gravit.launchserver.auth.AuthException;
 import pro.gravit.launchserver.auth.AuthProviderPair;
 import pro.gravit.launchserver.auth.provider.AuthProvider;
+import pro.gravit.launchserver.auth.provider.AuthProviderDAOResult;
 import pro.gravit.launchserver.auth.provider.AuthProviderResult;
 import pro.gravit.launchserver.socket.Client;
 import pro.gravit.launchserver.socket.response.SimpleResponse;
@@ -84,6 +85,10 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti
                 clientData.username = result.playerProfile.username;
             else
                 clientData.username = login;
+            if(aresult instanceof AuthProviderDAOResult)
+            {
+                clientData.daoObject = ((AuthProviderDAOResult) aresult).daoObject;
+            }
             result.accessToken = aresult.accessToken;
             result.permissions = clientData.permissions;
             if (getSession) {