99238cf0 |
1 | /* |
2 | * To change this template, choose Tools | Templates |
3 | * and open the template in the editor. |
4 | */ |
5 | package org.ufcspa.simdecs.comunicacao; |
6 | |
99238cf0 |
7 | import java.io.PrintWriter; |
99238cf0 |
8 | import javax.servlet.http.HttpServletRequest; |
9 | import javax.servlet.http.HttpServletResponse; |
99238cf0 |
10 | import javax.persistence.EntityManager; |
11 | import javax.persistence.NoResultException; |
23fb5861 |
12 | import org.ufcspa.simdecs.action.Action; |
99238cf0 |
13 | import org.ufcspa.simdecs.entities.Usuario; |
23fb5861 |
14 | import org.ufcspa.simdecs.util.JadeUtil; |
99238cf0 |
15 | |
16 | /** |
17 | * |
d4cba9a5 |
18 | * @author pbarros |
d4cba9a5 |
19 | * |
99238cf0 |
20 | */ |
cff9bc95 |
21 | public class MetodoAutenticacao extends BaseComunicacao { |
99238cf0 |
22 | |
cff9bc95 |
23 | @Override |
24 | protected void executaServico(EntityManager em, HttpServletRequest request, HttpServletResponse response, PrintWriter out) |
25 | throws Exception |
26 | { |
99238cf0 |
27 | response.setContentType( "text/xml" ); |
28 | response.setHeader( "Cache-Control", "no-cache" ); |
99238cf0 |
29 | |
30 | out.println( "<xml>" ); |
31 | |
32 | Usuario user; |
33 | try { |
34 | user = (Usuario) em.createQuery("select usu from Usuario as usu where usu.login=:login and usu.senha=:senha") |
35 | .setParameter("login", request.getParameter("user").toLowerCase()) |
36 | .setParameter("senha", request.getParameter("pass")) |
37 | .getSingleResult(); |
38 | |
39 | out.println( "<id>" + String.valueOf(user.getId()) + "</id>" ); |
40 | } catch (NoResultException ne) { |
41 | out.println( "<id>" + "0" + "</id>" ); |
cff9bc95 |
42 | } finally { |
99238cf0 |
43 | out.println( "</xml>" ); |
99238cf0 |
44 | } |
cff9bc95 |
45 | // JadeUtil instance = JadeUtil.getInstance(); |
46 | // Action ac = instance.getActions().get("sendmessage"); |
47 | // ac.perform(this, request, response); |
48 | // out.print(ac.toString()); |
99238cf0 |
49 | } |
99238cf0 |
50 | } |