mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-17 01:31:01 +00:00
refactoring of LoginEntryPoint UI content to be based on UI-Binder
This commit is contained in:
1 parent
eb14e655e2
commit
43ae039bcb
6 files changed
+148
-122
No files matched your search
+3
-103
@@ -1,131 +1,31 @@
|
||||
package com.sap.sse.security.ui.login;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.rpc.ServiceDefTarget;
|
||||
import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.DockLayoutPanel;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.FormPanel;
|
||||
import com.google.gwt.user.client.ui.FormPanel.SubmitEvent;
|
||||
import com.google.gwt.user.client.ui.FormPanel.SubmitHandler;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.PasswordTextBox;
|
||||
import com.google.gwt.user.client.ui.RootLayoutPanel;
|
||||
import com.google.gwt.user.client.ui.SubmitButton;
|
||||
import com.google.gwt.user.client.ui.TextBox;
|
||||
import com.sap.sse.gwt.client.AbstractEntryPoint;
|
||||
import com.sap.sse.gwt.client.EntryPointHelper;
|
||||
import com.sap.sse.gwt.client.async.MarkedAsyncCallback;
|
||||
import com.sap.sse.security.shared.UserManagementException;
|
||||
import com.sap.sse.security.ui.client.EntryPointLinkFactory;
|
||||
import com.sap.sse.security.ui.client.RemoteServiceMappingConstants;
|
||||
import com.sap.sse.security.ui.client.Resources;
|
||||
import com.sap.sse.security.ui.client.StringMessages;
|
||||
import com.sap.sse.security.ui.client.UserService;
|
||||
import com.sap.sse.security.ui.oauth.client.component.OAuthLoginPanel;
|
||||
import com.sap.sse.security.ui.shared.SuccessInfo;
|
||||
import com.sap.sse.security.ui.shared.UserManagementService;
|
||||
import com.sap.sse.security.ui.shared.UserManagementServiceAsync;
|
||||
|
||||
public class LoginEntryPoint extends AbstractEntryPoint {
|
||||
private final StringMessages stringMessages = GWT.create(StringMessages.class);
|
||||
private static final Resources resource = GWT.create(Resources.class);
|
||||
private UserManagementServiceAsync userManagementService;
|
||||
private UserService userService;
|
||||
|
||||
@Override
|
||||
public void doOnModuleLoad() {
|
||||
userManagementService = GWT.create(UserManagementService.class);
|
||||
EntryPointHelper.registerASyncService((ServiceDefTarget) userManagementService,
|
||||
RemoteServiceMappingConstants.userManagementServiceRemotePath);
|
||||
EntryPointHelper.registerASyncService((ServiceDefTarget) userManagementService, RemoteServiceMappingConstants.userManagementServiceRemotePath);
|
||||
userService = new UserService(userManagementService);
|
||||
|
||||
RootLayoutPanel rootPanel = RootLayoutPanel.get();
|
||||
DockLayoutPanel dockPanel = new DockLayoutPanel(Unit.PX);
|
||||
rootPanel.add(dockPanel);
|
||||
|
||||
FlowPanel fp = new FlowPanel();
|
||||
Label nameLabel = new Label(stringMessages.username());
|
||||
fp.add(nameLabel);
|
||||
final TextBox nameText = new TextBox();
|
||||
nameText.ensureDebugId("username");
|
||||
fp.add(nameText);
|
||||
final Button passwordReset = new Button(stringMessages.resetPassword());
|
||||
passwordReset.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
userManagementService.resetPassword(nameText.getText(), new MarkedAsyncCallback<Void>(new AsyncCallback<Void>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
if (caught instanceof UserManagementException) {
|
||||
if (UserManagementException.CANNOT_RESET_PASSWORD_WITHOUT_VALIDATED_EMAIL.equals(caught.getMessage())) {
|
||||
Window.alert(stringMessages.cannotResetPasswordWithoutValidatedEmail(nameText.getText()));
|
||||
} else {
|
||||
Window.alert(stringMessages.errorDuringPasswordReset(caught.getMessage()));
|
||||
}
|
||||
} else {
|
||||
Window.alert(stringMessages.errorDuringPasswordReset(caught.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
Window.alert(stringMessages.newPasswordSent(nameText.getText()));
|
||||
}
|
||||
}));
|
||||
}
|
||||
});
|
||||
fp.add(passwordReset);
|
||||
Label pwLabel = new Label(stringMessages.password());
|
||||
pwLabel.ensureDebugId("password");
|
||||
fp.add(pwLabel);
|
||||
final PasswordTextBox pwText = new PasswordTextBox();
|
||||
fp.add(pwText);
|
||||
final SubmitButton submit = new SubmitButton(stringMessages.signIn());
|
||||
submit.ensureDebugId("login");
|
||||
fp.add(submit);
|
||||
fp.add(new Anchor(new SafeHtmlBuilder().appendEscaped(stringMessages.signUp()).toSafeHtml(),
|
||||
EntryPointLinkFactory.createRegistrationLink(Collections.<String, String> emptyMap())));
|
||||
FormPanel formPanel = new FormPanel();
|
||||
formPanel.addSubmitHandler(new SubmitHandler() {
|
||||
@Override
|
||||
public void onSubmit(SubmitEvent event) {
|
||||
userService.login(nameText.getText(), pwText.getText(), new AsyncCallback<SuccessInfo>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
GWT.log(caught.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(SuccessInfo result) {
|
||||
if (result.isSuccessful()) {
|
||||
if (!result.getRedirectURL().equals("")) {
|
||||
Window.Location.replace(result.getRedirectURL());
|
||||
} else {
|
||||
Window.alert(stringMessages.loggedIn(result.getUserDTO().getName()));
|
||||
}
|
||||
} else {
|
||||
if (SuccessInfo.FAILED_TO_LOGIN.equals(result.getMessage())) {
|
||||
Window.alert(stringMessages.failedToSignIn());
|
||||
} else {
|
||||
Window.alert(result.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
fp.add(new OAuthLoginPanel(userManagementService, resource.css()));
|
||||
formPanel.add(fp);
|
||||
dockPanel.add(formPanel);
|
||||
nameText.setFocus(true);
|
||||
dockPanel.add(new LoginView(userManagementService, userService));
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package com.sap.sse.security.ui.login;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.uibinder.client.UiHandler;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||
import com.google.gwt.user.client.ui.PasswordTextBox;
|
||||
import com.google.gwt.user.client.ui.TextBox;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.sap.sse.gwt.client.async.MarkedAsyncCallback;
|
||||
import com.sap.sse.security.shared.UserManagementException;
|
||||
import com.sap.sse.security.ui.client.EntryPointLinkFactory;
|
||||
import com.sap.sse.security.ui.client.Resources;
|
||||
import com.sap.sse.security.ui.client.StringMessages;
|
||||
import com.sap.sse.security.ui.client.UserService;
|
||||
import com.sap.sse.security.ui.oauth.client.component.OAuthLoginPanel;
|
||||
import com.sap.sse.security.ui.shared.SuccessInfo;
|
||||
import com.sap.sse.security.ui.shared.UserManagementServiceAsync;
|
||||
|
||||
public class LoginView extends Composite {
|
||||
private static LoginViewUiBinder uiBinder = GWT.create(LoginViewUiBinder.class);
|
||||
|
||||
interface LoginViewUiBinder extends UiBinder<Widget, LoginView> {
|
||||
}
|
||||
|
||||
private final UserManagementServiceAsync userManagementService;
|
||||
private final UserService userService;
|
||||
|
||||
@UiField TextBox nameText;
|
||||
@UiField Button passwordReset;
|
||||
@UiField PasswordTextBox pwText;
|
||||
@UiField Button submit;
|
||||
@UiField Anchor signUpAnchor;
|
||||
@UiField HTMLPanel oAuthPanel;
|
||||
|
||||
public LoginView(UserManagementServiceAsync userManagementService, UserService userService) {
|
||||
this.userManagementService = userManagementService;
|
||||
this.userService = userService;
|
||||
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
|
||||
String registrationLink = EntryPointLinkFactory.createRegistrationLink(Collections.<String, String> emptyMap());
|
||||
signUpAnchor.setHref(registrationLink);
|
||||
|
||||
oAuthPanel.add(new OAuthLoginPanel(userManagementService, Resources.INSTANCE.css()));
|
||||
|
||||
nameText.setFocus(true);
|
||||
}
|
||||
|
||||
@UiHandler("submit")
|
||||
void submitClicked(ClickEvent e) {
|
||||
userService.login(nameText.getText(), pwText.getText(), new AsyncCallback<SuccessInfo>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
GWT.log(caught.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(SuccessInfo result) {
|
||||
if (result.isSuccessful()) {
|
||||
if (!result.getRedirectURL().equals("")) {
|
||||
Window.Location.replace(result.getRedirectURL());
|
||||
} else {
|
||||
Window.alert(StringMessages.INSTANCE.loggedIn(result.getUserDTO().getName()));
|
||||
}
|
||||
} else {
|
||||
if (SuccessInfo.FAILED_TO_LOGIN.equals(result.getMessage())) {
|
||||
Window.alert(StringMessages.INSTANCE.failedToSignIn());
|
||||
} else {
|
||||
Window.alert(result.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@UiHandler("passwordReset")
|
||||
void passwordResetClicked(ClickEvent e) {
|
||||
userManagementService.resetPassword(nameText.getText(), new MarkedAsyncCallback<Void>(new AsyncCallback<Void>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
if (caught instanceof UserManagementException) {
|
||||
if (UserManagementException.CANNOT_RESET_PASSWORD_WITHOUT_VALIDATED_EMAIL.equals(caught.getMessage())) {
|
||||
Window.alert(StringMessages.INSTANCE.cannotResetPasswordWithoutValidatedEmail(nameText.getText()));
|
||||
} else {
|
||||
Window.alert(StringMessages.INSTANCE.errorDuringPasswordReset(caught.getMessage()));
|
||||
}
|
||||
} else {
|
||||
Window.alert(StringMessages.INSTANCE.errorDuringPasswordReset(caught.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
Window.alert(StringMessages.INSTANCE.newPasswordSent(nameText.getText()));
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
||||
xmlns:g="urn:import:com.google.gwt.user.client.ui">
|
||||
<ui:with field="i18n" type="com.sap.sse.security.ui.client.StringMessages"/>
|
||||
<ui:with field="res" type="com.sap.sse.security.ui.login.LoginViewResources" />
|
||||
<g:HTMLPanel ui:field="fp">
|
||||
<div><ui:text from='{i18n.username}'/></div>
|
||||
<div><g:TextBox ui:field="nameText" /></div>
|
||||
<div><ui:text from='{i18n.password}'/></div>
|
||||
<div><g:PasswordTextBox ui:field="pwText" /></div>
|
||||
<g:Button ui:field="submit" text="{i18n.signIn}" />
|
||||
<g:Button ui:field="passwordReset" text="{i18n.resetPassword}" />
|
||||
<g:Anchor ui:field="signUpAnchor" text="{i18n.signUp}" />
|
||||
<g:HTMLPanel ui:field="oAuthPanel" />
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
.a {
|
||||
}
|
||||
.b {
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.sap.sse.security.ui.login;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.resources.client.ClientBundle;
|
||||
import com.google.gwt.resources.client.CssResource;
|
||||
|
||||
public interface LoginViewResources extends ClientBundle {
|
||||
public static final LoginViewResources INSTANCE = GWT.create(LoginViewResources.class);
|
||||
|
||||
@Source("com/sap/sse/security/ui/login/LoginViewResources.css")
|
||||
LocalCss css();
|
||||
|
||||
public interface LocalCss extends CssResource {
|
||||
String a();
|
||||
String b();
|
||||
}
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
package com.sap.sse.security.ui.loginpanel;
|
||||
|
||||
import com.google.gwt.http.client.URL;
|
||||
|
||||
public class URLEncoder {
|
||||
|
||||
private URLEncoder() { }
|
||||
|
||||
private final static char[] charsToReplace = { '\'', '(', ')', '"', '[', ']', '{', '}', '<', '>', '|' };
|
||||
|
||||
public static String encode(String url) {
|
||||
String nearlyEncoded = URL.encode(url);
|
||||
for (char c : charsToReplace) {
|
||||
nearlyEncoded = nearlyEncoded.replaceAll("\\" + Character.toString(c), "%" + Integer.toHexString(c));
|
||||
}
|
||||
return nearlyEncoded;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user