Search in sources :

Example 1 with HttpException

use of se.light.assembly64.model.HttpException in project assembly64fx by freabemania.

the class UserService method storeSettings.

public void storeSettings() throws HttpException {
    Response response = null;
    try {
        response = getClient().target(getBackendServer()).path("/leet/user3/settings").request().header("email", getSessionInfo().getEmail()).header("token", getSessionInfo().getToken()).post(Entity.json(settings));
    } finally {
        response.close();
    }
    invalidateUserDb();
    if (response.getStatus() != 200) {
        throw new HttpException(response.getStatus());
    }
}
Also used : Response(javax.ws.rs.core.Response) HttpException(se.light.assembly64.model.HttpException)

Example 2 with HttpException

use of se.light.assembly64.model.HttpException in project assembly64fx by freabemania.

the class ForgottenPasswordController method register.

@FXML
protected void register() {
    if (globalRepoService.contains(CONFMAILSENT)) {
        getStage().close();
        return;
    }
    String mail = email.getText();
    if (!mail.contains("@")) {
        message.setText("Enter valid mail");
        return;
    }
    try {
        Analytics.sendEvent("application", "forgotten_pass");
        userService.forgotPassword(mail);
        globalRepoService.put(CONFMAILSENT, "true");
        message.setText("Check your mailbox for confirmation mail");
        sendPass.setImage(new Image(getClass().getResourceAsStream("button-close.png")));
    } catch (HttpException e) {
        message.setText("Error" + e.getErrorCode() + ", please try again");
    }
}
Also used : HttpException(se.light.assembly64.model.HttpException) Image(javafx.scene.image.Image) FXML(javafx.fxml.FXML)

Example 3 with HttpException

use of se.light.assembly64.model.HttpException in project assembly64fx by freabemania.

the class RegistrationController method register.

@FXML
protected void register() {
    if (globalRepoService.contains(CONFMAILSENT)) {
        getStage().close();
        return;
    }
    String mail = email.getText();
    String pass1 = password.getText();
    String pass2 = passwordConfirm.getText();
    if (!mail.contains("@")) {
        message.setText("Enter valid mail");
        return;
    }
    if (pass1.length() < 6) {
        message.setText("Password needs to be atleast 6 chars");
        return;
    }
    if (!pass1.equals(pass2)) {
        message.setText("Passwords are not matching");
        return;
    }
    try {
        userService.register(mail, pass1);
        globalRepoService.put(CONFMAILSENT, "true");
        message.setText("Check mailbox for confirmation");
        register.setImage(new Image(getClass().getResourceAsStream("button-close.png")));
        cancel.setVisible(false);
    } catch (HttpException e) {
        switch(e.getErrorCode()) {
            case 428:
                message.setText("Registration is closed, please try later");
                break;
            default:
                message.setText("Unable to register");
        }
    // action.setText("Close");
    }
}
Also used : HttpException(se.light.assembly64.model.HttpException) Image(javafx.scene.image.Image) FXML(javafx.fxml.FXML)

Example 4 with HttpException

use of se.light.assembly64.model.HttpException in project assembly64fx by freabemania.

the class SettingsController method storeSettings.

@FXML
protected void storeSettings(MouseEvent event) {
    try {
        Settings settings = userService.getSettings();
        if (settings.getNotificationOnNewContent() != notifyOnNewContent.isSelected() || !settings.getCountry().equals(countries.getSelectionModel().getSelectedItem()) || !settings.getName().equals(username.getText()) || !settings.getAnonymous().equals(anonymous.isSelected())) {
            settings.setNotificationOnNewContent(notifyOnNewContent.isSelected());
            settings.setCountry(countries.getSelectionModel().getSelectedItem());
            settings.setName(username.getText());
            settings.setAnonymous(anonymous.isSelected());
            userService.storeSettings();
            Analytics.sendEvent("application_click", "store_settings");
            LOGGER.info("Settings were stored");
        }
        localDb.setSidifyAsDefault(sidifyAsDefault.isSelected());
        if (userService.isPremium()) {
            int tmp = workers.getSelectionModel().getSelectedIndex();
            if (tmp != initialWorkers) {
                localDb.addLocalDBSetting("instances", String.valueOf(workers.getSelectionModel().getSelectedIndex()));
                Scheduler.reinitIfNotWorking();
            }
            localDb.addLocalDBSetting("vicepath", vicePath.getText());
            localDb.setRunScriptInsteadOfVice(executeAsCommand.isSelected());
            if (executeAsCommand.isSelected()) {
                localDb.setViceStyleFormatOnArgs(viceStyleFormatOnArgs.isSelected());
            } else {
                localDb.setViceStyleFormatOnArgs(false);
            }
        }
        localDb.addLocalDBSetting("maxage", String.valueOf(latestMaxAge.getSelectionModel().getSelectedItem()));
        if (latestMaxAge.getSelectionModel().getSelectedIndex() > currMaxAgeIndex) {
            for (WorkLocation location : userService.getExistingLocations()) {
                FileUtils.deleteQuietly(new File(location.asFile().getAbsolutePath() + "/.db/latest"));
            }
        }
        getStage().close();
    } catch (Exception e) {
        if (e instanceof HttpException) {
            GenericMessageDialogController.withErrorProps("Oops", "Unable to store. Invalid length of name").showAndWait();
        }
        LOGGER.error("Unable to store settings", e);
    }
}
Also used : WorkLocation(se.light.assembly64.model.WorkLocation) HttpException(se.light.assembly64.model.HttpException) File(java.io.File) Settings(se.light.assembly64.model.Settings) HttpException(se.light.assembly64.model.HttpException) FXML(javafx.fxml.FXML)

Example 5 with HttpException

use of se.light.assembly64.model.HttpException in project assembly64fx by freabemania.

the class UserService method loginToken.

public String loginToken(String email, String token) throws HttpException {
    Response response = getClient().target(getBackendServer()).path("/leet/user3/tokenlogin/" + email + "/" + encrypt(token)).request().get();
    if (response.getStatus() != 200) {
        response.close();
        throw new HttpException(response.getStatus());
    }
    userLite = response.readEntity(UserLite.class);
    return userLite.getToken();
}
Also used : Response(javax.ws.rs.core.Response) HttpException(se.light.assembly64.model.HttpException) UserLite(se.light.assembly64.model.UserLite)

Aggregations

HttpException (se.light.assembly64.model.HttpException)5 FXML (javafx.fxml.FXML)3 Image (javafx.scene.image.Image)2 Response (javax.ws.rs.core.Response)2 File (java.io.File)1 Settings (se.light.assembly64.model.Settings)1 UserLite (se.light.assembly64.model.UserLite)1 WorkLocation (se.light.assembly64.model.WorkLocation)1