mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 02:37:03 -07:00
Refactoring for CredentialsDialog usage (not finished yet)
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@886 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
dd630f20a1
commit
cf699594f9
5 changed files with 62 additions and 154 deletions
|
@ -19,7 +19,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace GreenshotJiraPlugin {
|
||||
partial class LoginForm {
|
||||
partial class SettingsForm {
|
||||
/// <summary>
|
||||
/// Designer variable used to keep track of non-visual components.
|
||||
/// </summary>
|
||||
|
@ -46,35 +46,12 @@ namespace GreenshotJiraPlugin {
|
|||
/// </summary>
|
||||
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;
|
||||
}
|
|
@ -28,10 +28,10 @@ namespace GreenshotJiraPlugin {
|
|||
/// <summary>
|
||||
/// Description of PasswordRequestForm.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -54,9 +54,9 @@
|
|||
<Compile Include="Forms\JiraForm.cs" />
|
||||
<Compile Include="Forms\JiraForm.Designer.cs" />
|
||||
<Compile Include="Forms\ListViewColumnSorter.cs" />
|
||||
<Compile Include="Forms\LoginForm.cs" />
|
||||
<Compile Include="Forms\LoginForm.Designer.cs">
|
||||
<DependentUpon>LoginForm.cs</DependentUpon>
|
||||
<Compile Include="Forms\SettingsForm.cs" />
|
||||
<Compile Include="Forms\SettingsForm.Designer.cs">
|
||||
<DependentUpon>SettingsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Jira.cs" />
|
||||
<Compile Include="JiraConfiguration.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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal login which catches the exceptions
|
||||
/// </summary>
|
||||
/// <returns>true if login was done sucessfully</returns>
|
||||
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() {
|
||||
|
|
|
@ -30,49 +30,25 @@ namespace GreenshotJiraPlugin {
|
|||
/// </summary>
|
||||
[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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A form for username/password
|
||||
/// </summary>
|
||||
/// <returns>bool true if OK was pressed, false if cancel</returns>
|
||||
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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue