* allow deletion of OSDB login
This commit is contained in:
parent
a5652f4d0e
commit
a2722d22f4
|
@ -8,7 +8,6 @@ import static net.filebot.util.FileUtilities.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -287,16 +286,27 @@ public final class WebServices {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLogin(String id, String user, String password) {
|
public static void setLogin(String id, String user, String password) {
|
||||||
if (user == null || password == null || user.contains(LOGIN_SEPARATOR) || (user.isEmpty() && !password.isEmpty()) || (!user.isEmpty() && password.isEmpty())) {
|
// delete login
|
||||||
throw new IllegalArgumentException(String.format("Illegal login: %s:%s", user, password));
|
if ((user == null || user.isEmpty()) && (password == null || password.isEmpty())) {
|
||||||
}
|
if (LOGIN_OPENSUBTITLES.equals(id)) {
|
||||||
|
OpenSubtitles.setUser("", "");
|
||||||
if (LOGIN_OPENSUBTITLES.equals(id)) {
|
Settings.forPackage(WebServices.class).remove(id);
|
||||||
String password_md5 = md5(StandardCharsets.UTF_8.encode(password));
|
} else {
|
||||||
OpenSubtitles.setUser(user, password_md5);
|
throw new IllegalArgumentException();
|
||||||
Settings.forPackage(WebServices.class).put(id, String.join(LOGIN_SEPARATOR, user, password_md5));
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException();
|
// enter login
|
||||||
|
if (user == null || password == null || user.contains(LOGIN_SEPARATOR) || (user.isEmpty() && !password.isEmpty()) || (!user.isEmpty() && password.isEmpty())) {
|
||||||
|
throw new IllegalArgumentException(String.format("Illegal login: %s:%s", user, password));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LOGIN_OPENSUBTITLES.equals(id)) {
|
||||||
|
String password_md5 = md5(password);
|
||||||
|
OpenSubtitles.setUser(user, password_md5);
|
||||||
|
Settings.forPackage(WebServices.class).put(id, String.join(LOGIN_SEPARATOR, user, password_md5));
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.filebot.ui.subtitle;
|
||||||
import static net.filebot.Settings.*;
|
import static net.filebot.Settings.*;
|
||||||
import static net.filebot.ui.LanguageComboBoxModel.*;
|
import static net.filebot.ui.LanguageComboBoxModel.*;
|
||||||
import static net.filebot.ui.NotificationLogging.*;
|
import static net.filebot.ui.NotificationLogging.*;
|
||||||
|
import static net.filebot.util.FileUtilities.*;
|
||||||
import static net.filebot.util.ui.SwingUI.*;
|
import static net.filebot.util.ui.SwingUI.*;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
@ -291,9 +292,9 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
|
||||||
osdbGroup.add(osdbPass, "growx, wrap unrel");
|
osdbGroup.add(osdbPass, "growx, wrap unrel");
|
||||||
|
|
||||||
// restore values
|
// restore values
|
||||||
String[] osdbAuth = WebServices.getLogin("osdb.user");
|
String[] osdbAuth = WebServices.getLogin(WebServices.LOGIN_OPENSUBTITLES);
|
||||||
osdbUser.setText(osdbAuth[0]);
|
osdbUser.setText(osdbAuth[0]);
|
||||||
osdbPass.setText(osdbAuth[1]);
|
// osdbPass.setText(osdbAuth[1]); // password is stored as MD5 hash so we can't restore it
|
||||||
|
|
||||||
if (osdbUser.getText().isEmpty()) {
|
if (osdbUser.getText().isEmpty()) {
|
||||||
osdbGroup.add(new LinkButton("Register", "Register to increase your download quota", WebServices.OpenSubtitles.getIcon(), URI.create("http://www.opensubtitles.org/en/newuser")), "spanx 2, tag left");
|
osdbGroup.add(new LinkButton("Register", "Register to increase your download quota", WebServices.OpenSubtitles.getIcon(), URI.create("http://www.opensubtitles.org/en/newuser")), "spanx 2, tag left");
|
||||||
|
@ -317,7 +318,7 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
|
||||||
try {
|
try {
|
||||||
if (osdbUser.getText().length() > 0 && osdbPass.getPassword().length > 0) {
|
if (osdbUser.getText().length() > 0 && osdbPass.getPassword().length > 0) {
|
||||||
final OpenSubtitlesClient osdb = new OpenSubtitlesClient(getApplicationName(), getApplicationVersion());
|
final OpenSubtitlesClient osdb = new OpenSubtitlesClient(getApplicationName(), getApplicationVersion());
|
||||||
osdb.setUser(osdbUser.getText(), new String(osdbPass.getPassword()));
|
osdb.setUser(osdbUser.getText(), md5(new String(osdbPass.getPassword())));
|
||||||
osdb.login();
|
osdb.login();
|
||||||
|
|
||||||
// do some status checks in background (since OpenSubtitles can be really really slow)
|
// do some status checks in background (since OpenSubtitles can be really really slow)
|
||||||
|
@ -333,6 +334,8 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
|
||||||
Logger.getLogger(SubtitlePanel.class.getName()).log(Level.WARNING, e.toString());
|
Logger.getLogger(SubtitlePanel.class.getName()).log(Level.WARNING, e.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else if (osdbUser.getText().isEmpty()) {
|
||||||
|
WebServices.setLogin(WebServices.LOGIN_OPENSUBTITLES, null, null); // delete login details
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
UILogger.log(Level.WARNING, "OpenSubtitles: " + e.getMessage());
|
UILogger.log(Level.WARNING, "OpenSubtitles: " + e.getMessage());
|
||||||
|
@ -341,7 +344,7 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
|
||||||
|
|
||||||
authPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
authPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||||
if (approved) {
|
if (approved) {
|
||||||
WebServices.setLogin("osdb.user", osdbUser.getText(), new String(osdbPass.getPassword()));
|
WebServices.setLogin(WebServices.LOGIN_OPENSUBTITLES, osdbUser.getText(), new String(osdbPass.getPassword()));
|
||||||
authPanel.setVisible(false);
|
authPanel.setVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import java.math.BigInteger;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.AtomicMoveNotSupportedException;
|
import java.nio.file.AtomicMoveNotSupportedException;
|
||||||
import java.nio.file.FileVisitOption;
|
import java.nio.file.FileVisitOption;
|
||||||
import java.nio.file.FileVisitResult;
|
import java.nio.file.FileVisitResult;
|
||||||
|
@ -630,6 +631,10 @@ public final class FileUtilities {
|
||||||
return Pattern.compile("\\s*[\\\\/]+\\s*").matcher(path).replaceAll(replacement);
|
return Pattern.compile("\\s*[\\\\/]+\\s*").matcher(path).replaceAll(replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String md5(String string) {
|
||||||
|
return md5(StandardCharsets.UTF_8.encode(string));
|
||||||
|
}
|
||||||
|
|
||||||
public static String md5(byte[] data) {
|
public static String md5(byte[] data) {
|
||||||
return md5(ByteBuffer.wrap(data));
|
return md5(ByteBuffer.wrap(data));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue