diff --git a/Programs/examples/PlexView/ClientMgr.cs b/Programs/examples/PlexView/ClientMgr.cs index 994d95c..7723309 100644 --- a/Programs/examples/PlexView/ClientMgr.cs +++ b/Programs/examples/PlexView/ClientMgr.cs @@ -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) diff --git a/Programs/examples/PlexView/nancyModules/UserMod.cs b/Programs/examples/PlexView/nancyModules/UserMod.cs index 67df554..af76fc7 100644 --- a/Programs/examples/PlexView/nancyModules/UserMod.cs +++ b/Programs/examples/PlexView/nancyModules/UserMod.cs @@ -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(); - 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 => diff --git a/Programs/examples/PlexView/types/User.cs b/Programs/examples/PlexView/types/User.cs index 6ad8088..514ddc2 100644 --- a/Programs/examples/PlexView/types/User.cs +++ b/Programs/examples/PlexView/types/User.cs @@ -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() +// { +// } } }