Fixing AuthenticationHelper fuckups (regex/http verb)

feature-npv2
Icedream 2014-05-07 22:00:34 +02:00
parent 24b5a93dda
commit 840ec4a64d
2 changed files with 11 additions and 7 deletions

View File

@ -65,19 +65,19 @@ namespace NPSharp.Authentication
Path = _path
}.Uri;
var req = (HttpWebRequest)WebRequest.Create (uri);
var req = (HttpWebRequest)WebRequest.Create(uri);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.AllowAutoRedirect = true;
using (var reqStream = req.GetRequestStream()) {
var buffer = Encoding.UTF8.GetBytes (post);
reqStream.Write (buffer, 0, post.Length);
reqStream.Flush ();
}
req.Method = "POST";
//req.ContentType = "application/x-www-urlencodedform";
req.AllowAutoRedirect = true;
// Response will be in this syntax:
// (ok|fail)#text#userid#username#email#sessiontoken
var rx = new Regex ("^(?P<status>ok|fail)#(?P<text>.+)#(?P<userid>[0-9]+)#(?P<username>.+)#(?P<usermail>.+)#(?P<sessiontoken>.+)$");
var rx = new Regex("^(?<status>ok|fail)#(?<text>.+)#(?<userid>[0-9]+)#(?<username>.+)#(?<usermail>.+)#(?<sessiontoken>.+)$");
var resp = (HttpWebResponse)req.GetResponse ();
using (var respStream = resp.GetResponseStream()) {
using (var respReader = new StreamReader(respStream)) {

View File

@ -17,9 +17,13 @@ namespace NPSharp.CommandLine.MOTD
{
ah.Authenticate(username, password);
}
catch
catch (Exception err)
{
Console.Error.WriteLine("Could not authenticate.");
#if DEBUG
Console.Error.WriteLine("Could not authenticate: {0}", err);
#else
Console.Error.WriteLine("Could not authenticate: {0}", err.Message);
#endif
return;
}