Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
J
JWT
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kis_intern1
JWT
Commits
6c4cd520
Commit
6c4cd520
authored
Aug 02, 2023
by
nk161690
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log
parent
136fc4fa
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
123 additions
and
60 deletions
+123
-60
UnityProject/Assets/FacebookLogin.cs
UnityProject/Assets/FacebookLogin.cs
+14
-2
UnityProject/Assets/Log.cs
UnityProject/Assets/Log.cs
+45
-0
UnityProject/Assets/Log.cs.meta
UnityProject/Assets/Log.cs.meta
+11
-0
UnityProject/Assets/Login.cs
UnityProject/Assets/Login.cs
+4
-57
UnityProject/Assets/PhotonServer.cs
UnityProject/Assets/PhotonServer.cs
+24
-0
UnityProject/Assets/PhotonServer.cs.meta
UnityProject/Assets/PhotonServer.cs.meta
+11
-0
UnityProject/Assets/Scenes/SampleScene.unity
UnityProject/Assets/Scenes/SampleScene.unity
+14
-1
No files found.
UnityProject/Assets/FacebookLogin.cs
View file @
6c4cd520
...
@@ -7,12 +7,14 @@ using Photon.Realtime;
...
@@ -7,12 +7,14 @@ using Photon.Realtime;
using
UnityEditor.VersionControl
;
using
UnityEditor.VersionControl
;
using
TMPro
;
using
TMPro
;
using
Unity.VisualScripting.Antlr3.Runtime
;
using
Unity.VisualScripting.Antlr3.Runtime
;
using
static
Log
;
using
System
;
public
class
FacebookLogin
:
MonoBehaviour
public
class
FacebookLogin
:
MonoBehaviour
{
{
[
SerializeField
]
private
TextMeshProUGUI
message
;
private
readonly
string
[]
facebookPermissions
=
{
"public_profile"
,
"email"
};
private
readonly
string
[]
facebookPermissions
=
{
"public_profile"
,
"email"
};
private
LoginSession
session
=
new
LoginSession
();
private
Log
log
=
new
Log
();
private
void
Awake
()
private
void
Awake
()
{
{
...
@@ -27,6 +29,12 @@ public class FacebookLogin : MonoBehaviour
...
@@ -27,6 +29,12 @@ public class FacebookLogin : MonoBehaviour
}
}
}
}
private
void
OnApplicationQuit
()
{
session
.
LogoutTime
=
DateTime
.
Now
.
ToString
(
"dd/MM/yyyy HH:mm"
);
log
.
LogLoginSession
(
session
);
}
private
void
OnInitComplete
()
private
void
OnInitComplete
()
{
{
if
(
FB
.
IsInitialized
)
if
(
FB
.
IsInitialized
)
...
@@ -66,6 +74,10 @@ public class FacebookLogin : MonoBehaviour
...
@@ -66,6 +74,10 @@ public class FacebookLogin : MonoBehaviour
// Use the accessToken to authenticate with Photon as a custom authentication type
// Use the accessToken to authenticate with Photon as a custom authentication type
OnFacebookLoggedIn
();
OnFacebookLoggedIn
();
// Log
session
.
Username
=
AccessToken
.
CurrentAccessToken
.
UserId
;
session
.
LoginTime
=
DateTime
.
Now
.
ToString
(
"dd/MM/yyyy HH:mm"
);
}
}
else
else
{
{
...
...
UnityProject/Assets/Log.cs
0 → 100644
View file @
6c4cd520
using
Newtonsoft.Json
;
using
System
;
using
System.Net.Http.Headers
;
using
System.Net.Http
;
using
System.Text
;
using
UnityEngine
;
using
static
System
.
Collections
.
Specialized
.
BitVector32
;
public
class
Log
{
public
class
LoginSession
{
public
string
Username
{
get
;
set
;
}
public
string
LoginTime
{
get
;
set
;
}
public
string
LogoutTime
{
get
;
set
;
}
}
public
async
void
LogLoginSession
(
LoginSession
session
)
{
// Serialize the data as JSON
string
jsonData
=
JsonConvert
.
SerializeObject
(
session
);
// Send the data to Elasticsearch using HTTP POST request
string
elasticUrl
=
"https://893485fbcebc4a4d9102091b2bad74a4.us-central1.gcp.cloud.es.io:443/login_sessions/_doc"
+
"?pipeline=ent-search-generic-ingestion"
;
using
(
HttpClient
client
=
new
HttpClient
())
{
var
contentType
=
new
MediaTypeWithQualityHeaderValue
(
"application/json"
);
client
.
DefaultRequestHeaders
.
Accept
.
Add
(
contentType
);
client
.
DefaultRequestHeaders
.
Authorization
=
new
AuthenticationHeaderValue
(
"ApiKey"
,
"MUdvM3NJa0I3bFF0X01wcFZWY2s6MzU4WllreVJRSldfZEhWSTVPbHZ1UQ=="
);
HttpContent
content
=
new
StringContent
(
jsonData
,
Encoding
.
UTF8
,
"application/json"
);
HttpResponseMessage
response
=
await
client
.
PostAsync
(
elasticUrl
,
content
);
if
(
response
.
IsSuccessStatusCode
)
{
Debug
.
Log
(
"Login session logged successfully!"
);
}
else
{
Debug
.
LogError
(
"Failed to log login session to Elasticsearch. Error: "
+
response
.
StatusCode
);
}
}
}
}
UnityProject/Assets/Log.cs.meta
0 → 100644
View file @
6c4cd520
fileFormatVersion: 2
guid: 132acc5db1794b342ab34765ca9c17d1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
UnityProject/Assets/Login.cs
View file @
6c4cd520
...
@@ -4,9 +4,8 @@ using UnityEngine;
...
@@ -4,9 +4,8 @@ using UnityEngine;
using
Newtonsoft.Json
;
using
Newtonsoft.Json
;
using
Photon.Realtime
;
using
Photon.Realtime
;
using
Photon.Pun
;
using
Photon.Pun
;
using
System.Text
;
using
System
;
using
System
;
using
System.Net.Http.Headers
;
using
static
Log
;
public
class
Login
:
MonoBehaviourPunCallbacks
public
class
Login
:
MonoBehaviourPunCallbacks
{
{
...
@@ -16,7 +15,8 @@ public class Login : MonoBehaviourPunCallbacks
...
@@ -16,7 +15,8 @@ public class Login : MonoBehaviourPunCallbacks
private
readonly
string
baseURL
=
"http://localhost:5172/User/"
;
private
readonly
string
baseURL
=
"http://localhost:5172/User/"
;
private
string
token
=
""
;
private
string
token
=
""
;
public
LoginSession
session
=
new
LoginSession
();
private
LoginSession
session
=
new
LoginSession
();
private
Log
log
=
new
Log
();
public
class
RespondMessage
public
class
RespondMessage
{
{
...
@@ -25,19 +25,6 @@ public class Login : MonoBehaviourPunCallbacks
...
@@ -25,19 +25,6 @@ public class Login : MonoBehaviourPunCallbacks
public
string
Data
{
get
;
set
;
}
public
string
Data
{
get
;
set
;
}
}
}
public
class
LoginSession
{
public
string
Username
{
get
;
set
;
}
public
DateTime
LoginTime
{
get
;
set
;
}
public
DateTime
?
LogoutTime
{
get
;
set
;
}
}
private
void
OnApplicationQuit
()
{
session
.
LogoutTime
=
DateTime
.
Now
;
LogLoginSession
(
token
);
}
public
async
void
CallLoginAPI
()
public
async
void
CallLoginAPI
()
{
{
string
endpoint
=
"Login"
;
string
endpoint
=
"Login"
;
...
@@ -63,7 +50,7 @@ public class Login : MonoBehaviourPunCallbacks
...
@@ -63,7 +50,7 @@ public class Login : MonoBehaviourPunCallbacks
token
=
respondMessage
.
Data
;
token
=
respondMessage
.
Data
;
AuthenticateWithPhoton
(
token
);
AuthenticateWithPhoton
(
token
);
session
.
Username
=
username
.
text
;
session
.
Username
=
username
.
text
;
session
.
LoginTime
=
DateTime
.
Now
;
session
.
LoginTime
=
DateTime
.
Now
.
ToString
(
"dd/MM/yyyy"
)
;
}
}
else
else
{
{
...
@@ -107,45 +94,5 @@ public class Login : MonoBehaviourPunCallbacks
...
@@ -107,45 +94,5 @@ public class Login : MonoBehaviourPunCallbacks
}
}
}
}
}
}
public
override
void
OnConnectedToMaster
()
{
base
.
OnConnectedToMaster
();
Debug
.
Log
(
"Connected to Photon!"
);
message
.
text
=
"Login successful! Connected to Photon."
;
}
public
override
void
OnDisconnected
(
DisconnectCause
cause
)
{
base
.
OnDisconnected
(
cause
);
Debug
.
Log
(
"Disconnected from Photon. Reason: "
+
cause
.
ToString
());
}
private
async
void
LogLoginSession
(
string
token
)
{
// Serialize the data as JSON
string
jsonData
=
JsonConvert
.
SerializeObject
(
session
);
// Send the data to Elasticsearch using HTTP POST request
string
elasticUrl
=
"https://893485fbcebc4a4d9102091b2bad74a4.us-central1.gcp.cloud.es.io:443/login_sessions/_doc"
+
"?pipeline=ent-search-generic-ingestion"
;
using
(
HttpClient
client
=
new
HttpClient
())
{
var
contentType
=
new
MediaTypeWithQualityHeaderValue
(
"application/json"
);
client
.
DefaultRequestHeaders
.
Accept
.
Add
(
contentType
);
client
.
DefaultRequestHeaders
.
Authorization
=
new
AuthenticationHeaderValue
(
"ApiKey"
,
"MUdvM3NJa0I3bFF0X01wcFZWY2s6MzU4WllreVJRSldfZEhWSTVPbHZ1UQ=="
);
HttpContent
content
=
new
StringContent
(
jsonData
,
Encoding
.
UTF8
,
"application/json"
);
HttpResponseMessage
response
=
await
client
.
PostAsync
(
elasticUrl
,
content
);
if
(
response
.
IsSuccessStatusCode
)
{
Debug
.
Log
(
"Login session logged successfully!"
);
}
else
{
Debug
.
LogError
(
"Failed to log login session to Elasticsearch. Error: "
+
response
.
StatusCode
);
}
}
}
}
}
UnityProject/Assets/PhotonServer.cs
0 → 100644
View file @
6c4cd520
using
Photon.Pun
;
using
Photon.Realtime
;
using
TMPro
;
using
UnityEngine
;
public
class
PhotonServer
:
MonoBehaviourPunCallbacks
{
[
SerializeField
]
private
TextMeshProUGUI
message
;
public
override
void
OnConnectedToMaster
()
{
base
.
OnConnectedToMaster
();
Debug
.
Log
(
"Connected to Photon!"
);
message
.
text
=
"Login successful! Connected to Photon."
;
}
public
override
void
OnDisconnected
(
DisconnectCause
cause
)
{
base
.
OnDisconnected
(
cause
);
Debug
.
Log
(
"Disconnected from Photon. Reason: "
+
cause
.
ToString
());
}
}
UnityProject/Assets/PhotonServer.cs.meta
0 → 100644
View file @
6c4cd520
fileFormatVersion: 2
guid: abbec8d2166306344b83dc07dadc742e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
UnityProject/Assets/Scenes/SampleScene.unity
View file @
6c4cd520
...
@@ -858,7 +858,6 @@ MonoBehaviour:
...
@@ -858,7 +858,6 @@ MonoBehaviour:
m_Script
:
{
fileID
:
11500000
,
guid
:
ab1db3a1da2c2b541bc729810838e50f
,
type
:
3
}
m_Script
:
{
fileID
:
11500000
,
guid
:
ab1db3a1da2c2b541bc729810838e50f
,
type
:
3
}
m_Name
:
m_Name
:
m_EditorClassIdentifier
:
m_EditorClassIdentifier
:
message
:
{
fileID
:
849773379
}
---
!u!1
&366359934
---
!u!1
&366359934
GameObject
:
GameObject
:
m_ObjectHideFlags
:
0
m_ObjectHideFlags
:
0
...
@@ -1140,6 +1139,7 @@ GameObject:
...
@@ -1140,6 +1139,7 @@ GameObject:
-
component
:
{
fileID
:
519420032
}
-
component
:
{
fileID
:
519420032
}
-
component
:
{
fileID
:
519420031
}
-
component
:
{
fileID
:
519420031
}
-
component
:
{
fileID
:
519420029
}
-
component
:
{
fileID
:
519420029
}
-
component
:
{
fileID
:
519420033
}
m_Layer
:
0
m_Layer
:
0
m_Name
:
Main Camera
m_Name
:
Main Camera
m_TagString
:
MainCamera
m_TagString
:
MainCamera
...
@@ -1213,6 +1213,19 @@ Transform:
...
@@ -1213,6 +1213,19 @@ Transform:
m_Father
:
{
fileID
:
0
}
m_Father
:
{
fileID
:
0
}
m_RootOrder
:
0
m_RootOrder
:
0
m_LocalEulerAnglesHint
:
{
x
:
0
,
y
:
0
,
z
:
0
}
m_LocalEulerAnglesHint
:
{
x
:
0
,
y
:
0
,
z
:
0
}
---
!u!114
&519420033
MonoBehaviour
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
519420028
}
m_Enabled
:
1
m_EditorHideFlags
:
0
m_Script
:
{
fileID
:
11500000
,
guid
:
abbec8d2166306344b83dc07dadc742e
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
message
:
{
fileID
:
849773379
}
---
!u!1
&569175305
---
!u!1
&569175305
GameObject
:
GameObject
:
m_ObjectHideFlags
:
0
m_ObjectHideFlags
:
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment