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.annotation.Route.HttpMethod; 006 import com.khubla.pragmatach.framework.annotation.View; 007 import com.khubla.pragmatach.framework.api.PragmatachException; 008 import com.khubla.pragmatach.framework.api.Response; 009 010 /** 011 * @author tome 012 */ 013 @Controller(name = "pragmatachAdminLoginController") 014 @View(view = "pragmatach/admin/login.html") 015 public class AdminLoginController extends BaseAdminController { 016 /** 017 * username 018 */ 019 private String username; 020 /** 021 * password 022 */ 023 private String password; 024 025 @Route(uri = "/pragmatach/admin/login/doLogin", method = HttpMethod.post) 026 public Response doLogin() throws PragmatachException { 027 /* 028 * valid u/p? 029 */ 030 if ((null != username) && (username.length() > 0) && (null != password) && (password.length() > 0)) { 031 /* 032 * check that it matches 033 */ 034 if ((username.compareTo(getConfigurationParameter("pragmatach.adminapp.username")) == 0) && (password.compareTo(getConfigurationParameter("pragmatach.adminapp.password")) == 0)) { 035 /* 036 * set session state 037 */ 038 this.getSessionScopedController(AdminUserController.class).setUsername(username); 039 /* 040 * set cookie 041 */ 042 getRequest().getCookies().setEncryptedCookie(BaseAdminController.USERID, username); 043 getRequest().getCookies().setEncryptedCookie(BaseAdminController.PASSWORD, password); 044 /* 045 * go to main page 046 */ 047 return super.forward("/pragmatach/admin/"); 048 } 049 } 050 return super.forward("/pragmatach/admin/login"); 051 } 052 053 public String getPassword() { 054 return password; 055 } 056 057 public String getUsername() { 058 return username; 059 } 060 061 @Route(uri = "/pragmatach/admin/login") 062 public Response render() throws PragmatachException { 063 return super.render(); 064 } 065 066 public void setPassword(String password) { 067 this.password = password; 068 } 069 070 public void setUsername(String username) { 071 this.username = username; 072 } 073 }