package pt.estgp.es.exemplos.hibernate.web.login;
import org.json.JSONException;
import org.json.JSONObject;
import pt.estgp.es.exemplos.hibernate.HibernateUtils;
import pt.estgp.es.exemplos.hibernate.UserSession;
import pt.estgp.es.exemplos.hibernate.web.SecurityFilter;
import pt.estgp.es.exemplos.hibernate.web.UserFilter;
import pt.estgp.es.exemplos.hibernate.web.rest.AbstractRestServlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class LoginRest
extends AbstractRestServlet
{
public JSONObject login
(JSONObject data, HttpServletRequest req, HttpServletResponse resp
) throws JSONException
{
1.5.0/docs/api/java/lang/String.html">String username = data.
getString("username");
1.5.0/docs/api/java/lang/String.html">String password = data.
getString("password");
HibernateUtils.
getCurrentSession().
beginTransaction();
//TODO COMPLETAR
UserSession session =
null;
try {
session = SecurityFilter.
loadSessionProxy(req
);
UserSession persistente =
(UserSession
) HibernateUtils.
getCurrentSession().
get(UserSession.
class,session.
getCookie());
//persistente.setUser(u);
} catch (1.5.0/docs/api/java/io/IOException.html">IOException e
) {
e.
printStackTrace();
} catch (ServletException e
) {
e.
printStackTrace();
}
1.5.0/docs/api/java/lang/System.html">System.
out.
println(username
);
1.5.0/docs/api/java/lang/System.html">System.
out.
println(password
);
JSONObject js =
new JSONObject
();
js.
put("result",
"ok");
addMessage
("User autenticado com sucesso",req
);
return js
;
}
public JSONObject logout
(JSONObject data, HttpServletRequest req, HttpServletResponse resp
) throws JSONException
{
JSONObject js =
new JSONObject
();
js.
put("result",
"ok");
return js
;
}
public JSONObject saveSeccao
(JSONObject data, HttpServletRequest req, HttpServletResponse resp
) throws JSONException
{
JSONObject seccao = data.
getJSONObject("seccao");
1.5.0/docs/api/java/lang/System.html">System.
out.
println("TITULO:" + seccao.
getString("titulo"));
JSONObject js =
new JSONObject
();
js.
put("result",
"ok");
addMessage
("Seccao salva com sucesso",req
);
return js
;
}
}