001    package com.khubla.pragmatach.plugin.adminapp;
002    
003    import com.khubla.pragmatach.framework.annotation.Controller;
004    import com.khubla.pragmatach.framework.annotation.Route;
005    import com.khubla.pragmatach.framework.api.PragmatachException;
006    import com.khubla.pragmatach.framework.api.Response;
007    import com.khubla.pragmatach.plugin.freemarker.FreemarkerController;
008    
009    /**
010     * @author tome
011     */
012    @Controller(name = "pragmatachBaseAdminController")
013    public class BaseAdminController extends FreemarkerController {
014       /**
015        * the cookie names
016        */
017       public static final String USERID = "adminUserId";
018       public static final String PASSWORD = "adminPassword";
019    
020       /**
021        * check if user is logged in
022        */
023       public boolean isLoggedIn() {
024          /*
025           * get the user controller
026           */
027          final AdminUserController adminUserController = this.getSessionScopedController(AdminUserController.class);
028          /*
029           * check
030           */
031          if (null != adminUserController.getUsername()) {
032             return true;
033          }
034          return false;
035       }
036    
037       /**
038        * log out
039        */
040       @Route(uri = "pragmatach/admin/logout")
041       public Response logout() throws PragmatachException {
042          try {
043             /*
044              * get the user controller
045              */
046             final AdminUserController adminUserController = this.getSessionScopedController(AdminUserController.class);
047             /*
048              * remove the login session state
049              */
050             adminUserController.setUsername(null);
051             /*
052              * remove the cookies
053              */
054             getRequest().getCookies().removeCookie(BaseAdminController.USERID);
055             getRequest().getCookies().removeCookie(BaseAdminController.PASSWORD);
056             /*
057              * to login screen
058              */
059             return super.forward("/pragmatach/admin/");
060          } catch (final Exception e) {
061             throw new PragmatachException("Exception in logout", e);
062          }
063       }
064    }