Project

General

Profile

« Previous | Next » 

Revision 50321

1. Modify web.xml file
2. Add check cookie methods on user service. Delete code for login/register/activate profile
3. Disable #login/#register uri's

View differences:

RepositoryManager.java
12 12
import com.google.gwt.user.client.History;
13 13
import com.google.gwt.user.client.Window;
14 14
import com.google.gwt.user.client.rpc.AsyncCallback;
15
import com.google.gwt.user.client.ui.FlowPanel;
16
import com.google.gwt.user.client.ui.RootPanel;
17 15
import eu.dnetlib.domain.functionality.UserProfile;
18 16
import eu.dnetlib.repo.manager.client.services.UserService;
19 17
import eu.dnetlib.repo.manager.client.services.UserServiceAsync;
20 18
import eu.dnetlib.repo.manager.shared.Tuple;
21
import eu.dnetlib.repo.manager.shared.UserAccessException;
22 19

  
23 20
import java.util.logging.Level;
24 21
import java.util.logging.Logger;
......
54 51
        History.addValueChangeHandler(new ValueChangeHandler<String>() {
55 52
            @Override
56 53
            public void onValueChange(ValueChangeEvent<String> event) {
57

  
58 54
                String historyToken = event.getValue();
59

  
60 55
                if(historyToken!=null && !historyToken.equals("")) {
61

  
62 56
                    String finalHistoryToken = getFinalHistoryToken(historyToken);
63

  
57
                    Window.alert(finalHistoryToken);
64 58
                    History.newItem(finalHistoryToken);
65 59
                    NavigationManager.getInstance().navigate(finalHistoryToken);
66

  
67
                } else {
68

  
60
                }else {
69 61
                    //TODO kapou peftei se loop
70 62
                    History.newItem("landing");
71 63
                    NavigationManager.getInstance().navigate("landing");
72 64
                }
73 65
            }
74 66
        });
67
        checkCookie("dashboard");
68
        addLogoutHandler();
69
    }
75 70

  
76
        String hash = Window.Location.getHash();
77
        String activationId = Window.Location.getParameter("activationId");
78
        final String hashValue = hash.substring(1);
