1 package org.apache.turbine.modules.actions; 2 3 56 57 import org.apache.turbine.Turbine; 58 import org.apache.turbine.RunData; 59 import org.apache.turbine.modules.Action; 60 import org.apache.fulcrum.security.TurbineSecurity; 61 import org.apache.fulcrum.security.entity.User; 62 import org.apache.fulcrum.security.util.DataBackendException; 63 import org.apache.fulcrum.security.util.TurbineSecurityException; 64 import org.apache.commons.logging.LogFactory; 65 import org.apache.commons.logging.Log; 66 67 75 public class LoginUser 76 extends Action 77 { 78 private static final Log log = LogFactory.getLog( LoginUser.class ); 79 80 94 public void doPerform( RunData data ) 95 throws Exception 96 { 97 if ( data.getUserFromSession() != null ) 102 { 103 return; 104 } 105 106 String username = data.getParameters().getString( "username", "" ); 107 String password = data.getParameters().getString( "password", "" ); 108 109 User user = null; 110 try 111 { 112 user = TurbineSecurity.getAuthenticatedUser( username, password ); 114 115 data.setUser(user); 117 118 user.setHasLoggedIn(Boolean.TRUE); 120 121 user.updateLastLogin(); 123 124 data.save(); 129 130 } 137 catch ( TurbineSecurityException e ) 138 { 139 if(e instanceof DataBackendException) 140 { 141 log.error(e); 142 } 143 144 data.setMessage(Turbine.getConfiguration().getString( 145 Turbine.LOGIN_ERROR)); 146 147 data.setUser (TurbineSecurity.getAnonymousUser()); 149 150 data.setTarget(Turbine.getConfiguration().getString( 151 Turbine.TEMPLATE_LOGIN)); 152 } 153 } 154 } 155 | Popular Tags |