Package org.itcr.myguru.model

Examples of org.itcr.myguru.model.User


        // Gather information
        HttpSession session = request.getSession();
        String uri = request.getServletPath();
        String method = request.getMethod();
        User user = null;
        try {
            user = (User) session.getAttribute("user");
        } catch(Exception e) {}
        boolean auth = user != null;
       
        // Result
        Command command = null;
       
        // Web
        if(uri.equals("/")) {
            command = new HomeCommand();
        } else if(uri.equals("/debug")) {
            command = new DebugCommand();
        } else if(uri.equals("/dashboard")) {
            if(auth && user.isUser() && user.isEnabled()) {
                command = new DashboardCommand();
            } else {
                command = new UnauthorizedCommand();
            }
        } else if(uri.equals("/profile")) {
            //if(auth && (user.isUser() || user.isAdmin())) {
            if(auth) {
                command = new ProfileCommand();
            } else {
                command = new UnauthorizedCommand();
            }
        } else if(uri.equals("/admin")) {
            if(auth && user.isAdmin() && user.isEnabled()) {
                command = new AdminCommand();
            } else {
                command = new UnauthorizedCommand();
            }
        // AJAX
        } else if(uri.equals("/login")) {
            command = new LoginCommand();
        } else if(uri.equals("/register")) {
            command = new RegisterCommand();
        } else if(uri.equals("/logout")) {
            command = new LogoutCommand();
        } else if(uri.equals("/request")) {
            if(auth && user.isUser() && user.isEnabled()) {
                command = new RequestCommand();
            } else {
                command = new UnauthorizedCommand();
            }
        } else if(uri.equals("/answer")) {
            if(auth && user.isUser() && user.isEnabled()) {
                command = new AnswerCommand();
            } else {
                command = new UnauthorizedCommand();
            }
        } else if(uri.equals("/upload/mygeo")) {
            if(auth && user.isAdmin() && user.isEnabled()) {
                command = new MyGeoCommand();
            } else {
                command = new UnauthorizedCommand();
            }
        } else if(uri.equals("/expertise/add") ||
                uri.equals("/expertise/remove")) {
            if(auth && user.isUser() && user.isEnabled()) {
                command = new ExpertiseCommand();
            } else {
                command = new UnauthorizedCommand();
            }
        }
View Full Code Here


    public void execute(HttpServletRequest request, HttpServletResponse response, DataAccessObject dao)
            throws ServletException, IOException {
       
        // Get data
        //  :: User (CommandFactory should guarantee that user is logged in)
        User user = (User) request.getSession().getAttribute("user");
       
        // Handle method POST
        String method = request.getMethod();
        if(method.equals("POST")) {
            String msg = handlePOST(user, request, dao);
            request.setAttribute("msg", msg);
        }
       
        // Set data
        request.setAttribute("user", user);
        if(user.isEnabled()) {
            //  :: Profile is enabled
            request.setAttribute("isEnabled", true);
            //  :: Permissions
            request.setAttribute("isUser", user.isUser());
            request.setAttribute("isAdmin", user.isAdmin());
            //  :: Expertise options for user
            List<Location> options = dao.getOptionsForUser(user);
            request.setAttribute("options", options);
        } else {
            request.setAttribute("isEnabled", false);
View Full Code Here

     */
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response, DataAccessObject dao)
            throws ServletException, IOException {
        // Get parameters
        User user = (User) request.getSession().getAttribute("user");
        String action = request.getParameter("action");
        String code = request.getParameter("code");
       
        // Configure response
        response.setContentType("text/html");
       
        // Verify arguments
        if(action == null || code == null ||
                action.equals("") || code.equals("") ||
                !(action.equals("remove") || action.equals("add"))
           ) {
            return;
        }
       
        // Business logic
        //  :: Find Location by code
        Location loc = dao.findLocationByCode(code);
        if(loc == null) {
            return;
        }
       
        // Add location to user expertise
        boolean hasExpertise = user.hasExpertise(loc);
        if(action.equals("add")) { // Add
            // Do nothing if user is already expert
            if(hasExpertise) {
                return;
            }
            user.addExpertise(loc);
           
        } else { // Remove
            // Do nothing if user is already expert
            if(!hasExpertise) {
                return;
            }
            user.removeExpertise(loc);
        }
       
        try {
            dao.persistChanges(user);
        } catch(Exception e) {
View Full Code Here

            out.flush();
            out.close();
            return;
        }
        // :: Find user
        User user = dao.findUserByLogin(usr);
        if(user == null) {
            out.print(-3);
            out.flush();
            out.close();
            return;
        }
        //  :: Match password
        if(user.comparePassword(pwd)) {
            session.setAttribute("user", user);
            // Dashboard : 0
            // Profile   : 1
            // Admin     : 2
            if(user.isEnabled()) {
                if(user.isAdmin()) {
                    out.print(2);
                } else if(user.isUser()) {
                    out.print(0);
                } else {
                    out.print(1);
                }
            } else {
View Full Code Here

    public void execute(HttpServletRequest request, HttpServletResponse response, DataAccessObject dao)
            throws ServletException, IOException {
       
        // Get data
        //  :: User
        User user = (User) request.getSession().getAttribute("user");
        //  :: Permissions
        if(user != null) {
            request.setAttribute("isUser", user.isUser());
            request.setAttribute("isAdmin", user.isAdmin());
        } else {
            request.setAttribute("isUser", false);
            request.setAttribute("isAdmin", false);
        }
       
View Full Code Here

    private void handleGET(HttpServletRequest request, HttpServletResponse response, DataAccessObject dao)
            throws ServletException, IOException {
       
        // Get data
        //  :: User
        User user = (User) request.getSession().getAttribute("user");
        //  :: Permissions
        if(user != null) {
            request.setAttribute("isUser", user.isUser());
            request.setAttribute("isAdmin", user.isAdmin());
        } else {
            request.setAttribute("isUser", false);
            request.setAttribute("isAdmin", false);
        }
        //  :: Pending recommendations
View Full Code Here

    private void handlePOST(HttpServletRequest request, HttpServletResponse response, DataAccessObject dao)
            throws ServletException, IOException {
       
        // Get data
        //  :: User
        User user = (User) request.getSession().getAttribute("user");
        //  :: Page
        String page_raw = request.getParameter("page");
        int page = 0;
        try {
            page = Integer.parseInt(page_raw);
View Full Code Here

    public void execute(HttpServletRequest request, HttpServletResponse response, DataAccessObject dao)
            throws ServletException, IOException {
       
        // Get data
        //  :: User
        User user = (User) request.getSession().getAttribute("user");
        //  :: Permissions
        if(user != null) {
            request.setAttribute("isLoggedIn", true);
            if(user.isEnabled()) {
                request.setAttribute("isUser", user.isUser());
                request.setAttribute("isAdmin", user.isAdmin());
            } else {
                request.setAttribute("isUser", false);
                request.setAttribute("isAdmin", false);
            }
           
View Full Code Here

            out.close();
            return;
        }
        // Business logic
        //  :: Check if login name is in use
        User user = dao.findUserByLogin(usr);
        if(user != null) {
            out.print(-2);
            out.flush();
            out.close();
            return;
        }
        //  :: Check if email is a valid email
        Pattern p = Pattern.compile(".+@.+\\.[a-z]+");
        Matcher m = p.matcher(email);
        boolean matchFound = m.matches();
        if(!matchFound) {
            out.print(-3);
            out.flush();
            out.close();
            return;
        }
        //  :: Check if email is in use
        user = dao.findUserByEmail(email);
        if(user != null) {
            out.print(-4);
            out.flush();
            out.close();
            return;
        }
        //  :: Create a new User
        User registered = new User();
        registered.setLogin(usr);
        registered.setEmail(email);
        registered.setPassword(pwd);
        registered.setUser(true); // Default role
        try {
            dao.save(registered);
            out.print(0);
        } catch(Exception e) {
            out.print(-5);
View Full Code Here

    public void execute(HttpServletRequest request, HttpServletResponse response, DataAccessObject dao)
            throws ServletException, IOException {
        // Get parameters
        HttpSession session = request.getSession();
        String id_raw = request.getParameter("id");
        User user = (User) session.getAttribute("user");
       
        // Configure response
        response.setContentType("application/json");
        PrintWriter out = response.getWriter();
        CommObject result = new CommObject();
       
        // Verify arguments
        if(id_raw == null || id_raw.equals("")) {
            result.setMessage("Wrong arguments");
            result.setStatus(-1);
            out.print(result);
            out.flush();
            out.close();
            return;
        }

        // Business logic
        //  :: Check if logged in
        if(user == null) {
            result.setMessage("Not logged in");
            result.setStatus(-2);
            out.print(result);
            out.flush();
            out.close();
            return;
        }
        // :: Find Recommendation
        int id = -1;
        try {
            id = Integer.parseInt(id_raw);
        } catch(Exception e) {}
        Recommendation recm = dao.findRecommendationById(id);
        if(recm == null) {
            result.setMessage("Recommendation not found");
            result.setStatus(-3);
            out.print(result);
            out.flush();
            out.close();
            return;
        }
        //  :: Check ownership
        if(recm.getAssignedTo().getId() != user.getId()) {
            result.setMessage("You are not owner");
            result.setStatus(-4);
        } else {
            // Return object
            result.setMessage("Success");
View Full Code Here

TOP

Related Classes of org.itcr.myguru.model.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.