Blame view

framework/security/LoginForm.php 1.2 KB
385d70ca   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  <?php
  /**
   * Abstract base class for a login form
   *
   * This class is used as a base class for the different log-in forms like
   * {@link MemberLoginForm} or {@link OpenIDLoginForm}.
   *
   * @author Markus Lanthaler <markus@silverstripe.com>
   * @package framework
   * @subpackage security
   */
  abstract class LoginForm extends Form {
  	public function __construct($controller, $name, $fields, $actions) {
  		parent::__construct($controller, $name, $fields, $actions);
  		
  		$this->disableSecurityToken();	
  	}
  
  	/**
  	 * Authenticator class to use with this login form
  	 * 
  	 * Set this variable to the authenticator class to use with this login
  	 * form.
  	 * @var string
  	 */
  	protected $authenticator_class;
  
  	/**
  	 * Get the authenticator instance
  	 * 
  	 * @return Authenticator Returns the authenticator instance for this login form.
  	 */
  	public function getAuthenticator() {
  		if(!class_exists($this->authenticator_class) || !is_subclass_of($this->authenticator_class, 'Authenticator')) {
  			user_error("The form uses an invalid authenticator class! '{$this->authenticator_class}'"
  				. " is not a subclass of 'Authenticator'", E_USER_ERROR);
  			return;
  		}
  		
  		return Injector::inst()->get($this->authenticator_class);
  	}
  }