Async login

This commit is contained in:
Blake Bourque
2015-06-24 18:31:17 -04:00
parent 068d53279e
commit bed881b279
3 changed files with 53 additions and 28 deletions
+18 -9
View File
@@ -18,19 +18,28 @@ namespace PlexView
return instance;
}
}
// [Obsolete]
// public User NewUser(Creds creds)
// {
// User client = new User(creds);
// client.Settings.LOGIN_SERVER = creds.gridURL;
// //@todo if creds.gridName not in Grids list add it
// users.Add(client.sessionID, client);
// return client;
// }
public User NewUser(Creds creds)
//create a new user and begin the login process
public Guid NewUserLogin(Creds creds)
{
//create the user object
User client = new User(creds);
client.Settings.LOGIN_SERVER = creds.gridURL;
//@todo if creds.gridName not in Grids list add it
users.Add(client.sessionID, client);
return client;
}
public bool Login(User client)
{
return client.Network.Login(client.creds.first, client.creds.last, client.creds.pass, Constants.CHANNEL, Constants.VERSION);
//add the user to the list of users
users.Add(client.sessionID, client);
//initiate login
client.Login();
return client.sessionID;
}
public bool Logout(Guid sessionID)
@@ -10,29 +10,21 @@ namespace PlexView
{
public UserMod () : base("/api")
{
//When the users requests to login
Post["/login"] = parameters =>
{
//process a login request
//parese their credentials
Creds creds = this.Bind<Creds>();
User client = ClientMgr.Instance.NewUser(creds);
//initiate login process
Guid sessionID = ClientMgr.Instance.NewUserLogin(creds);
//tell them that we have started login
Hashtable msg = new Hashtable();
msg.Add("status", "login begin");
msg.Add("sessionID", sessionID);
return msg;
if (ClientMgr.Instance.Login(client))
{
Hashtable msg = new Hashtable();
msg.Add("status", "success");
msg.Add("motd", client.Network.LoginMessage);
msg.Add("sessionID", client.sessionID);
return msg;
}
else
{
Hashtable msg = new Hashtable();
msg.Add("status", "fail");
msg.Add("motd", client.Network.LoginMessage);
msg.Add("sessionID", client.sessionID);
return msg;
}
};
Post["/logout"] = parameters =>
+25 -1
View File
@@ -59,7 +59,31 @@ namespace PlexView
lastRequest = DateTime.Now;
sessionID = Guid.NewGuid();
Settings.LOGIN_SERVER = creds.gridURL;
this.creds = creds;
}
}
public void Login()
{
//setup a callback (delagate) as the lgon status changes
Network.LoginProgress += delegate(NetworkManager sender, LoginProgressEventArgs e)
{
if (e.Status == LoginStatus.Success)
{
//@todo login successfull
Console.WriteLine ("Login Success "+sender.client.ToString());
}
else if (e.Status == LoginStatus.Failed)
{
//@todo login failure
Console.WriteLine ("Login Failure");
}
};
Network.BeginLogin(new LoginParams(this, creds.first, creds.last, creds.pass, Constants.CHANNEL, Constants.VERSION));
}
// public bool IsLoggedIn()
// {
// }
}
}