BrightSide Workbench Full Report + Source Code
IAgreements.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.action;
19 
20 import java.io.IOException;
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.http.HttpServletResponse;
23 import javax.servlet.http.HttpSession;
24 import org.turro.action.queue.NotificationCategory;
25 import org.turro.elephant.context.ElephantContext;
26 import org.turro.elephant.context.IConstructor;
27 import org.turro.plugin.contacts.IContact;
28 
33 public interface IAgreements {
34 
35  public String AGREE_CHECKED = "AGREE_CHECKED";
36 
37  public void setContact(IContact contact);
38  public void setContact(String idContact);
39  public boolean isValid();
40  public boolean canNotify();
41  public boolean canAccess();
42  public boolean canAct(String action);
43  public boolean declinedNotifications();
44  public boolean declinedAccessing();
45  public void sendIfNecessary(IConstructor constructor);
46  public boolean canSendEmails(NotificationCategory nc);
47  public String getPendingAccessURL();
48  public String getPendingActURL(String action);
49 
50  public static boolean checkAgreements(HttpServletRequest request, HttpServletResponse response) throws IOException {
51  String url = request.getRequestURL().toString();
52  HttpSession session = request.getSession(true);
53  if(session.getAttribute(Contacts.LOGGED_ICONTACT) != null &&
54  !Boolean.TRUE.equals(session.getAttribute(IAgreements.AGREE_CHECKED)) &&
55  !url.contains("/user/myagreements")) {
56  IAgreements agreements = Plugins.loadImplementation(IAgreements.class, "agreements");
57  if(agreements != null) {
58  agreements.setContact((IContact) session.getAttribute(Contacts.LOGGED_ICONTACT));
59  if(!agreements.canAccess()) {
60  response.sendRedirect(ElephantContext.getRootWebPath() + agreements.getPendingAccessURL());
61  return false;
62  } else {
63  session.setAttribute(IAgreements.AGREE_CHECKED, Boolean.TRUE);
64  }
65  }
66  }
67  return true;
68  }
69 
70 }
static final String LOGGED_ICONTACT
Definition: Contacts.java:45
static< T > T loadImplementation(Class< T > jclass)
Definition: Plugins.java:57
void setContact(String idContact)
boolean canSendEmails(NotificationCategory nc)
void sendIfNecessary(IConstructor constructor)
static boolean checkAgreements(HttpServletRequest request, HttpServletResponse response)
void setContact(IContact contact)
String getPendingActURL(String action)
boolean canAct(String action)