use of com.haulmont.cuba.web.App in project cuba by cuba-platform.
the class WebTimeField method updateWidth.
protected void updateWidth() {
if (!App.isBound()) {
return;
}
App app = App.getInstance();
ThemeConstants theme = app.getThemeConstants();
int digitWidth = theme.getInt("cuba.web.WebTimeField.digitWidth");
int digitPadding = theme.getInt("cuba.web.WebTimeField.digitPadding");
int separatorWidth = theme.getInt("cuba.web.WebTimeField.separatorWidth");
int partsCount = isAmPmUsed() ? 1 : 0;
int newWidth = isAmPmUsed() ? digitWidth + digitPadding : digitPadding;
if (showSeconds) {
newWidth = newWidth + digitWidth;
partsCount += 1;
}
switch(resolution) {
case HOUR:
partsCount += 1;
newWidth = digitWidth + newWidth;
break;
case MIN:
case SEC:
partsCount += 2;
newWidth = digitWidth * 2 + newWidth;
break;
}
newWidth += (partsCount - 1) * separatorWidth;
component.setWidth(newWidth + "px");
}
use of com.haulmont.cuba.web.App in project cuba by cuba-platform.
the class ChangeSubstUserAction method actionPerform.
@Override
public void actionPerform(com.haulmont.cuba.gui.components.Component component) {
AppUI ui = AppUI.getCurrent();
WebScreens screens = (WebScreens) ui.getScreens();
screens.checkModificationsAndCloseAll().then(() -> {
App app = ui.getApp();
try {
app.getConnection().substituteUser(user);
doAfterChangeUser();
} catch (javax.persistence.NoResultException e) {
Messages messages = AppBeans.get(Messages.NAME);
app.getWindowManager().showNotification(messages.formatMainMessage("substitutionNotPerformed", user.getName()), Frame.NotificationType.WARNING);
doRevert();
}
}).otherwise(this::doRevert);
}
use of com.haulmont.cuba.web.App in project cuba by cuba-platform.
the class WebUserSessionSource method checkCurrentUserSession.
@Override
public boolean checkCurrentUserSession() {
if (App.isBound()) {
App app = App.getInstance();
Connection connection = app.getConnection();
return connection.isConnected() && connection.getSession() != null;
} else {
SecurityContext securityContext = AppContext.getSecurityContext();
if (securityContext == null) {
return false;
}
if (securityContext.getSession() != null) {
return true;
} else if (AppContext.isStarted()) {
try {
getUserSessionFromMiddleware(securityContext.getSessionId());
return true;
} catch (Exception e) {
return false;
}
} else
return false;
}
}
use of com.haulmont.cuba.web.App in project cuba by cuba-platform.
the class ChangePasswordAfterLoginListener method onApplicationEvent.
@Override
public void onApplicationEvent(AppLoggedInEvent event) {
App app = event.getApp();
Connection connection = app.getConnection();
if (connection.isAuthenticated() && !isLoggedInWithExternalAuth(connection.getSessionNN())) {
User user = connection.getSessionNN().getUser();
// Change password on logon
if (Boolean.TRUE.equals(user.getChangePasswordAtNextLogon())) {
WindowManager wm = app.getWindowManager();
for (Window window : wm.getOpenWindows()) {
window.setEnabled(false);
}
WindowInfo changePasswordDialog = windowConfig.getWindowInfo("sec$User.changePassword");
Window changePasswordWindow = wm.openWindow(changePasswordDialog, WindowManager.OpenType.DIALOG.closeable(false), ParamsMap.of("cancelEnabled", Boolean.FALSE));
changePasswordWindow.addCloseListener(actionId -> {
for (Window window : wm.getOpenWindows()) {
window.setEnabled(true);
}
});
}
}
}
use of com.haulmont.cuba.web.App in project cuba by cuba-platform.
the class LegacyLoginEventsForwarder method appStarted.
@Order(Events.HIGHEST_PLATFORM_PRECEDENCE + 10)
@EventListener
protected void appStarted(AppStartedEvent event) {
App app = event.getApp();
Locale locale = app.getLocale();
Principal principal = getSessionPrincipal();
// Login on start only on first request from user
if (isTryLoginOnStart() && principal != null && webAuthConfig.getExternalAuthentication()) {
String userName = principal.getName();
log.debug("Trying to login after external authentication as {}", userName);
try {
app.getConnection().loginAfterExternalAuthentication(userName, locale);
} catch (LoginException e) {
log.trace("Unable to login on start", e);
} finally {
// Close attempt login on start
setTryLoginOnStart(false);
}
}
}
Aggregations