diff --git a/GreenshotJiraPlugin/Forms/LoginForm.Designer.cs b/GreenshotJiraPlugin/Forms/SettingsForm.Designer.cs
similarity index 58%
rename from GreenshotJiraPlugin/Forms/LoginForm.Designer.cs
rename to GreenshotJiraPlugin/Forms/SettingsForm.Designer.cs
index 537b398f2..540e00ec3 100644
--- a/GreenshotJiraPlugin/Forms/LoginForm.Designer.cs
+++ b/GreenshotJiraPlugin/Forms/SettingsForm.Designer.cs
@@ -19,7 +19,7 @@
* along with this program. If not, see .
*/
namespace GreenshotJiraPlugin {
- partial class LoginForm {
+ partial class SettingsForm {
///
/// Designer variable used to keep track of non-visual components.
///
@@ -46,35 +46,12 @@ namespace GreenshotJiraPlugin {
///
private void InitializeComponent()
{
- this.textBoxPassword = new System.Windows.Forms.TextBox();
- this.label_password = new System.Windows.Forms.Label();
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
- this.label_user = new System.Windows.Forms.Label();
- this.textBoxUser = new System.Windows.Forms.TextBox();
this.label_url = new System.Windows.Forms.Label();
this.textBoxUrl = new System.Windows.Forms.TextBox();
- this.checkBoxDoNotStorePassword = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
- // textBoxPassword
- //
- this.textBoxPassword.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.textBoxPassword.Location = new System.Drawing.Point(102, 73);
- this.textBoxPassword.Name = "textBoxPassword";
- this.textBoxPassword.PasswordChar = '*';
- this.textBoxPassword.Size = new System.Drawing.Size(276, 20);
- this.textBoxPassword.TabIndex = 0;
- this.textBoxPassword.KeyUp += new System.Windows.Forms.KeyEventHandler(this.TextBoxPasswordKeyUp);
- //
- // label_password
- //
- this.label_password.Location = new System.Drawing.Point(12, 73);
- this.label_password.Name = "label_password";
- this.label_password.Size = new System.Drawing.Size(84, 20);
- this.label_password.TabIndex = 1;
- this.label_password.Text = "Password";
- //
// buttonOK
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@@ -97,22 +74,6 @@ namespace GreenshotJiraPlugin {
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancelClick);
//
- // label_user
- //
- this.label_user.Location = new System.Drawing.Point(12, 47);
- this.label_user.Name = "label_user";
- this.label_user.Size = new System.Drawing.Size(84, 20);
- this.label_user.TabIndex = 5;
- this.label_user.Text = "User";
- //
- // textBoxUser
- //
- this.textBoxUser.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.textBoxUser.Location = new System.Drawing.Point(102, 47);
- this.textBoxUser.Name = "textBoxUser";
- this.textBoxUser.Size = new System.Drawing.Size(276, 20);
- this.textBoxUser.TabIndex = 4;
- //
// label_url
//
this.label_url.Location = new System.Drawing.Point(12, 21);
@@ -129,44 +90,22 @@ namespace GreenshotJiraPlugin {
this.textBoxUrl.Size = new System.Drawing.Size(276, 20);
this.textBoxUrl.TabIndex = 6;
//
- // checkBoxDoNotStorePassword
- //
- this.checkBoxDoNotStorePassword.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.checkBoxDoNotStorePassword.Checked = true;
- this.checkBoxDoNotStorePassword.CheckState = System.Windows.Forms.CheckState.Checked;
- this.checkBoxDoNotStorePassword.Location = new System.Drawing.Point(102, 99);
- this.checkBoxDoNotStorePassword.Name = "checkBoxDoNotStorePassword";
- this.checkBoxDoNotStorePassword.Size = new System.Drawing.Size(276, 24);
- this.checkBoxDoNotStorePassword.TabIndex = 8;
- this.checkBoxDoNotStorePassword.Text = "Do not store the password";
- this.checkBoxDoNotStorePassword.UseVisualStyleBackColor = true;
- //
- // LoginForm
+ // SettingsForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(387, 174);
- this.Controls.Add(this.checkBoxDoNotStorePassword);
this.Controls.Add(this.label_url);
this.Controls.Add(this.textBoxUrl);
- this.Controls.Add(this.label_user);
- this.Controls.Add(this.textBoxUser);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
- this.Controls.Add(this.label_password);
- this.Controls.Add(this.textBoxPassword);
- this.Name = "LoginForm";
+ this.Name = "SettingsForm";
this.Text = "Please enter your Jira data";
this.ResumeLayout(false);
this.PerformLayout();
}
- private System.Windows.Forms.CheckBox checkBoxDoNotStorePassword;
private System.Windows.Forms.TextBox textBoxUrl;
private System.Windows.Forms.Label label_url;
- private System.Windows.Forms.TextBox textBoxUser;
- private System.Windows.Forms.Label label_password;
- private System.Windows.Forms.Label label_user;
- private System.Windows.Forms.TextBox textBoxPassword;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.Button buttonOK;
}
diff --git a/GreenshotJiraPlugin/Forms/LoginForm.cs b/GreenshotJiraPlugin/Forms/SettingsForm.cs
similarity index 70%
rename from GreenshotJiraPlugin/Forms/LoginForm.cs
rename to GreenshotJiraPlugin/Forms/SettingsForm.cs
index 6ece429a9..d2f59fbd3 100644
--- a/GreenshotJiraPlugin/Forms/LoginForm.cs
+++ b/GreenshotJiraPlugin/Forms/SettingsForm.cs
@@ -28,10 +28,10 @@ namespace GreenshotJiraPlugin {
///
/// Description of PasswordRequestForm.
///
- public partial class LoginForm : Form {
+ public partial class SettingsForm : Form {
private ILanguage lang = Language.GetInstance();
- public LoginForm() {
+ public SettingsForm() {
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
@@ -41,11 +41,8 @@ namespace GreenshotJiraPlugin {
private void InitializeTexts() {
this.label_url.Text = lang.GetString(LangKey.label_url);
- this.label_user.Text = lang.GetString(LangKey.label_user);
- this.label_password.Text = lang.GetString(LangKey.label_password);
this.buttonOK.Text = lang.GetString(LangKey.OK);
this.buttonCancel.Text = lang.GetString(LangKey.CANCEL);
- this.checkBoxDoNotStorePassword.Text = lang.GetString(LangKey.label_no_password_store);
this.Text = lang.GetString(LangKey.login_title);
}
@@ -54,21 +51,6 @@ namespace GreenshotJiraPlugin {
set {textBoxUrl.Text = value;}
}
- public string User {
- get {return textBoxUser.Text;}
- set {textBoxUser.Text = value;}
- }
-
- public string Password {
- get {return textBoxPassword.Text;}
- set {textBoxPassword.Text = value;}
- }
-
- public bool DoNotStorePassword {
- get {return checkBoxDoNotStorePassword.Checked;}
- set {checkBoxDoNotStorePassword.Checked = value;}
- }
-
void ButtonOKClick(object sender, EventArgs e) {
this.DialogResult = DialogResult.OK;
}
@@ -76,11 +58,5 @@ namespace GreenshotJiraPlugin {
void ButtonCancelClick(object sender, System.EventArgs e) {
this.DialogResult = DialogResult.Cancel;
}
-
- void TextBoxPasswordKeyUp(object sender, KeyEventArgs e) {
- if (e.KeyCode == Keys.Enter) {
- this.DialogResult = DialogResult.OK;
- }
- }
}
}
diff --git a/GreenshotJiraPlugin/GreenshotJiraPlugin.csproj b/GreenshotJiraPlugin/GreenshotJiraPlugin.csproj
index 39a0ec5c5..337fb2039 100644
--- a/GreenshotJiraPlugin/GreenshotJiraPlugin.csproj
+++ b/GreenshotJiraPlugin/GreenshotJiraPlugin.csproj
@@ -54,9 +54,9 @@
-
-
- LoginForm.cs
+
+
+ SettingsForm.cs
diff --git a/GreenshotJiraPlugin/Jira.cs b/GreenshotJiraPlugin/Jira.cs
index dd1d7501f..43cfb0aec 100644
--- a/GreenshotJiraPlugin/Jira.cs
+++ b/GreenshotJiraPlugin/Jira.cs
@@ -25,8 +25,9 @@ using System.IO;
using System.Text;
using System.Windows.Forms;
-using GreenshotJiraPlugin;
using Greenshot.Core;
+using Greenshot.Helpers;
+using GreenshotJiraPlugin;
namespace Jira {
#region transport classes
@@ -113,39 +114,55 @@ namespace Jira {
logout();
}
+ ///
+ /// Internal login which catches the exceptions
+ ///
+ /// true if login was done sucessfully
+ private bool doLogin(string user, string password) {
+ try {
+ this.credentials = jira.login(user, password);
+ this.loggedInTime = DateTime.Now;
+ this.loggedIn = true;
+ } catch (Exception e) {
+ // check if auth failed
+ if (e.Message.Contains(AUTH_FAILED_EXCEPTION_NAME)) {
+ return false;
+ }
+ // Not an authentication issue
+ this.loggedIn = false;
+ this.credentials = null;
+ e.Data.Add("user", user);
+ e.Data.Add("url", config.Url);
+ throw e;
+ }
+ return true;
+ }
+
public void login() {
logout();
try {
- if (config.HasPassword()) {
- this.credentials = jira.login(config.User, config.Password);
- } else if (config.HasTmpPassword()) {
- this.credentials = jira.login(config.User, config.TmpPassword);
- } else {
- if (config.ShowConfigDialog()) {
- if (config.HasPassword()) {
- this.credentials = jira.login(config.User, config.Password);
- } else if (config.HasTmpPassword()) {
- this.credentials = jira.login(config.User, config.TmpPassword);
- }
- } else {
- throw new Exception("User pressed cancel!");
- }
- }
- this.loggedInTime = DateTime.Now;
- this.loggedIn = true;
- } catch (Exception e) {
- this.loggedIn = false;
- this.credentials = null;
- e.Data.Add("user",config.User);
- e.Data.Add("url",config.Url);
- if (e.Message.Contains(AUTH_FAILED_EXCEPTION_NAME)) {
- // Login failed due to wrong user or password, password should be removed!
- config.Password = null;
- config.TmpPassword = null;
- throw new Exception(e.Message.Replace(AUTH_FAILED_EXCEPTION_NAME+ ": ",""));
- }
- throw e;
- }
+ CredentialsDialog dialog = new CredentialsDialog(config.Url.Replace(JiraConfiguration.DEFAULT_PREFIX,"").Replace(JiraConfiguration.DEFAULT_POSTFIX,""));
+ dialog.Name = null;
+ while (dialog.Show(dialog.Name) == DialogResult.OK) {
+ if (doLogin(dialog.Name, dialog.Password)) {
+ if (dialog.SaveChecked) {
+ dialog.Confirm(true);
+ }
+ return;
+ } else {
+ try {
+ dialog.Confirm(false);
+ } catch (ApplicationException e) {
+ // exception handling ...
+ LOG.Error("Problem using the credentials dialog", e);
+ }
+ dialog.IncorrectPassword = true;
+ }
+ }
+ } catch (ApplicationException e) {
+ // exception handling ...
+ LOG.Error("Problem using the credentials dialog", e);
+ }
}
public void logout() {
diff --git a/GreenshotJiraPlugin/JiraConfiguration.cs b/GreenshotJiraPlugin/JiraConfiguration.cs
index 0cf8e6f97..5a4a93f6a 100644
--- a/GreenshotJiraPlugin/JiraConfiguration.cs
+++ b/GreenshotJiraPlugin/JiraConfiguration.cs
@@ -30,49 +30,25 @@ namespace GreenshotJiraPlugin {
///
[IniSection("Jira", Description="Greenshot Jira Plugin configuration")]
public class JiraConfiguration : IniSection {
- [IniProperty("Url", Description="Url to Jira system, including wsdl.", DefaultValue="http://jira/rpc/soap/jirasoapservice-v2?wsdl")]
+ public const string DEFAULT_POSTFIX = "/rpc/soap/jirasoapservice-v2?wsdl";
+ public const string DEFAULT_PREFIX = "http://";
+ private const string DEFAULT_URL = DEFAULT_PREFIX + "jira" + DEFAULT_POSTFIX;
+ [IniProperty("Url", Description="Url to Jira system, including wsdl.", DefaultValue=DEFAULT_URL)]
public string Url;
[IniProperty("Timeout", Description="Session timeout in minutes", DefaultValue="30")]
public int Timeout;
- [IniProperty("User", Description="User for the Jira System")]
- public string User;
- [IniProperty("Password", Description="Password for the Jira System, belonging to user.")]
- public string Password;
- // This will not be stored
- public string TmpPassword;
- public bool HasPassword() {
- return (Password != null && Password.Length > 0);
- }
-
- public bool HasTmpPassword() {
- return (TmpPassword != null && TmpPassword.Length > 0);
- }
-
///
/// A form for username/password
///
/// bool true if OK was pressed, false if cancel
public bool ShowConfigDialog() {
- LoginForm pwForm = new LoginForm();
- if (User == null || User.Length == 0) {
- User = Environment.UserName;
- }
- pwForm.User = User;
+ SettingsForm pwForm = new SettingsForm();
pwForm.Url = Url;
DialogResult result = pwForm.ShowDialog();
if (result == DialogResult.OK) {
- if (pwForm.DoNotStorePassword) {
- TmpPassword = pwForm.Password;
- Password = null;
- } else {
- Password = pwForm.Password;
- TmpPassword = null;
- }
-
- if (!pwForm.User.Equals(User) ||!pwForm.Url.Equals(Url)) {
- User = pwForm.User;
+ if (!pwForm.Url.Equals(Url)) {
Url = pwForm.Url;
}
IniConfig.Save();