Search in sources :

Example 6 with TokenInfo

use of org.stepik.api.objects.auth.TokenInfo in project intellij-plugins by StepicOrg.

the class AbstractAuthorizationPostQuery method execute.

@NotNull
@Override
public TokenInfo execute() {
    TokenInfo tokenInfo = super.execute();
    StepikAbstractAction action = getStepikAction();
    action.getStepikApiClient().setTokenInfo(tokenInfo);
    return tokenInfo;
}
Also used : TokenInfo(org.stepik.api.objects.auth.TokenInfo) StepikAbstractAction(org.stepik.api.actions.StepikAbstractAction) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with TokenInfo

use of org.stepik.api.objects.auth.TokenInfo in project intellij-plugins by StepicOrg.

the class StepikAuthManager method setState.

private static void setState(@NotNull StepikAuthState value) {
    StepikAuthState oldState = state;
    state = value;
    if (state == NOT_AUTH) {
        stepikApiClient.setTokenInfo(null);
        user = null;
        long userId = getLastUser();
        setTokenInfo(userId, new TokenInfo());
        setLastUser(0);
    }
    if (oldState != state) {
        if (state == AUTH) {
            Metrics.authenticate(SUCCESSFUL);
        }
        executor.execute(() -> listeners.forEach(listener -> listener.stateChanged(oldState, state)));
    }
}
Also used : AUTH(org.stepik.core.stepik.StepikAuthState.AUTH) Application(com.intellij.openapi.application.Application) CredentialAttributes(com.intellij.credentialStore.CredentialAttributes) PLUGIN_ID(org.stepik.core.utils.PluginUtils.PLUGIN_ID) ModalityState(com.intellij.openapi.application.ModalityState) StepikClientException(org.stepik.api.exceptions.StepikClientException) CompletableFuture(java.util.concurrent.CompletableFuture) ProductGroup(org.stepik.core.utils.ProductGroup) PluginUtils.getCurrentProduct(org.stepik.core.utils.PluginUtils.getCurrentProduct) User(org.stepik.api.objects.users.User) ArrayList(java.util.ArrayList) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Credentials(com.intellij.credentialStore.Credentials) Metrics(org.stepik.core.metrics.Metrics) Map(java.util.Map) Logger(com.intellij.openapi.diagnostic.Logger) PluginUtils.getVersion(org.stepik.core.utils.PluginUtils.getVersion) SUCCESSFUL(org.stepik.core.metrics.MetricsStatus.SUCCESSFUL) HttpConfigurable(com.intellij.util.net.HttpConfigurable) ExecutorService(java.util.concurrent.ExecutorService) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) SHOW_DIALOG(org.stepik.core.stepik.StepikAuthState.SHOW_DIALOG) PluginUtils.getCurrentProductVersion(org.stepik.core.utils.PluginUtils.getCurrentProductVersion) NOT_AUTH(org.stepik.core.stepik.StepikAuthState.NOT_AUTH) Executors(java.util.concurrent.Executors) UNKNOWN(org.stepik.core.stepik.StepikAuthState.UNKNOWN) InvocationTargetException(java.lang.reflect.InvocationTargetException) PluginUtils(org.stepik.core.utils.PluginUtils) AuthDialog(org.stepik.plugin.auth.ui.AuthDialog) HttpTransportClient(org.stepik.api.client.HttpTransportClient) TokenInfo(org.stepik.api.objects.auth.TokenInfo) List(java.util.List) PasswordSafe(com.intellij.ide.passwordSafe.PasswordSafe) ApplicationManager(com.intellij.openapi.application.ApplicationManager) StepikProjectManager(org.stepik.core.StepikProjectManager) StepikApiClient(org.stepik.api.client.StepikApiClient) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) TokenInfo(org.stepik.api.objects.auth.TokenInfo)

Example 8 with TokenInfo

use of org.stepik.api.objects.auth.TokenInfo in project intellij-plugins by StepicOrg.

the class StepikAuthManager method getTokenInfo.

@NotNull
private static TokenInfo getTokenInfo(long userId, StepikApiClient client) {
    if (userId == 0) {
        return new TokenInfo();
    }
    String serviceName = StepikProjectManager.class.getName();
    CredentialAttributes attributes = new CredentialAttributes(serviceName, String.valueOf(userId), StepikProjectManager.class, false);
    Credentials credentials = PasswordSafe.getInstance().get(attributes);
    TokenInfo authInfo = null;
    if (credentials != null) {
        String password = credentials.getPasswordAsString();
        authInfo = client.getJsonConverter().fromJson(password, TokenInfo.class);
    }
    if (authInfo == null) {
        return new TokenInfo();
    }
    return authInfo;
}
Also used : CredentialAttributes(com.intellij.credentialStore.CredentialAttributes) TokenInfo(org.stepik.api.objects.auth.TokenInfo) Credentials(com.intellij.credentialStore.Credentials) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)8 TokenInfo (org.stepik.api.objects.auth.TokenInfo)8 StepikApiClient (org.stepik.api.client.StepikApiClient)4 StepikClientException (org.stepik.api.exceptions.StepikClientException)4 CredentialAttributes (com.intellij.credentialStore.CredentialAttributes)2 Credentials (com.intellij.credentialStore.Credentials)2 HttpConfigurable (com.intellij.util.net.HttpConfigurable)2 HashMap (java.util.HashMap)2 ClientResponse (org.stepik.api.client.ClientResponse)2 HttpTransportClient (org.stepik.api.client.HttpTransportClient)2 TransportClient (org.stepik.api.client.TransportClient)2 StepikUnauthorizedException (org.stepik.api.exceptions.StepikUnauthorizedException)2 User (org.stepik.api.objects.users.User)2 PasswordSafe (com.intellij.ide.passwordSafe.PasswordSafe)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 Application (com.intellij.openapi.application.Application)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ModalityState (com.intellij.openapi.application.ModalityState)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1