I'm pretty confused about how to get a session Id for a user when logging in and how to use it when logging out. I have looked at the documentation for this on the app42 website and have had no success so far. What specific lines do I need to add to my code? any help would be great!
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System;
using com.shephertz.app42.paas.sdk.csharp;
using com.shephertz.app42.paas.sdk.csharp.user;
using com.shephertz.app42.paas.sdk.csharp.session;
using AssemblyCSharp;
public class LogIn : MonoBehaviour
{
Constant cons = new Constant ();
ServiceAPI sp = null;
UserService userService = null; // Initializing User Service.
User createUserObj = null;
public string success, txt_userName, txt_password, txt_emailId, box;
public string sessionId = "";
UserResponse callBack = new UserResponse ();
public GUIStyle typeFont;
public GUIStyle labelFont;
public GUIStyle buttonFont;
public GUIStyle errorFont;
private App42 app42;
float originalWidth = 1024; // Design resoultion
float originalHeight = 768;
#if UNITY_EDITOR
public static bool Validator (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{return true;}
#endif
void Start ()
{
#if UNITY_EDITOR
ServicePointManager.ServerCertificateValidationCallback = Validator;
#endif
sp = new ServiceAPI (cons.apiKey,cons.secretKey);
}
void OnGUI ()
{
// Set matrix
Vector2 ratio = new Vector2(Screen.width/originalWidth , Screen.height/originalHeight );
Matrix4x4 guiMatrix = Matrix4x4.identity;
guiMatrix.SetTRS(new Vector3(1, 1, 1), Quaternion.identity, new Vector3(ratio.x, ratio.y, 1));
GUI.matrix = guiMatrix;
GUI.TextArea (new Rect (10, 5, 300, 30), box, errorFont);
if (Time.time % 2 < 1) {
success = callBack.getResult ();
}
// For Setting Up ResponseBox.
GUI.TextArea (new Rect (10, 5, 300, 30), success, errorFont);
GUI.Label (new Rect (250, 100, 100, 30), "E n t e r u s e r n a m e", labelFont);
txt_userName = GUI.TextArea (new Rect (250, 150, 550, 50), txt_userName, typeFont);
GUI.Label (new Rect (250, 220, 100, 30), "E n t e r p a s s w o r d", labelFont);
txt_password = GUI.TextArea (new Rect (250, 270, 550, 50), txt_password, typeFont);
//GUI.Label (new Rect (250, 340, 100, 30), "E n t e r e m a i l", labelFont);
//txt_emailId = GUI.TextArea (new Rect (250, 390, 550, 50), txt_emailId, typeFont);
string UserName = txt_userName;
//UserName = cons.userName;
string password = txt_password;
string email = txt_emailId;
//=========================================================================
if (GUI.Button (new Rect (250, 340, 300, 50), "Log In", buttonFont)) {
userService = sp.BuildUserService (); // Initializing UserService.
userService.Authenticate (UserName, password, callBack);
Application.LoadLevel ("menu");
}
// Reset matrix
GUI.matrix = Matrix4x4.identity;
}
public void OnSuccess(object response)
{
User user = (User) response;
App42Log.Console("userName is " + user.GetUserName());
App42Log.Console("emailId is " + user.GetEmail());
App42Log.Console("Session Id is " + user.GetSessionId());
}
}