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