mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Fixed saving password on logging in unsecured mode
This commit is contained in:
parent
2e8f8bd7b6
commit
1fce57e119
7 changed files with 31 additions and 16 deletions
|
|
@ -87,7 +87,7 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.ViewHolder
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
Server server = servers.get(getBindingAdapterPosition());
|
||||
saveServerPreference(server.getAddress(), server.getUsername(), server.getToken(), server.getSalt());
|
||||
saveServerPreference(server.getServerId(), server.getAddress(), server.getUsername(), server.isLowSecurity() ? server.getPassword() : null, server.getToken(), server.getSalt());
|
||||
refreshSubsonicClientInstance();
|
||||
|
||||
SystemRepository systemRepository = new SystemRepository(App.getInstance());
|
||||
|
|
@ -98,8 +98,8 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.ViewHolder
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String token, String salt) {
|
||||
saveServerPreference(null, null, token, salt);
|
||||
public void onSuccess(String password, String token, String salt) {
|
||||
saveServerPreference(null, null, null, password, token, salt);
|
||||
enter();
|
||||
}
|
||||
});
|
||||
|
|
@ -121,11 +121,14 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.ViewHolder
|
|||
mainActivity.goFromLogin();
|
||||
}
|
||||
|
||||
private void saveServerPreference(String server, String user, String token, String salt) {
|
||||
private void saveServerPreference(String serverId, String server, String user, String password, String token, String salt) {
|
||||
if (user != null) PreferenceUtil.getInstance(context).setUser(user);
|
||||
if (serverId != null) PreferenceUtil.getInstance(context).setServerId(serverId);
|
||||
if (server != null) PreferenceUtil.getInstance(context).setServer(server);
|
||||
if (password != null) PreferenceUtil.getInstance(context).setPassword(password);
|
||||
|
||||
if (token != null && salt != null) {
|
||||
PreferenceUtil.getInstance(context).setPassword(password);
|
||||
PreferenceUtil.getInstance(context).setToken(token);
|
||||
PreferenceUtil.getInstance(context).setSalt(salt);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ import com.cappielloantonio.play.model.Server;
|
|||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@Database(
|
||||
version = 31,
|
||||
version = 32,
|
||||
entities = {Queue.class, Server.class, RecentSearch.class, Download.class, Playlist.class},
|
||||
autoMigrations = { @AutoMigration(from = 30, to = 31) }
|
||||
autoMigrations = { @AutoMigration(from = 31, to = 32) }
|
||||
)
|
||||
public abstract class AppDatabase extends RoomDatabase {
|
||||
private static final String TAG = "AppDatabase";
|
||||
|
|
|
|||
|
|
@ -4,5 +4,5 @@ public interface SystemCallback {
|
|||
|
||||
void onError(Exception exception);
|
||||
|
||||
void onSuccess(String token, String salt);
|
||||
void onSuccess(String password, String token, String salt);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ public class Server implements Parcelable {
|
|||
@ColumnInfo(name = "username")
|
||||
private String username;
|
||||
|
||||
@ColumnInfo(name = "password")
|
||||
private String password;
|
||||
|
||||
@ColumnInfo(name = "address")
|
||||
private String address;
|
||||
|
||||
|
|
@ -36,10 +39,11 @@ public class Server implements Parcelable {
|
|||
@ColumnInfo(name = "low_security", defaultValue = "false")
|
||||
private boolean lowSecurity;
|
||||
|
||||
public Server(@NonNull String serverId, String serverName, String username, String address, String token, String salt, long timestamp, boolean lowSecurity) {
|
||||
public Server(@NonNull String serverId, String serverName, String username, String password, String address, String token, String salt, long timestamp, boolean lowSecurity) {
|
||||
this.serverId = serverId;
|
||||
this.serverName = serverName;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.address = address;
|
||||
this.token = token;
|
||||
this.salt = salt;
|
||||
|
|
@ -72,6 +76,14 @@ public class Server implements Parcelable {
|
|||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,9 +34,10 @@ public class SystemRepository {
|
|||
if (response.body().getStatus().getValue().equals(ResponseStatus.FAILED)) {
|
||||
callback.onError(new Exception(response.body().getError().getCode().getValue() + " - " + response.body().getError().getMessage()));
|
||||
} else if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||
String salt = response.raw().request().url().queryParameter("s");
|
||||
String password = response.raw().request().url().queryParameter("p");
|
||||
String token = response.raw().request().url().queryParameter("t");
|
||||
callback.onSuccess(token, salt);
|
||||
String salt = response.raw().request().url().queryParameter("s");
|
||||
callback.onSuccess(password, token, salt);
|
||||
} else {
|
||||
callback.onError(new Exception("Empty response"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ public class MainActivity extends BaseActivity {
|
|||
initBottomSheet();
|
||||
initNavigation();
|
||||
|
||||
if (PreferenceUtil.getInstance(this).getToken() != null) {
|
||||
if (PreferenceUtil.getInstance(this).getToken() != null && PreferenceUtil.getInstance(this).getSalt() != null) {
|
||||
goFromLogin();
|
||||
} else {
|
||||
goToLogin();
|
||||
|
|
|
|||
|
|
@ -148,8 +148,8 @@ public class ServerSignupDialog extends DialogFragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String token, String salt) {
|
||||
saveServerPreference(null, null, null, token, salt);
|
||||
public void onSuccess(String password, String token, String salt) {
|
||||
saveServerPreference(null, null, password, token, salt);
|
||||
if (directAccess) enter();
|
||||
}
|
||||
});
|
||||
|
|
@ -167,13 +167,12 @@ public class ServerSignupDialog extends DialogFragment {
|
|||
if (token != null && salt != null) {
|
||||
String serverID = loginViewModel.getServerToEdit() != null ? loginViewModel.getServerToEdit().getServerId() : UUID.randomUUID().toString();
|
||||
|
||||
PreferenceUtil.getInstance(context).setPassword(this.lowSecurity ? password : null);
|
||||
PreferenceUtil.getInstance(context).setToken(token);
|
||||
PreferenceUtil.getInstance(context).setSalt(salt);
|
||||
PreferenceUtil.getInstance(context).setServerId(serverID);
|
||||
|
||||
if (!lowSecurity) PreferenceUtil.getInstance(context).setPassword(null);
|
||||
|
||||
loginViewModel.addServer(new Server(serverID, this.serverName, this.username, this.server, token, salt, System.currentTimeMillis(), this.lowSecurity));
|
||||
loginViewModel.addServer(new Server(serverID, this.serverName, this.username, this.lowSecurity ? password : null, this.server, token, salt, System.currentTimeMillis(), this.lowSecurity));
|
||||
}
|
||||
|
||||
App.getSubsonicClientInstance(context, true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue