Rev 2049 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2049 | Rev 2069 | ||
---|---|---|---|
1 | package pt.estgp.es.exemplos.hibernate.web.login; |
1 | package pt.estgp.es.exemplos.hibernate.web.login; |
2 | 2 | ||
3 | import org.json.JSONException; |
3 | import org.json.JSONException; |
4 | import org.json.JSONObject; |
4 | import org.json.JSONObject; |
5 | import pt.estgp.es.exemplos.hibernate.HibernateUtils; |
5 | import pt.estgp.es.exemplos.hibernate.HibernateUtils; |
6 | import pt.estgp.es.exemplos.hibernate.UserSession; |
6 | import pt.estgp.es.exemplos.hibernate.UserSession; |
7 | import pt.estgp.es.exemplos.hibernate.web.SecurityFilter; |
7 | import pt.estgp.es.exemplos.hibernate.web.SecurityFilter; |
8 | import pt.estgp.es.exemplos.hibernate.web.UserFilter; |
8 | import pt.estgp.es.exemplos.hibernate.web.UserFilter; |
9 | import pt.estgp.es.exemplos.hibernate.web.rest.AbstractRestServlet; |
9 | import pt.estgp.es.exemplos.hibernate.web.rest.AbstractRestServlet; |
10 | 10 | ||
11 | import javax.servlet.ServletException; |
11 | import javax.servlet.ServletException; |
12 | import javax.servlet.http.HttpServletRequest; |
12 | import javax.servlet.http.HttpServletRequest; |
13 | import javax.servlet.http.HttpServletResponse; |
13 | import javax.servlet.http.HttpServletResponse; |
14 | import java.io.IOException; |
14 | import java.io.IOException; |
15 | 15 | ||
16 | public class LoginRest extends AbstractRestServlet |
16 | public class LoginRest extends AbstractRestServlet |
17 | { |
17 | { |
18 | public JSONObject login(JSONObject data, HttpServletRequest req, HttpServletResponse resp) throws JSONException |
18 | public JSONObject login(JSONObject data, HttpServletRequest req, HttpServletResponse resp) throws JSONException |
19 | { |
19 | { |
20 | 1.5.0/docs/api/java/lang/String.html">String username = data.getString("username"); |
20 | 1.5.0/docs/api/java/lang/String.html">String username = data.getString("username"); |
21 | 1.5.0/docs/api/java/lang/String.html">String password = data.getString("password"); |
21 | 1.5.0/docs/api/java/lang/String.html">String password = data.getString("password"); |
22 | 22 | ||
23 | HibernateUtils.getCurrentSession().beginTransaction(); |
23 | HibernateUtils.getCurrentSession().beginTransaction(); |
24 | 24 | ||
25 | //TODO COMPLETAR |
25 | //TODO COMPLETAR |
26 | UserSession session = null; |
26 | UserSession session = null; |
27 | try { |
27 | try { |
28 | session = SecurityFilter.loadSessionProxy(req); |
28 | session = SecurityFilter.loadSessionProxy(req); |
29 | UserSession persistente = (UserSession) HibernateUtils.getCurrentSession().get(UserSession.class,session.getCookie()); |
29 | UserSession persistente = (UserSession) HibernateUtils.getCurrentSession().get(UserSession.class,session.getCookie()); |
30 | //persistente.setUser(u); |
30 | //persistente.setUser(u); |
31 | } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) { |
31 | } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) { |
32 | e.printStackTrace(); |
32 | e.printStackTrace(); |
33 | } catch (ServletException e) { |
33 | } catch (ServletException e) { |
34 | e.printStackTrace(); |
34 | e.printStackTrace(); |
35 | } |
35 | } |
36 | 36 | ||
37 | 37 | ||
38 | 38 | ||
39 | 1.5.0/docs/api/java/lang/System.html">System.out.println(username); |
39 | 1.5.0/docs/api/java/lang/System.html">System.out.println(username); |
40 | 1.5.0/docs/api/java/lang/System.html">System.out.println(password); |
40 | 1.5.0/docs/api/java/lang/System.html">System.out.println(password); |
41 | 41 | ||
42 | 42 | ||
43 | 43 | ||
44 | JSONObject js = new JSONObject(); |
44 | JSONObject js = new JSONObject(); |
45 | js.put("result","ok"); |
45 | js.put("result","ok"); |
46 | 46 | ||
47 | addMessage("User autenticado com sucesso",req); |
47 | addMessage("User autenticado com sucesso",req); |
48 | 48 | ||
49 | return js; |
49 | return js; |
50 | } |
50 | } |
51 | 51 | ||
52 | public JSONObject logout(JSONObject data, HttpServletRequest req, HttpServletResponse resp) throws JSONException |
52 | public JSONObject logout(JSONObject data, HttpServletRequest req, HttpServletResponse resp) throws JSONException |
53 | { |
53 | { |
54 | JSONObject js = new JSONObject(); |
54 | JSONObject js = new JSONObject(); |
55 | js.put("result","ok"); |
55 | js.put("result","ok"); |
56 | 56 | ||
57 | return js; |
57 | return js; |
58 | } |
58 | } |
- | 59 | ||
- | 60 | public JSONObject saveSeccao(JSONObject data, HttpServletRequest req, HttpServletResponse resp) throws JSONException |
|
- | 61 | { |
|
- | 62 | JSONObject seccao = data.getJSONObject("seccao"); |
|
- | 63 | ||
- | 64 | ||
- | 65 | 1.5.0/docs/api/java/lang/System.html">System.out.println("TITULO:" + seccao.getString("titulo")); |
|
- | 66 | JSONObject js = new JSONObject(); |
|
- | 67 | js.put("result","ok"); |
|
- | 68 | ||
- | 69 | addMessage("Seccao salva com sucesso",req); |
|
- | 70 | ||
- | 71 | return js; |
|
- | 72 | } |
|
59 | } |
73 | } |
60 | 74 |