1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Windows.Forms;
|
---|
24 | using HeuristicLab.Clients.Common;
|
---|
25 | using CcSettings = HeuristicLab.Clients.Common.Properties;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Clients.Access.Views {
|
---|
28 | public partial class ChangePasswordDialog : Form {
|
---|
29 | public ChangePasswordDialog() {
|
---|
30 | InitializeComponent();
|
---|
31 | }
|
---|
32 |
|
---|
33 | private void cancelButton_Click(object sender, System.EventArgs e) {
|
---|
34 | Close();
|
---|
35 | }
|
---|
36 |
|
---|
37 | private void changePasswordButton_Click(object sender, System.EventArgs e) {
|
---|
38 | SaveUserPasswordConfig();
|
---|
39 | DisplayProgressBar();
|
---|
40 | ExecuteActionAsync(UpdatePassword);
|
---|
41 | }
|
---|
42 |
|
---|
43 | private void UpdatePassword() {
|
---|
44 | UserInformation.Instance.Refresh();
|
---|
45 |
|
---|
46 | if (!UserInformation.Instance.UserExists) {
|
---|
47 | MessageBox.Show("Couldn't fetch user information from the server." + Environment.NewLine + "Please verify that you have an existing user and that your user name and password is correct. ", "HeuristicLab Access Service", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
48 | } else {
|
---|
49 | bool result = AccessClient.CallAccessService<bool>(x => x.ChangePassword(UserInformation.Instance.User.Id, oldPasswordTextBox.Text, newPasswordTextBox.Text));
|
---|
50 | if (result) {
|
---|
51 | MessageBox.Show("Password change successfull.", "HeuristicLab Access Service", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
---|
52 | SaveNewUserPasswordConfig();
|
---|
53 | Close();
|
---|
54 | } else {
|
---|
55 | MessageBox.Show("Password change failed. " + Environment.NewLine + "Please check the entered passwords to conform with the passwords standards.", "HeuristicLab Access Service", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | private void SaveUserPasswordConfig() {
|
---|
61 | CcSettings.Settings.Default.UserName = userNameTextBox.Text;
|
---|
62 | CcSettings.Settings.Default.SavePassword = savePasswordCheckBox.Checked;
|
---|
63 | CcSettings.Settings.Default.Password = string.Empty;
|
---|
64 | CcSettings.Settings.Default.Save();
|
---|
65 | CcSettings.Settings.Default.Password = CryptoService.EncryptString(oldPasswordTextBox.Text);
|
---|
66 | if (savePasswordCheckBox.Checked)
|
---|
67 | CcSettings.Settings.Default.Save();
|
---|
68 | }
|
---|
69 |
|
---|
70 | private void SaveNewUserPasswordConfig() {
|
---|
71 | CcSettings.Settings.Default.Password = CryptoService.EncryptString(newPasswordTextBox.Text);
|
---|
72 | if (savePasswordCheckBox.Checked)
|
---|
73 | CcSettings.Settings.Default.Save();
|
---|
74 | }
|
---|
75 |
|
---|
76 | private void DisplayProgressBar() {
|
---|
77 | progressBar.Visible = true;
|
---|
78 | progressBar.Style = ProgressBarStyle.Marquee;
|
---|
79 | progressBar.Value = 0;
|
---|
80 | }
|
---|
81 |
|
---|
82 | private void HideProgressBar() {
|
---|
83 | progressBar.Visible = false;
|
---|
84 | }
|
---|
85 |
|
---|
86 | private void ChangePasswordDialog_Load(object sender, EventArgs e) {
|
---|
87 | userNameTextBox.Text = CcSettings.Settings.Default.UserName;
|
---|
88 | oldPasswordTextBox.Text = CryptoService.DecryptString(CcSettings.Settings.Default.Password);
|
---|
89 | savePasswordCheckBox.Checked = CcSettings.Settings.Default.SavePassword;
|
---|
90 | }
|
---|
91 |
|
---|
92 | public void ExecuteActionAsync(Action action) {
|
---|
93 | var call = new Func<Exception>(delegate() {
|
---|
94 | try {
|
---|
95 | action();
|
---|
96 | }
|
---|
97 | catch (Exception ex) {
|
---|
98 | return ex;
|
---|
99 | }
|
---|
100 | finally {
|
---|
101 | HideProgressBar();
|
---|
102 | }
|
---|
103 | return null;
|
---|
104 | });
|
---|
105 | call.BeginInvoke(delegate(IAsyncResult result) {
|
---|
106 | Exception ex = call.EndInvoke(result);
|
---|
107 | if (ex != null) PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex);
|
---|
108 | }, null);
|
---|
109 | }
|
---|
110 |
|
---|
111 | #region validation events
|
---|
112 | private void userNameTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
113 | if (userNameTextBox.Text == string.Empty) {
|
---|
114 | e.Cancel = true;
|
---|
115 | errorProvider.SetError(userNameTextBox, "Please enter a user name");
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | private void userNameTextBox_Validated(object sender, EventArgs e) {
|
---|
120 | errorProvider.SetError(userNameTextBox, string.Empty);
|
---|
121 | }
|
---|
122 |
|
---|
123 | private void oldPasswordTextBox_Validated(object sender, EventArgs e) {
|
---|
124 | errorProvider.SetError(oldPasswordTextBox, string.Empty);
|
---|
125 | }
|
---|
126 |
|
---|
127 | private void oldPasswordTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
128 | if (oldPasswordTextBox.Text == string.Empty) {
|
---|
129 | e.Cancel = true;
|
---|
130 | errorProvider.SetError(oldPasswordTextBox, "Please enter a password");
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | private void newPasswordTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
135 | if (newPasswordTextBox.Text == string.Empty) {
|
---|
136 | e.Cancel = true;
|
---|
137 | errorProvider.SetError(newPasswordTextBox, "Please enter a new password");
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | private void newPasswordTextBox_Validated(object sender, EventArgs e) {
|
---|
142 | errorProvider.SetError(newPasswordTextBox, string.Empty);
|
---|
143 | }
|
---|
144 |
|
---|
145 | private void retypedNewPasswordtextBox_Validated(object sender, EventArgs e) {
|
---|
146 | errorProvider.SetError(retypedNewPasswordtextBox, string.Empty);
|
---|
147 | }
|
---|
148 |
|
---|
149 | private void retypedNewPasswordtextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
150 | if (retypedNewPasswordtextBox.Text == string.Empty) {
|
---|
151 | e.Cancel = true;
|
---|
152 | errorProvider.SetError(retypedNewPasswordtextBox, "Please retype the new password");
|
---|
153 | }
|
---|
154 | }
|
---|
155 | #endregion
|
---|
156 | }
|
---|
157 | }
|
---|