mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix EDU-794 Changes in stepik credentials in Settings aren't saved
Refactor settings creation: 1) Erase password on login change 2) Do not erase password on focus gained by password field 3) Use lambda instead of anonymous class where possible Refactor stepik settings: 1) Login in settings under progress 2) Do not save new credentials until they are posted on stepic 3) Remove default password for show: set user password in stepik settings panel
This commit is contained in:
+3
-1
@@ -52,7 +52,9 @@ public class CCOptions implements StudyOptionsProvider {
|
||||
|
||||
@Override
|
||||
public void apply() throws ConfigurationException {
|
||||
CCSettings.getInstance().setUseHtmlAsDefaultTaskFormat(myHtmlRadioButton.isSelected());
|
||||
if (isModified()) {
|
||||
CCSettings.getInstance().setUseHtmlAsDefaultTaskFormat(myHtmlRadioButton.isSelected());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
@@ -182,6 +182,7 @@ public class EduStepicAuthorizedClient {
|
||||
return stepicUser[0];
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static StepicUser login(@NotNull final String email, @NotNull final String password) {
|
||||
final List<NameValuePair> parameters = new ArrayList<>();
|
||||
if (password.isEmpty()) return null;
|
||||
|
||||
+29
-49
@@ -16,6 +16,8 @@
|
||||
package com.jetbrains.edu.learning.stepic;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
@@ -27,17 +29,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.text.PlainDocument;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
|
||||
public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
private static final String DEFAULT_PASSWORD_TEXT = "************";
|
||||
private static final Logger LOG = Logger.getInstance(StepicStudyOptions.class);
|
||||
private JTextField myLoginTextField;
|
||||
private JPasswordField myPasswordField;
|
||||
@@ -47,6 +43,14 @@ public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
private boolean myCredentialsModified;
|
||||
|
||||
public StepicStudyOptions() {
|
||||
myLoginTextField.getDocument().addDocumentListener(new DocumentAdapter() {
|
||||
@Override
|
||||
protected void textChanged(DocumentEvent e) {
|
||||
myCredentialsModified = true;
|
||||
erasePassword();
|
||||
}
|
||||
});
|
||||
|
||||
myPasswordField.getDocument().addDocumentListener(new DocumentAdapter() {
|
||||
@Override
|
||||
protected void textChanged(DocumentEvent e) {
|
||||
@@ -54,36 +58,7 @@ public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
}
|
||||
});
|
||||
|
||||
DocumentListener passwordEraser = new DocumentAdapter() {
|
||||
@Override
|
||||
protected void textChanged(DocumentEvent e) {
|
||||
if (!myCredentialsModified) {
|
||||
erasePassword();
|
||||
}
|
||||
}
|
||||
};
|
||||
myLoginTextField.getDocument().addDocumentListener(passwordEraser);
|
||||
|
||||
myPasswordField.addFocusListener(new FocusListener() {
|
||||
@Override
|
||||
public void focusGained(FocusEvent e) {
|
||||
if (!myCredentialsModified && !getPassword().isEmpty()) {
|
||||
erasePassword();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusLost(FocusEvent e) {
|
||||
}
|
||||
});
|
||||
|
||||
myEnableTestingFromSamples.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
myCredentialsModified = true;
|
||||
}
|
||||
});
|
||||
reset();
|
||||
myEnableTestingFromSamples.addChangeListener(e -> myCredentialsModified = true);
|
||||
}
|
||||
|
||||
private void erasePassword() {
|
||||
@@ -107,12 +82,11 @@ public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
|
||||
@NotNull
|
||||
private String getPassword() {
|
||||
final String passwordText = String.valueOf(myPasswordField.getPassword());
|
||||
return passwordText.equals(DEFAULT_PASSWORD_TEXT) ? "" : passwordText;
|
||||
return String.valueOf(myPasswordField.getPassword());
|
||||
}
|
||||
|
||||
private void setPassword(@NotNull final String password) {
|
||||
myPasswordField.setText(StringUtil.isEmpty(password) ? null : password);
|
||||
myPasswordField.setText(password);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,7 +96,7 @@ public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
|
||||
final StepicUser user = taskManager.getUser();
|
||||
setLogin(user.getEmail());
|
||||
setPassword(DEFAULT_PASSWORD_TEXT);
|
||||
setPassword(user.getPassword());
|
||||
myEnableTestingFromSamples.setSelected(taskManager.isEnableTestingFromSamples());
|
||||
resetCredentialsModification();
|
||||
}
|
||||
@@ -137,7 +111,7 @@ public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
public void apply() throws ConfigurationException {
|
||||
if (myCredentialsModified) {
|
||||
final Project project = StudyUtils.getStudyProject();
|
||||
if (project != null) {
|
||||
@@ -146,14 +120,20 @@ public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
final String login = getLogin();
|
||||
final String password = getPassword();
|
||||
if (!StringUtil.isEmptyOrSpaces(login) && !StringUtil.isEmptyOrSpaces(password)) {
|
||||
final StepicUser user = taskManager.getUser();
|
||||
user.setEmail(login);
|
||||
user.setPassword(password);
|
||||
|
||||
// login to post credentials
|
||||
final StepicUser stepicUser = EduStepicAuthorizedClient.login(login, password);
|
||||
if (stepicUser != null) {
|
||||
taskManager.setUser(stepicUser);
|
||||
final StepicUser[] stepicUser = new StepicUser[1];
|
||||
ProgressManager.getInstance().runProcessWithProgressSynchronously(
|
||||
() -> {
|
||||
ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
|
||||
stepicUser[0] = StudyUtils.execCancelable(() -> EduStepicAuthorizedClient.login(login, password));
|
||||
}, "Logging In", true,
|
||||
project);
|
||||
|
||||
if (stepicUser[0] != null && stepicUser[0].getAccessToken() != null) {
|
||||
taskManager.setUser(stepicUser[0]);
|
||||
}
|
||||
else {
|
||||
throw new ConfigurationException("Unable to login");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,7 +153,7 @@ public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
public boolean isModified() {
|
||||
return myCredentialsModified;
|
||||
}
|
||||
|
||||
|
||||
public void resetCredentialsModification() {
|
||||
myCredentialsModified = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user