1
|
package eu.dnetlib.client;
|
2
|
|
3
|
import com.google.gwt.core.client.EntryPoint;
|
4
|
import com.google.gwt.core.client.GWT;
|
5
|
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
6
|
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
7
|
import com.google.gwt.user.client.Cookies;
|
8
|
import com.google.gwt.user.client.History;
|
9
|
import com.google.gwt.user.client.Window;
|
10
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
11
|
import com.google.gwt.user.client.ui.RootPanel;
|
12
|
import eu.dnetlib.goldoa.domain.Role;
|
13
|
import eu.dnetlib.goldoa.domain.User;
|
14
|
import eu.dnetlib.goldoa.domain.UserRole;
|
15
|
import eu.dnetlib.shared.InitLoad;
|
16
|
|
17
|
import java.util.ArrayList;
|
18
|
import java.util.List;
|
19
|
|
20
|
|
21
|
public class GoldOAPortal implements EntryPoint {
|
22
|
|
23
|
public static User currentUser = null;
|
24
|
|
25
|
public static String publicCaptchaKey = "";
|
26
|
|
27
|
public static String currentToken = "home";
|
28
|
public static String previousToken = "home";
|
29
|
|
30
|
public static List<Role> userRoles = new ArrayList<>();
|
31
|
|
32
|
private DataServiceAsync dataService = GWT.create(DataService.class);
|
33
|
|
34
|
public void onModuleLoad() {
|
35
|
|
36
|
RootPanel.get("loginRegister").add(RegisterLoginElement.getInstance());
|
37
|
|
38
|
History.addValueChangeHandler(new ValueChangeHandler<String>() {
|
39
|
@Override
|
40
|
public void onValueChange(ValueChangeEvent<String> event) {
|
41
|
|
42
|
String historyToken = event.getValue();
|
43
|
|
44
|
if(historyToken!=null && !historyToken.equals("")) {
|
45
|
|
46
|
String finalHistoryToken = getFinalHistoryToken(historyToken);
|
47
|
|
48
|
History.newItem(finalHistoryToken);
|
49
|
NavigationManager.getInstance().navigate(finalHistoryToken);
|
50
|
|
51
|
} else {
|
52
|
|
53
|
//TODO kapou peftei se loop
|
54
|
History.newItem("home");
|
55
|
NavigationManager.getInstance().navigate("home");
|
56
|
}
|
57
|
}
|
58
|
});
|
59
|
|
60
|
String hash = Window.Location.getHash();
|
61
|
String email = Window.Location.getParameter("email");
|
62
|
String token = Window.Location.getParameter("token");
|
63
|
String encryptedEmail = Cookies.getCookie("currentUser");
|
64
|
String cookieEmail = null;
|
65
|
if(encryptedEmail!=null)
|
66
|
cookieEmail = Crypto.decrypt(encryptedEmail);
|
67
|
|
68
|
dataService.load(hash, email, token, cookieEmail, new AsyncCallback<InitLoad>() {
|
69
|
|
70
|
@Override
|
71
|
public void onFailure(Throwable throwable) {
|
72
|
//TODO system error
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public void onSuccess(InitLoad initLoad) {
|
77
|
|
78
|
GoldOAPortal.publicCaptchaKey = initLoad.getPublicCaptchaKey();
|
79
|
|
80
|
GoldOAPortal.currentUser = null;
|
81
|
Cookies.removeCookie("currentUser");
|
82
|
|
83
|
GoldOAPortal.userRoles = initLoad.getUserRoles();
|
84
|
|
85
|
if(initLoad.getPerson()!=null) {
|
86
|
|
87
|
//TODO if it was activate, remove parameters from url
|
88
|
|
89
|
GoldOAPortal.currentUser = initLoad.getPerson();
|
90
|
Cookies.setCookie("currentUser", Crypto.encrypt(initLoad.getPerson().getEmail()));
|
91
|
|
92
|
UserInfoElement userInfoElement = new UserInfoElement();
|
93
|
RootPanel.get("loginRegister").clear();
|
94
|
RootPanel.get("loginRegister").add(userInfoElement.asWidget());
|
95
|
|
96
|
NavigationManager.getInstance().update();
|
97
|
|
98
|
String finalHistoryToken = getFinalHistoryToken(initLoad.getGoTo());
|
99
|
History.newItem(finalHistoryToken);
|
100
|
NavigationManager.getInstance().navigate(finalHistoryToken);
|
101
|
|
102
|
} else {
|
103
|
|
104
|
if(initLoad.getErrorMessage()!=null) {
|
105
|
|
106
|
NavigationManager.getInstance().update();
|
107
|
|
108
|
String finalHistoryToken = getFinalHistoryToken(initLoad.getGoTo());
|
109
|
History.newItem(finalHistoryToken);
|
110
|
NavigationManager.getInstance().navigate(finalHistoryToken);
|
111
|
//TODO display error message
|
112
|
|
113
|
} else {
|
114
|
|
115
|
NavigationManager.getInstance().update();
|
116
|
|
117
|
String finalHistoryToken = getFinalHistoryToken(initLoad.getGoTo());
|
118
|
History.newItem(finalHistoryToken);
|
119
|
NavigationManager.getInstance().navigate(finalHistoryToken);
|
120
|
}
|
121
|
}
|
122
|
}
|
123
|
});
|
124
|
}
|
125
|
|
126
|
private String getFinalHistoryToken(String historyToken) {
|
127
|
|
128
|
if(GoldOAPortal.currentUser==null) {
|
129
|
if(!(historyToken.equals("home") || historyToken.equals("support") || historyToken.equals("eligibleProjects")
|
130
|
|| historyToken.equals("login") || historyToken.equals("register") || historyToken.equals("statistics")
|
131
|
|| historyToken.equals("forgotYourPassword"))) {
|
132
|
historyToken = "home";
|
133
|
}
|
134
|
} else {
|
135
|
|
136
|
boolean isModeratorOrAdmin = false;
|
137
|
boolean isLibrarian = false;
|
138
|
boolean isAdminOrAccountingOfficer = false;
|
139
|
|
140
|
for(UserRole personRole : GoldOAPortal.currentUser.getRoles()) {
|
141
|
if(personRole.getPk().getRole().getId().equals("moderator") && personRole.isApproved()) {
|
142
|
isModeratorOrAdmin = true;
|
143
|
}
|
144
|
if(personRole.getPk().getRole().getId().equals("administrator") && personRole.isApproved()) {
|
145
|
isModeratorOrAdmin = true;
|
146
|
isAdminOrAccountingOfficer = true;
|
147
|
}
|
148
|
if(personRole.getPk().getRole().getId().equals("accounting") && personRole.isApproved()) {
|
149
|
isAdminOrAccountingOfficer = true;
|
150
|
}
|
151
|
if(personRole.getPk().getRole().getId().equals("library_staff") && personRole.isApproved()) {
|
152
|
isLibrarian = true;
|
153
|
}
|
154
|
}
|
155
|
|
156
|
if(!Utils.currentUserHasRoleApproved("administrator") && historyToken.equals("monitorHelpTexts"))
|
157
|
historyToken = "home";
|
158
|
|
159
|
if((!isModeratorOrAdmin && historyToken.equals("monitorFundingRequests"))
|
160
|
|| (!isModeratorOrAdmin && historyToken.equals("monitorBudgets"))
|
161
|
|| (!isModeratorOrAdmin && historyToken.equals("monitorUsers"))
|
162
|
|| (!isModeratorOrAdmin && historyToken.equals("monitorUserRoles"))
|
163
|
|| (!isModeratorOrAdmin && historyToken.equals("monitor"))) {
|
164
|
historyToken = "home";
|
165
|
}
|
166
|
|
167
|
if((!isAdminOrAccountingOfficer && historyToken.equals("accountingMonitor"))
|
168
|
|| (!isAdminOrAccountingOfficer && historyToken.equals("accountingMonitorFundingRequests"))
|
169
|
|| (!isAdminOrAccountingOfficer && historyToken.equals("accountingMonitorBudgets"))) {
|
170
|
historyToken = "home";
|
171
|
}
|
172
|
|
173
|
if((!isLibrarian && historyToken.equals("newBudgetRequest"))
|
174
|
|| (!isLibrarian && historyToken.equals("existingBudgetRequests"))) {
|
175
|
historyToken = "home";
|
176
|
}
|
177
|
}
|
178
|
|
179
|
return historyToken;
|
180
|
}
|
181
|
}
|