71
    private void checkCookie(final String nextPage) {
72
        userService.checkCookie(new AsyncCallback<Tuple<UserProfile, String>>() {
73
            @Override
74
            public void onFailure(Throwable throwable) {
75
                if(throwable instanceof ClassCastException)
76
                    Window.alert("Authentication class exception");
77
                else
78
                    Window.alert("User not found exception");
79 79

  
80
        if(hashValue.startsWith("activateAccount")) {
80
                Cookies.removeCookie("currentUser");
81 81

  
82
            Cookies.removeCookie("currentUser");
82
                //String finalHistoryToken = getFinalHistoryToken(hashValue);
83
                History.newItem("landing");
84
                NavigationManager.getInstance().navigate("landing");
85
            }
86
            @Override
87
            public void onSuccess(Tuple<UserProfile, String> result) {
88
                RepositoryManager.currentUser = result.getFirst();
89
                RepositoryManager.currentUserRole = result.getSecond();
83 90

  
84
            if(activationId!=null) {
91
                if (RepositoryManager.currentUser != null)
92
                    Document.get().getElementById("currentUser").setInnerText(RepositoryManager.currentUser.getFirstname()
93
                            + " " + RepositoryManager.currentUser.getLastname());
85 94

  
86
                userService.activateUser(activationId, new AsyncCallback<Void>() {
95
                //TODO use role instead of email
96
                if(RepositoryManager.currentUserRole.equals("admin")) {
97
                    Document.get().getElementById("admin1").getStyle().setDisplay(Style.Display.BLOCK);
98
                    Document.get().getElementById("admin2").getStyle().setDisplay(Style.Display.BLOCK);
99
                }
87 100

  
88
                    @Override
89
                    public void onFailure(Throwable throwable) {
90

  
91
                        if(throwable instanceof UserAccessException) {
92
                            UserAccessException uae = (UserAccessException) throwable;
93
                            LoginPage.getInstance().showSuccessfulMessage(uae.getMessage());
94
                            Window.Location.replace(GWT.getHostPageBaseURL() + "#login");
95
                        } else {
96
                            //TODO
97
                        }
98
                    }
99

  
100
                    @Override
101
                    public void onSuccess(Void aVoid) {
102

  
103
                        //TODO it does not show the message because it refreshes the page
104
                        LoginPage.getInstance().showSuccessfulMessage("Account activation was successful! You can now log-in " +
105
                                "using your account details.");
106
                        Window.Location.replace(GWT.getHostPageBaseURL() + "#login");
107
//                        NavigationManager.getInstance().navigate("login");
108
//                        Window.Location.replace(GWT.getHostPageBaseURL() + "#login");
109
                    }
110
                });
111

  
112
            } else {
113

  
114
                //TODO invalid url
101
                //String finalHistoryToken = getFinalHistoryToken(page);
102
                History.newItem(nextPage);
103
                NavigationManager.getInstance().navigate(nextPage);
115 104
            }
105
        });
106
    }
116 107

  
117
        } else {
108
    private void addLogoutHandler() {
118 109

  
119
            String encryptedEmail = Cookies.getCookie("currentUser");
120
            if (encryptedEmail == null) {
110
        $(".logoutLink").click(new Function() {
121 111

  
122
                String finalHistoryToken = getFinalHistoryToken(hashValue);
123
                History.newItem(finalHistoryToken);
124
                NavigationManager.getInstance().navigate(finalHistoryToken);
112
            public boolean f(Event e) {
125 113

  
126
            } else {
127

  
128
                userService.getUserByEmail(Crypto.decrypt(encryptedEmail), new AsyncCallback<Tuple<UserProfile, String>>() {
129

  
114
                Cookies.removeCookie("currentUser");
115
                userService.clearCookie(new AsyncCallback<Void>() {
130 116
                    @Override
131
                    public void onFailure(Throwable caught) {
117
                    public void onFailure(Throwable throwable) {
132 118

  
133
                        Cookies.removeCookie("currentUser");
134

  
135
                        String finalHistoryToken = getFinalHistoryToken(hashValue);
136
                        History.newItem(finalHistoryToken);
137
                        NavigationManager.getInstance().navigate(finalHistoryToken);
138 119
                    }
139 120

  
140 121
                    @Override
141
                    public void onSuccess(Tuple<UserProfile, String> result) {
122
                    public void onSuccess(Void aVoid) {
123
                        RepositoryManager.currentUser = null;
124
                        RepositoryManager.currentUserRole = null;
142 125

  
143
                        RepositoryManager.currentUser = result.getFirst();
144
                        RepositoryManager.currentUserRole = result.getSecond();
145

  
146
                        if (RepositoryManager.currentUser != null)
147
                            Document.get().getElementById("currentUser").setInnerText(RepositoryManager.currentUser.getFirstname()
148
                                    + " " + RepositoryManager.currentUser.getLastname());
149

  
150
                        //TODO use role instead of email
151
                        if(RepositoryManager.currentUserRole.equals("admin")) {
152
                            Document.get().getElementById("admin1").getStyle().setDisplay(Style.Display.BLOCK);
153
                            Document.get().getElementById("admin2").getStyle().setDisplay(Style.Display.BLOCK);
154
                        }
155

  
156
                        String finalHistoryToken = getFinalHistoryToken(hashValue);
157
                        History.newItem(finalHistoryToken);
158
                        NavigationManager.getInstance().navigate(finalHistoryToken);
126
                        if(RepositoryManager.currentToken.equals("landing"))
127
                            NavigationManager.getInstance().navigate("landing");
128
                        else
129
                            History.newItem("landing");
159 130
                    }
160 131
                });
161
            }
162
        }
163

  
164
        addLogoutHandler();
165
    }
166

  
167
    private void addLogoutHandler() {
168

  
169
        $(".logoutLink").click(new Function() {
170

  
171
            public boolean f(Event e) {
172

  
173
                Cookies.removeCookie("currentUser");
174
                RepositoryManager.currentUser = null;
175
                RepositoryManager.currentUserRole = null;
176

  
177
                if(RepositoryManager.currentToken.equals("landing"))
178
                    NavigationManager.getInstance().navigate("landing");
179
                else
180
                    History.newItem("landing");
181

  
182 132
                return false;
183 133
            }
184 134
        });

Also available in: Unified diff