Package com.nevernote.admin

Source Code of com.nevernote.admin.DisableUserServlet

package com.nevernote.admin;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.context.support.GenericXmlApplicationContext;

import com.nevernote.domain.Users;
import com.nevernote.service.UsersService;


/*
*  What sort of requests should this Servlet receive?
*  1) Post-Login / Default Request
*     Should Receive:
*         - UserID / UserBean
*     Will Need to Do: 
*       - Retrieve full User Bean if only ID is passed
*       - Retrieve Preferences for User
*      - Retrieve Collection of Notes for User
*      - Use Sorting Algo from Preferences to Sort Notes and package in Collection to be passed to jsp
*     
*    
*  2) Note Delete Request
*     ShouldReceive:
*      - UserBean (at this point)
*      - Note name or Bean
*     Will Need to Do:
*      - Delete Note from DB
*      - Either call "Default" Request, or perform same actions
*  3) Change of Preferences?
*    - Seperate page or allow Dynamic option? (e.g. DropDown of color scheme on main jsp?)
*/


/**
* Servlet implementation class ClientDashServlet
*/
public class DisableUserServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public DisableUserServlet() {  
        super();
    }

  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
   
    HttpSession session = request.getSession();
    session.setMaxInactiveInterval(-1);
   
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context.xml");
    ctx.refresh();

    UsersService us = ctx.getBean("usersService", UsersService.class);
   
    Users user = (Users) session.getAttribute("userSession");
    if (user == null){
      response.sendRedirect("Login.jsp");
    }
    if (!user.getEnabled()) {
      response.sendRedirect("Login.jsp");
    }
    if (!"root".equals(user.getId())) {
      response.sendRedirect("Login.jsp");
    }

    String userId = request.getParameter("disable");
    Users userToDisable = us.findById(userId);
    userToDisable.setEnabled(false);
    us.save(userToDisable.getId(), userToDisable);

    response.sendRedirect("AdminDashServlet");
  }

  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request, response);
  }

}
TOP

Related Classes of com.nevernote.admin.DisableUserServlet

TOP
Copyright © 2018 www.massapi.com. 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.