public async Task<Auths> getMobileSession(string username, string password) { var parameters = new Dictionary<string, string>(); parameters.Add("username", username); parameters.Add("password", password); parameters.Add("method", "auth.getMobileSession"); parameters.Add("api_key", AuthKeys.APIkey); string sign = new Sign().Make(parameters); string url = string.Concat(AuthKeys.APIurl, "?method=auth.getMobileSession", "&format=json", "&api_key=", AuthKeys.APIkey, "&username="******"&password="******"&api_sig=", sign); try { string response = await new HttpCall().DoTask(url); JsonObject ob = JsonObject.Parse(response); if (ob.ContainsKey("session")) { Auths auth = new Auths(); auth.username = JsonObject.Parse(ob.GetNamedObject("session").ToString()).GetNamedString("name"); auth.sessionkey = JsonObject.Parse(ob.GetNamedObject("session").ToString()).GetNamedString("key"); return auth; } if (ob.ContainsKey("error")) { double error = JsonObject.Parse(ob.GetNamedObject("error").ToString()).GetNamedNumber("code"); //throw new LastFmException(error.ToString()); return null; } } catch (Exception ex) { throw new HttpException(ex.ToString()); } return null; }
private async void webauth_Click(object sender, RoutedEventArgs e) { auth = await new AuthWeb().getWebSession(); if (auth != null) { await showdialog("Success!"); } else { await showdialog("Failed!"); } }
private async void LoginMobile_Click(object sender, RoutedEventArgs e) { auth = await new AuthMobile().getMobileSession(username.Text, password.Password); if (auth != null) { await showdialog("Success!"); } else { await showdialog("Failed!"); } MobileAuth.Visibility = Visibility.Collapsed; }