1 |
40232
|
stefania.m
|
package eu.dnetlib.repo.manager.client;
|
2 |
|
|
|
3 |
40267
|
stefania.m
|
import com.google.gwt.core.client.GWT;
|
4 |
40232
|
stefania.m
|
import com.google.gwt.dom.client.Document;
|
5 |
|
|
import com.google.gwt.dom.client.Style;
|
6 |
40267
|
stefania.m
|
import com.google.gwt.event.dom.client.ClickEvent;
|
7 |
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
8 |
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
9 |
42068
|
stefania.m
|
import com.google.gwt.user.client.ui.HTML;
|
10 |
|
|
import com.google.gwt.user.client.ui.PasswordTextBox;
|
11 |
|
|
import com.google.gwt.user.client.ui.RootPanel;
|
12 |
40267
|
stefania.m
|
import eu.dnetlib.domain.functionality.UserProfile;
|
13 |
42068
|
stefania.m
|
import eu.dnetlib.gwt.client.MyFormGroup;
|
14 |
41093
|
stefania.m
|
import eu.dnetlib.repo.manager.client.services.UserService;
|
15 |
|
|
import eu.dnetlib.repo.manager.client.services.UserServiceAsync;
|
16 |
42068
|
stefania.m
|
import eu.dnetlib.repo.manager.client.widgets.TextBox;
|
17 |
40267
|
stefania.m
|
import eu.dnetlib.repo.manager.shared.UserAccessException;
|
18 |
42068
|
stefania.m
|
import org.gwtbootstrap3.client.ui.Alert;
|
19 |
|
|
import org.gwtbootstrap3.client.ui.Anchor;
|
20 |
|
|
import org.gwtbootstrap3.client.ui.Form;
|
21 |
|
|
import org.gwtbootstrap3.client.ui.SubmitButton;
|
22 |
|
|
import org.gwtbootstrap3.client.ui.constants.AlertType;
|
23 |
|
|
import org.gwtbootstrap3.client.ui.constants.ButtonType;
|
24 |
|
|
import org.gwtbootstrap3.client.ui.html.Paragraph;
|
25 |
40232
|
stefania.m
|
|
26 |
|
|
/**
|
27 |
|
|
* Created by stefania on 12/2/15.
|
28 |
|
|
*/
|
29 |
|
|
public class RegisterPage {
|
30 |
|
|
|
31 |
|
|
private static RegisterPage instance = null;
|
32 |
|
|
|
33 |
42068
|
stefania.m
|
private Form userRegistrationForm = new Form();
|
34 |
40267
|
stefania.m
|
|
35 |
42068
|
stefania.m
|
private Alert successLabel = new Alert();
|
36 |
|
|
private Alert errorLabel = new Alert();
|
37 |
|
|
|
38 |
|
|
private TextBox username = new TextBox();
|
39 |
|
|
private TextBox firstName = new TextBox();
|
40 |
|
|
private TextBox lastName = new TextBox();
|
41 |
|
|
private TextBox email = new TextBox();
|
42 |
|
|
private TextBox institution = new TextBox();
|
43 |
|
|
private PasswordTextBox password = new PasswordTextBox();
|
44 |
|
|
private PasswordTextBox confirmPassword = new PasswordTextBox();
|
45 |
|
|
|
46 |
|
|
private SubmitButton register = new SubmitButton();
|
47 |
|
|
|
48 |
|
|
private Paragraph paragraph = new Paragraph();
|
49 |
|
|
private Anchor login = new Anchor();
|
50 |
|
|
|
51 |
40267
|
stefania.m
|
private UserServiceAsync userService = GWT.create(UserService.class);
|
52 |
|
|
|
53 |
40232
|
stefania.m
|
private RegisterPage() {
|
54 |
40267
|
stefania.m
|
|
55 |
42068
|
stefania.m
|
successLabel.setType(AlertType.SUCCESS);
|
56 |
|
|
successLabel.setVisible(false);
|
57 |
|
|
successLabel.setDismissable(false);
|
58 |
|
|
userRegistrationForm.add(successLabel);
|
59 |
40267
|
stefania.m
|
|
60 |
42068
|
stefania.m
|
errorLabel.setType(AlertType.DANGER);
|
61 |
|
|
errorLabel.setVisible(false);
|
62 |
|
|
errorLabel.setDismissable(false);
|
63 |
|
|
userRegistrationForm.add(errorLabel);
|
64 |
|
|
|
65 |
|
|
userRegistrationForm.addStyleName("m-t");
|
66 |
|
|
|
67 |
|
|
username.setPlaceholder("Username (*)");
|
68 |
|
|
username.addStyleName("form-control");
|
69 |
|
|
userRegistrationForm.add(new MyFormGroup(false, null, username));
|
70 |
|
|
|
71 |
|
|
firstName.setPlaceholder("First Name (*)");
|
72 |
|
|
firstName.addStyleName("form-control");
|
73 |
|
|
userRegistrationForm.add(new MyFormGroup(false, null, firstName));
|
74 |
|
|
|
75 |
|
|
lastName.setPlaceholder("Last Name (*)");
|
76 |
|
|
lastName.addStyleName("form-control");
|
77 |
|
|
userRegistrationForm.add(new MyFormGroup(false, null, lastName));
|
78 |
|
|
|
79 |
|
|
email.setPlaceholder("Email (*)");
|
80 |
|
|
email.addStyleName("form-control");
|
81 |
|
|
userRegistrationForm.add(new MyFormGroup(false, null, email));
|
82 |
|
|
|
83 |
|
|
institution.setPlaceholder("Institution");
|
84 |
|
|
institution.addStyleName("form-control");
|
85 |
|
|
userRegistrationForm.add(new MyFormGroup(false, null, institution));
|
86 |
|
|
|
87 |
|
|
password.getElement().setPropertyString("placeholder", "Password (*)");
|
88 |
|
|
password.addStyleName("form-control");
|
89 |
|
|
userRegistrationForm.add(new MyFormGroup(false, null, password));
|
90 |
|
|
|
91 |
|
|
confirmPassword.getElement().setPropertyString("placeholder", "Re-enter password (*)");
|
92 |
|
|
confirmPassword.addStyleName("form-control");
|
93 |
|
|
userRegistrationForm.add(new MyFormGroup(false, null, confirmPassword));
|
94 |
|
|
|
95 |
|
|
register.setType(ButtonType.PRIMARY);
|
96 |
|
|
register.setText("Register");
|
97 |
|
|
register.addStyleName("block full-width m-b");
|
98 |
|
|
register.addClickHandler(new ClickHandler() {
|
99 |
|
|
|
100 |
40267
|
stefania.m
|
@Override
|
101 |
42068
|
stefania.m
|
public void onClick(ClickEvent event) {
|
102 |
40267
|
stefania.m
|
|
103 |
42068
|
stefania.m
|
errorLabel.setVisible(false);
|
104 |
|
|
successLabel.setVisible(false);
|
105 |
40267
|
stefania.m
|
|
106 |
42068
|
stefania.m
|
if(username.getValue().trim().isEmpty() || firstName.getValue().trim().isEmpty()
|
107 |
|
|
|| lastName.getValue().trim().isEmpty() || email.getValue().trim().isEmpty()
|
108 |
|
|
|| password.getValue().trim().isEmpty() || confirmPassword.getValue().trim().isEmpty()) {
|
109 |
40267
|
stefania.m
|
|
110 |
42068
|
stefania.m
|
errorLabel.setText("All asterisk (*) fields are required");
|
111 |
|
|
errorLabel.setVisible(true);
|
112 |
40267
|
stefania.m
|
|
113 |
42068
|
stefania.m
|
} else if(!password.getValue().equals(confirmPassword.getValue())) {
|
114 |
40267
|
stefania.m
|
|
115 |
42068
|
stefania.m
|
errorLabel.setText("Password fields do not match");
|
116 |
|
|
errorLabel.setVisible(true);
|
117 |
40267
|
stefania.m
|
|
118 |
42068
|
stefania.m
|
} else {
|
119 |
40267
|
stefania.m
|
|
120 |
42068
|
stefania.m
|
UserProfile userProfile = new UserProfile();
|
121 |
|
|
userProfile.setFirstname(firstName.getValue());
|
122 |
|
|
userProfile.setLastname(lastName.getValue());
|
123 |
|
|
userProfile.setUsername(username.getValue());
|
124 |
|
|
userProfile.setEmail(email.getValue());
|
125 |
|
|
userProfile.setPassword(password.getValue());
|
126 |
|
|
if(institution.getValue()!=null && !institution.getValue().isEmpty())
|
127 |
|
|
userProfile.setInstitution(institution.getValue());
|
128 |
40267
|
stefania.m
|
|
129 |
42068
|
stefania.m
|
final HTML loadingWheel = new HTML("<div class=\"loader-small\"></div><div class=\"whiteFilm\"></div>");
|
130 |
|
|
userRegistrationForm.addStyleName("loading");
|
131 |
|
|
userRegistrationForm.add(loadingWheel);
|
132 |
40267
|
stefania.m
|
|
133 |
42068
|
stefania.m
|
userService.register(userProfile, new AsyncCallback<Void>() {
|
134 |
|
|
|
135 |
|
|
@Override
|
136 |
|
|
public void onFailure(Throwable throwable) {
|
137 |
|
|
|
138 |
|
|
userRegistrationForm.removeStyleName("loading");
|
139 |
|
|
userRegistrationForm.remove(loadingWheel);
|
140 |
|
|
|
141 |
|
|
if(throwable instanceof UserAccessException) {
|
142 |
|
|
UserAccessException uae = (UserAccessException) throwable;
|
143 |
|
|
errorLabel.setText(uae.getMessage());
|
144 |
|
|
errorLabel.setVisible(true);
|
145 |
|
|
} else {
|
146 |
|
|
errorLabel.setText("Registration failed - Something went wrong, please try again.");
|
147 |
|
|
errorLabel.setVisible(true);
|
148 |
40267
|
stefania.m
|
}
|
149 |
42068
|
stefania.m
|
}
|
150 |
40267
|
stefania.m
|
|
151 |
42068
|
stefania.m
|
@Override
|
152 |
|
|
public void onSuccess(Void aVoid) {
|
153 |
|
|
|
154 |
|
|
userRegistrationForm.removeStyleName("loading");
|
155 |
|
|
userRegistrationForm.remove(loadingWheel);
|
156 |
42070
|
stefania.m
|
|
157 |
42068
|
stefania.m
|
successLabel.setText("An activation e-mail has been sent to the e-mail " +
|
158 |
|
|
"address you specified. Please follow the link included in that e-mail to activate your account.");
|
159 |
|
|
successLabel.setVisible(true);
|
160 |
|
|
}
|
161 |
|
|
});
|
162 |
40267
|
stefania.m
|
}
|
163 |
|
|
}
|
164 |
|
|
});
|
165 |
42068
|
stefania.m
|
userRegistrationForm.add(register);
|
166 |
|
|
|
167 |
|
|
paragraph.setHTML("<small>Do not have an account?</small>");
|
168 |
|
|
paragraph.addStyleName("text-muted text-center");
|
169 |
|
|
userRegistrationForm.add(paragraph);
|
170 |
|
|
|
171 |
|
|
login.setHref("#login");
|
172 |
|
|
login.setText("Already have an account?");
|
173 |
|
|
login.addStyleName("btn btn-sm btn-white btn-block");
|
174 |
|
|
userRegistrationForm.add(login);
|
175 |
|
|
|
176 |
|
|
RootPanel.get("registerForm").add(userRegistrationForm);
|
177 |
40232
|
stefania.m
|
}
|
178 |
|
|
|
179 |
|
|
public static final RegisterPage getInstance() {
|
180 |
|
|
|
181 |
|
|
if(instance==null)
|
182 |
|
|
instance = new RegisterPage();
|
183 |
|
|
|
184 |
|
|
return instance;
|
185 |
|
|
}
|
186 |
|
|
|
187 |
|
|
public void showRegisterPage() {
|
188 |
|
|
|
189 |
|
|
Document.get().getElementById("landingPage").getStyle().setDisplay(Style.Display.NONE);
|
190 |
|
|
Document.get().getElementById("login").getStyle().setDisplay(Style.Display.NONE);
|
191 |
|
|
Document.get().getElementById("wrapper").getStyle().setDisplay(Style.Display.NONE);
|
192 |
|
|
Document.get().getElementById("register").getStyle().setDisplay(Style.Display.BLOCK);
|
193 |
|
|
|
194 |
48932
|
antonis.le
|
// Document.get().getBody().removeClassName("landing-page");
|
195 |
|
|
// Document.get().getBody().addClassName("gray-bg");
|
196 |
40232
|
stefania.m
|
}
|
197 |
|
|
}
|