コード例 #1
0
ファイル: AjaxLogin.java プロジェクト: puneethp/IPoll
  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    HttpSession session = req.getSession(false);

    if (session != null) {
      if (session.getAttribute("user") != null)
        if (session.getAttribute("user") instanceof User) {
          User user = (User) session.getAttribute("user");
          Gson gson = new Gson();
          String json = gson.toJson(user);
          resp.getWriter().write(json);
        }
    } else {
      if (req.getParameter("id") != null && req.getParameter("password") != null) {
        UserServ serv;
        serv = new UserServ();
        UserDAO udao = new UserDAO();
        udao.setSessionFactory(factory);
        serv.setDao(udao);
        if (serv.isValidUser(req.getParameter("id"), req.getParameter("password"))) {
          User user = serv.getUser();
          Gson gson = new Gson();
          String json = gson.toJson(user);
          resp.getWriter().write(json);
          session = req.getSession();
          session.setAttribute("user", user);
        }
      }
    }
  }
コード例 #2
0
ファイル: UserDAOTest.java プロジェクト: italopaiva/EuVou
  public void testDeleteByName() throws ParseException, UserException {

    UserDAO userDAO = new UserDAO();
    User user =
        new User("Marcelo", "marceloChavosaoa", "*****@*****.**", "123456", "24/11/1969");
    if (!userDAO.save(user).contains("Salvo")) assertTrue(false);
    assertTrue(userDAO.delete("marceloChavosaoa").contains("Salvo"));
  }
コード例 #3
0
ファイル: UserDAOTest.java プロジェクト: italopaiva/EuVou
  public void testDeleteById() throws ParseException, UserException, JSONException {

    UserDAO userDAO = new UserDAO();
    User user = new User("VIny", "viny", "*****@*****.**", "123456", "14/02/1995");
    if (!userDAO.save(user).contains("Salvo")) assertTrue(false);
    int id = userDAO.searchUserByUsername("viny").getJSONObject("0").getInt("idUser");
    assertTrue(userDAO.delete(id).contains("Salvo"));
    userDAO.delete("viny");
  }
コード例 #4
0
ファイル: Welcome.java プロジェクト: f9chen/cmu-projects
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html");
    RequestDispatcher view = null;
    HttpSession session = request.getSession(true);
    if (session.getAttribute("login") == null) {
      session.setAttribute("login", false);
    }
    String email = request.getParameter("email");
    String pwd = request.getParameter("pwd");
    session.setAttribute("email", email);

    try {
      request.setAttribute("numCourses", courseDAO.getNumCourse());
      if (email == null) {
        request.setAttribute("numCourses", courseDAO.getNumCourse());
        view = request.getRequestDispatcher("welcome.jsp");
        view.forward(request, response);
        return;
      }
      if (!(Boolean) session.getAttribute("login")) {
        if (userDAO.lookup(email) != null) {
          if (userDAO.lookup(email).getPassword().equals(pwd)) {
            session.setAttribute("login", true);

            request.setAttribute("email", email);
            request.setAttribute("courseListSelect", userDAO.getMyCourseListToSelectHTML(email));
            request.setAttribute("notes", userDAO.getMyCourseNotesToHTML(email, courseDAO));
            request.setAttribute("courseList", userDAO.getMyCourseListToHTML(email));
            view = request.getRequestDispatcher("your-courses.jsp");
            view.forward(request, response);
          } else {
            request.setAttribute("message", "login error!");
            view = request.getRequestDispatcher("welcome.jsp");
            view.forward(request, response);
          }
        } else {
          request.setAttribute("numCourses", courseDAO.getNumCourse());
          view = request.getRequestDispatcher("welcome.jsp");
          view.forward(request, response);
        }
      } else {
        request.setAttribute("numCourses", courseDAO.getNumCourse());
        request.setAttribute("email", email);
        request.setAttribute("message", "already logged in!");
        view = request.getRequestDispatcher("welcome.jsp");
        view.forward(request, response);
      }
    } catch (MyDAOException e) {
    }
  }
コード例 #5
0
ファイル: GetUser.java プロジェクト: JavaSEaudio/backend
 @GET
 @Path("/id")
 @Produces(MediaType.APPLICATION_JSON)
 public Response getUserInfo(@QueryParam("id") int id) {
   UserDAO userDAO = Factory.getInstance().getUserDAO();
   try {
     UserDTO user = new UserDTO(userDAO.getById(id));
     log.info("GetUser ID: success");
     return Response.ok().entity(user).build();
   } catch (Exception e) {
     log.info("GetUser ID: exception");
     return Response.ok().status(400).build();
   }
 }
コード例 #6
0
ファイル: UserDAOTest.java プロジェクト: italopaiva/EuVou
 public void testSave() throws ParseException, UserException {
   UserDAO userDAO = new UserDAO();
   User user;
   user =
       new User(
           "marceloChavosaao",
           "marceloChavosaao",
           "*****@*****.**",
           "*****@*****.**",
           "123456",
           "123456",
           "11/09/2015");
   assertTrue(userDAO.save(user).contains("Salvo"));
   userDAO.delete("marceloChavosaao");
 }
コード例 #7
0
ファイル: GetUser.java プロジェクト: JavaSEaudio/backend
  @GET
  @Path("/mylogin")
  @Produces(MediaType.APPLICATION_JSON)
  public Response editUser(@CookieParam(value = "name") String uid) {

    UserDAO userDAO = Factory.getInstance().getUserDAO();
    SessionDAO sessionDAO = Factory.getInstance().getSessionDAO();

    UserEntity user = userDAO.getById(sessionDAO.haveKey(uid));
    UserDTO userDTO = new UserDTO(user);
    if (user == null) {

      return Response.ok().status(400).build();
    }
    System.out.println(user.getLogin());

    return Response.ok().entity(userDTO).build();
  }
コード例 #8
0
ファイル: GetUser.java プロジェクト: JavaSEaudio/backend
 @GET
 @Path("/all")
 @Produces(MediaType.APPLICATION_JSON)
 public Response getAllUsers(@CookieParam("name") String uid) {
   int userid = Sessions.uid(uid);
   if (Factory.getInstance().getUserDAO().getById(userid).getAccess() == 2) {
     UserDAO userDAO = Factory.getInstance().getUserDAO();
     try {
       ArrayList<UserDTO> users = (ArrayList<UserDTO>) GetListDTO.getListUserDTO(userDAO.getAll());
       log.info("GetUser ALL: success");
       return Response.ok(new GenericEntity<ArrayList<UserDTO>>(users) {}).build();
     } catch (Exception e) {
       log.info("GetUser ALL: exception");
       return null;
     }
   }
   return Response.status(400).entity("not access").build();
 }
コード例 #9
0
ファイル: UserDAOTest.java プロジェクト: italopaiva/EuVou
 public void testUpdateUser() throws ParseException, UserException, JSONException {
   UserDAO userDAO = new UserDAO();
   User user =
       new User(
           1,
           "Vinicius ppp",
           "umteste",
           "14/02/1995",
           "*****@*****.**",
           "*****@*****.**",
           "123456",
           "123456");
   if (!userDAO.save(user).contains("Salvo")) {
     assertTrue(false);
     userDAO.delete("umteste");
   }
   assertTrue(userDAO.update(user).contains("Salvo"));
   userDAO.delete("umteste");
 }
コード例 #10
0
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    User u = new User();
    UserDAO userDao = new UserDAO();
    u.setUserName(request.getParameter("user"));
    u.setPassword(request.getParameter("password"));
    u.setEmail(request.getParameter("email"));
    userDao.AddUser(u);

    RequestDispatcher rd = request.getRequestDispatcher("/home.jsp");

    try {
      rd.forward(request, response);
    } catch (ServletException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
コード例 #11
0
ファイル: LoginAction.java プロジェクト: hustjf/Enroll
 @Override
 public ActionForward execute(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   LoginActionForm loginActionForm = (LoginActionForm) form;
   String username = loginActionForm.getUsername();
   String password = loginActionForm.getPassword();
   UserInfo userinfo = new UserInfo();
   CourseInfo courseinfo = new CourseInfo();
   BeanFactory factory = new ClassPathXmlApplicationContext(contextConfigLocation);
   UserDAO userDAO = (UserDAO) factory.getBean("UserDao");
   UserEntity user = userDAO.finduserByUsernamePassword(username, password);
   if (user != null) {
     userinfo.setUsername(username);
     userinfo.setPassword(password);
     userinfo.setIsright(true);
     userinfo.setStuid(user.getStuid());
     List<CourseEntity> course = userDAO.findcourseByStuid(user.getStuid());
     List<String> coursename = courseinfo.getCoursename();
     List<Integer> coursenumber = courseinfo.getCoursenumber();
     for (CourseEntity cn : course) {
       coursename.add(cn.getCoursename());
       coursenumber.add(cn.getCoursenumber());
     }
     courseinfo.setCoursename(coursename);
     courseinfo.setCoursenumber(coursenumber);
   } else {
     userinfo.setIsright(false);
   }
   request.setAttribute("courseinfo", courseinfo);
   HttpSession session = request.getSession();
   session.setAttribute("userinfo", userinfo);
   return mapping.findForward("login");
 }
コード例 #12
0
  public static Result getUserGifts(String userId) {
    if (!Utils.checkCredentials(request())) {
      return unauthorized();
    }
    try {
      User user = UserDAO.getInstance().findUserById(userId);
      ObjectNode result = Json.newObject();
      ArrayNode resultArr = new ArrayNode(JsonNodeFactory.instance);
      for (UserGiftMap userGiftMap : user.getWonGifts())
        resultArr.add(GiftDAO.getInstance().findGiftById(userGiftMap.getGiftId()).toJson());

      result.put("gifts", resultArr);
      return ok(result);
    } catch (Exception e) {
      return generateInternalServer(e.getMessage());
    }
  }
コード例 #13
0
ファイル: UserDAOTest.java プロジェクト: italopaiva/EuVou
 public void testDisableLogin() throws ParseException, UserException, JSONException {
   UserDAO userDAO = new UserDAO();
   User user =
       new User(
           1,
           "Vinicius Pinheiro",
           "umteste",
           "14/02/1995",
           "*****@*****.**",
           "*****@*****.**",
           "123456",
           "123456");
   if (!userDAO.save(user).contains("Salvo")) {
     assertTrue(false);
     userDAO.delete("umteste");
   }
   int id = userDAO.searchUserByUsername("umteste").getJSONObject("0").getInt("idUser");
   assertTrue(userDAO.disableUser(id).contains("Salvo"));
   userDAO.delete("umteste");
 }
コード例 #14
0
 public boolean isValid(User user, ConstraintValidatorContext context) {
   return !userDao.containsUserWithLogin(user.getLogin());
 }
コード例 #15
0
  //    @PostConstruct
  public void init() {

    System.out.println("PostConstruct method call...");

    User ulan = new User();
    ulan.setName("Ulan");

    userDAO.save(ulan);

    User carl = new User("Carl");
    userDAO.save(carl);

    //        System.out.println(ulan);

    List<User> userList = userDAO.getUserList();

    System.out.println("UserList:");

    for (User u : userList) {
      System.out.println(u);
    }

    Loan loan1 = new Loan();
    loan1.setAmount(300);
    loan1.setTerm(15);

    Loan loan2 = new Loan();
    loan2.setAmount(200);
    loan2.setTerm(10);

    Loan loan3 = new Loan();
    loan3.setAmount(400);
    loan3.setTerm(20);

    User user1 = userList.get(0);

    user1.addLoan(loan1);
    user1.addLoan(loan2);

    User user2 = userList.get(1);

    user2.addLoan(loan3);

    userDAO.save(user1);
    userDAO.save(user2);

    List<Loan> loanList = loanDAO.getLoanList();
    System.out.println("Printing loanList:");
    for (Loan loan : loanList) {
      System.out.println(loan);
    }

    System.out.println("Printing whole DB:");
    userList = userDAO.getUserList();
    for (User u : userList) {
      System.out.println(u);
      for (Loan loan : u.getLoanList()) {
        System.out.println(loan);
      }
    }

    System.out.println("Printing list for User with ID 1");
    user1 = userDAO.getById(1);
    for (Loan loan : user1.getLoanList()) {
      System.out.println(loan);
    }

    System.out.println("Printing list for User with ID 2");
    user2 = userDAO.getById(2);
    for (Loan loan : user2.getLoanList()) {
      System.out.println(loan);
    }
  }