1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2018 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 HeuristicLab.MainForm;
|
---|
26 | using CcSettings = HeuristicLab.Clients.Common.Properties;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Clients.Access.Views {
|
---|
29 | public partial class ChangePasswordDialog : Form {
|
---|
30 | public ChangePasswordDialog() {
|
---|
31 | InitializeComponent();
|
---|
32 | }
|
---|
33 |
|
---|
34 | private void cancelButton_Click(object sender, System.EventArgs e) {
|
---|
35 | Close();
|
---|
36 | }
|
---|
37 |
|
---|
38 | private void changePasswordButton_Click(object sender, System.EventArgs e) {
|
---|
39 | SaveUserPasswordConfig();
|
---|
40 | DisplayProgressBar();
|
---|
41 | ExecuteActionAsync(UpdatePassword);
|
---|
42 | }
|
---|
43 |
|
---|
44 | private void UpdatePassword() {
|
---|
45 | UserInformation.Instance.Refresh();
|
---|
46 |
|
---|
47 | if (!UserInformation.Instance.UserExists) {
|
---|
48 | 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);
|
---|
49 | } else {
|
---|
50 | bool result = AccessClient.CallAccessService<bool>(x => x.ChangePassword(UserInformation.Instance.User.Id, oldPasswordTextBox.Text, newPasswordTextBox.Text));
|
---|
51 | if (result) {
|
---|
52 | MessageBox.Show("Password change successfull.", "HeuristicLab Access Service", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
---|
53 | SaveNewUserPasswordConfig();
|
---|
54 | Close();
|
---|
55 | } else {
|
---|
56 | 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);
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | private void SaveUserPasswordConfig() {
|
---|
62 | CcSettings.Settings.Default.UserName = userNameTextBox.Text;
|
---|
63 | CcSettings.Settings.Default.SavePassword = savePasswordCheckBox.Checked;
|
---|
64 | CcSettings.Settings.Default.Password = string.Empty;
|
---|
65 | CcSettings.Settings.Default.Save();
|
---|
66 | CcSettings.Settings.Default.Password = CryptoService.EncryptString(oldPasswordTextBox.Text);
|
---|
67 | if (savePasswordCheckBox.Checked)
|
---|
68 | CcSettings.Settings.Default.Save();
|
---|
69 | }
|
---|
70 |
|
---|
71 | private void SaveNewUserPasswordConfig() {
|
---|
72 | CcSettings.Settings.Default.Password = CryptoService.EncryptString(newPasswordTextBox.Text);
|
---|
73 | if (savePasswordCheckBox.Checked)
|
---|
74 | CcSettings.Settings.Default.Save();
|
---|
75 | }
|
---|
76 |
|
---|
77 | private void DisplayProgressBar() {
|
---|
78 | progressBar.Visible = true;
|
---|
79 | progressBar.Style = ProgressBarStyle.Marquee;
|
---|
80 | progressBar.Value = 0;
|
---|
81 | }
|
---|
82 |
|
---|
83 | private void HideProgressBar() {
|
---|
84 | progressBar.Visible = false;
|
---|
85 | }
|
---|
86 |
|
---|
87 | private void ChangePasswordDialog_Load(object sender, EventArgs e) {
|
---|
88 | userNameTextBox.Text = CcSettings.Settings.Default.UserName;
|
---|
89 | oldPasswordTextBox.Text = CryptoService.DecryptString(CcSettings.Settings.Default.Password);
|
---|
90 | savePasswordCheckBox.Checked = CcSettings.Settings.Default.SavePassword;
|
---|
91 | }
|
---|
92 |
|
---|
93 | public void ExecuteActionAsync(Action action) {
|
---|
94 | var call = new Func<Exception>(delegate() {
|
---|
95 | try {
|
---|
96 | action();
|
---|
97 | }
|
---|
98 | catch (Exception ex) {
|
---|
99 | return ex;
|
---|
100 | }
|
---|
101 | finally {
|
---|
102 | HideProgressBar();
|
---|
103 | }
|
---|
104 | return null;
|
---|
105 | });
|
---|
106 | call.BeginInvoke(delegate(IAsyncResult result) {
|
---|
107 | Exception ex = call.EndInvoke(result);
|
---|
108 | if (ex != null)
|
---|
109 | MainFormManager.MainForm.ShowError(ex.Message, ex);
|
---|
110 | }, null);
|
---|
111 | }
|
---|
112 |
|
---|
113 | #region validation events
|
---|
114 | private void userNameTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
115 | if (userNameTextBox.Text == string.Empty) {
|
---|
116 | e.Cancel = true;
|
---|
117 | errorProvider.SetError(userNameTextBox, "Please enter a user name");
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | private void userNameTextBox_Validated(object sender, EventArgs e) {
|
---|
122 | errorProvider.SetError(userNameTextBox, string.Empty);
|
---|
123 | }
|
---|
124 |
|
---|
125 | private void oldPasswordTextBox_Validated(object sender, EventArgs e) {
|
---|
126 | errorProvider.SetError(oldPasswordTextBox, string.Empty);
|
---|
127 | }
|
---|
128 |
|
---|
129 | private void oldPasswordTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
130 | if (oldPasswordTextBox.Text == string.Empty) {
|
---|
131 | e.Cancel = true;
|
---|
132 | errorProvider.SetError(oldPasswordTextBox, "Please enter a password");
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | private void newPasswordTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
137 | if (newPasswordTextBox.Text == string.Empty) {
|
---|
138 | e.Cancel = true;
|
---|
139 | errorProvider.SetError(newPasswordTextBox, "Please enter a new password");
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | private void newPasswordTextBox_Validated(object sender, EventArgs e) {
|
---|
144 | errorProvider.SetError(newPasswordTextBox, string.Empty);
|
---|
145 | }
|
---|
146 |
|
---|
147 | private void retypedNewPasswordtextBox_Validated(object sender, EventArgs e) {
|
---|
148 | errorProvider.SetError(retypedNewPasswordtextBox, string.Empty);
|
---|
149 | }
|
---|
150 |
|
---|
151 | private void retypedNewPasswordtextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
152 | if (retypedNewPasswordtextBox.Text == string.Empty) {
|
---|
153 | e.Cancel = true;
|
---|
154 | errorProvider.SetError(retypedNewPasswordtextBox, "Please retype the new password");
|
---|
155 | }
|
---|
156 | }
|
---|
157 | #endregion
|
---|
158 | }
|
---|
159 | }
|
---|