Skip to content

Commit

Permalink
http redirection bugfix(on login), UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jarig committed Jan 19, 2016
1 parent 3dea9df commit 2f34d81
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 31 deletions.
4 changes: 2 additions & 2 deletions EliteReporter/Forms/LoginForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ private void loginButton_Click(object sender, EventArgs e)
var profile = edapi.getProfile();
if (profile != null)
{
MessageBox.Show("Greetings commander " + profile.CommanderName, "Welcome!");
Dispose();
this.DialogResult = DialogResult.OK;
}
else
{
Expand All @@ -66,6 +65,7 @@ private void loginButton_Click(object sender, EventArgs e)

private void closeButton_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Dispose();
}

Expand Down
2 changes: 1 addition & 1 deletion EliteReporter/Forms/ReportForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 26 additions & 18 deletions EliteReporter/Forms/ReportForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ private void analyzeScreenShot(string pathToBmp)

private void activateButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(commanderName))
{
initialize();
return;
}
// Begin watching.
if (watcher != null && watcher.EnableRaisingEvents)
{
Expand Down Expand Up @@ -165,12 +170,6 @@ private void ReportForm_Load(object sender, EventArgs e)

}

private void showLoginForm()
{
var loginForm = new LoginForm(edapi);
loginForm.Show();
}

private void ReportForm_FormClosing(object sender, FormClosingEventArgs e)
{

Expand All @@ -187,26 +186,35 @@ private void button1_Click(object sender, EventArgs e)
Dispose();
}

private void ReportForm_Shown(object sender, EventArgs e)
private void initialize()
{
if (edapi.isLoginRequired())
{
//show login form
showLoginForm();
var loginForm = new LoginForm(edapi);
if (loginForm.ShowDialog(this) != DialogResult.OK)
{
toolStripStatusLabel1.Text = "Login was cancelled.";
activateButton.Text = "Login";
return;
}
else
loginForm.Dispose();
}
commanderName = edapi.getProfile().CommanderName;
if (!string.IsNullOrEmpty(commanderName))
toolStripStatusLabel1.Text = "Welcome CMDR " + commanderName + ". ";
if (Directory.Exists(Properties.Settings.Default.PicturesFolder))
activateButton_Click(null, null);
else
{
commanderName = edapi.getProfile().CommanderName;
if (!string.IsNullOrEmpty(commanderName))
toolStripStatusLabel1.Text = "Welcome CMDR " + commanderName + ". ";
if (Directory.Exists(Properties.Settings.Default.PicturesFolder))
activateButton_Click(null, null);
else
{
toolStripStatusLabel1.Text = "Configure pictures folder in settings and press Activate button to start watching for missions!";
}
toolStripStatusLabel1.Text = "Configure pictures folder in settings and press Activate button to start watching for missions!";
}

}

private void ReportForm_Shown(object sender, EventArgs e)
{
initialize();
}
}
}
26 changes: 16 additions & 10 deletions EliteReporter/Utils/EDAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public EDAPI()
}
}

private ResponseData makeRequest(string uri, Dictionary<string, string> values = null)
private ResponseData makeRequest(string uri, Dictionary<string, string> values = null, string rawData = "", string method = null)
{
if (uri.Equals("/"))
uri = "";
Expand All @@ -53,20 +53,26 @@ private ResponseData makeRequest(string uri, Dictionary<string, string> values =
request.UserAgent = agent;
var cc = new CookieContainer();
cc.Add(cookieContainer.GetCookies(new Uri(baseUrl)));
request.CookieContainer = cookieContainer;
if (values == null)
request.CookieContainer = cc;
if (values == null && string.IsNullOrEmpty(rawData))
request.Method = "GET";
else
{
request.Method = "POST";
string postData = "";
if (method == null)
request.Method = "POST";
else
request.Method = method;
string postData = rawData;

foreach (string key in values.Keys)
if (values != null)
{
postData += HttpUtility.UrlEncode(key) + "="
+ HttpUtility.UrlEncode(values[key]) + "&";
foreach (string key in values.Keys)
{
postData += HttpUtility.UrlEncode(key) + "="
+ HttpUtility.UrlEncode(values[key]) + "&";
}
postData = postData.TrimEnd('&');
}
postData = postData.TrimEnd('&');
byte[] data = Encoding.ASCII.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Expand Down Expand Up @@ -117,7 +123,7 @@ private ResponseData makeRequest(string uri, Dictionary<string, string> values =
}
}
if (resp.Headers["Location"] != null)
return makeRequest(resp.Headers["Location"], values);
return makeRequest(resp.Headers["Location"], null, responseText, resp.Method);
return new ResponseData()
{
Text = responseText,
Expand Down

0 comments on commit 2f34d81

Please sign in to comment.