|
|
@ -67,29 +67,34 @@ public class LoginActivity extends BaseActivity {
|
|
|
|
String scope = requestedAdmin ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES;
|
|
|
|
String scope = requestedAdmin ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES;
|
|
|
|
oauthVM.createToken(currentInstanceLogin, "authorization_code", client_idLogin, client_secretLogin, Helper.REDIRECT_CONTENT_WEB, scope, code)
|
|
|
|
oauthVM.createToken(currentInstanceLogin, "authorization_code", client_idLogin, client_secretLogin, Helper.REDIRECT_CONTENT_WEB, scope, code)
|
|
|
|
.observe(LoginActivity.this, tokenObj -> {
|
|
|
|
.observe(LoginActivity.this, tokenObj -> {
|
|
|
|
Account account = new Account();
|
|
|
|
if (tokenObj != null) {
|
|
|
|
account.client_id = client_idLogin;
|
|
|
|
Account account = new Account();
|
|
|
|
account.client_secret = client_secretLogin;
|
|
|
|
account.client_id = client_idLogin;
|
|
|
|
account.token = tokenObj.token_type + " " + tokenObj.access_token;
|
|
|
|
account.client_secret = client_secretLogin;
|
|
|
|
account.api = apiLogin;
|
|
|
|
account.token = tokenObj.token_type + " " + tokenObj.access_token;
|
|
|
|
account.software = softwareLogin;
|
|
|
|
account.api = apiLogin;
|
|
|
|
account.instance = currentInstanceLogin;
|
|
|
|
account.software = softwareLogin;
|
|
|
|
//API call to retrieve account information for the new token
|
|
|
|
account.instance = currentInstanceLogin;
|
|
|
|
AccountsVM accountsVM = new ViewModelProvider(LoginActivity.this).get(AccountsVM.class);
|
|
|
|
//API call to retrieve account information for the new token
|
|
|
|
accountsVM.getConnectedAccount(currentInstanceLogin, account.token).observe(LoginActivity.this, mastodonAccount -> {
|
|
|
|
AccountsVM accountsVM = new ViewModelProvider(LoginActivity.this).get(AccountsVM.class);
|
|
|
|
account.mastodon_account = mastodonAccount;
|
|
|
|
accountsVM.getConnectedAccount(currentInstanceLogin, account.token).observe(LoginActivity.this, mastodonAccount -> {
|
|
|
|
account.user_id = mastodonAccount.id;
|
|
|
|
account.mastodon_account = mastodonAccount;
|
|
|
|
//We check if user have really moderator rights
|
|
|
|
account.user_id = mastodonAccount.id;
|
|
|
|
if (requestedAdmin) {
|
|
|
|
//We check if user have really moderator rights
|
|
|
|
AdminVM adminVM = new ViewModelProvider(LoginActivity.this).get(AdminVM.class);
|
|
|
|
if (requestedAdmin) {
|
|
|
|
adminVM.getAccount(account.instance, account.token, account.user_id).observe(LoginActivity.this, adminAccount -> {
|
|
|
|
AdminVM adminVM = new ViewModelProvider(LoginActivity.this).get(AdminVM.class);
|
|
|
|
account.admin = adminAccount != null;
|
|
|
|
adminVM.getAccount(account.instance, account.token, account.user_id).observe(LoginActivity.this, adminAccount -> {
|
|
|
|
|
|
|
|
account.admin = adminAccount != null;
|
|
|
|
|
|
|
|
WebviewConnectActivity.proceedLogin(LoginActivity.this, account);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
WebviewConnectActivity.proceedLogin(LoginActivity.this, account);
|
|
|
|
WebviewConnectActivity.proceedLogin(LoginActivity.this, account);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
});
|
|
|
|
WebviewConnectActivity.proceedLogin(LoginActivity.this, account);
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
Toasty.error(LoginActivity.this, getString(R.string.toast_token), Toast.LENGTH_LONG).show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|