Fixed minor things and added missing file
[vanilla-miry.git] / library / People / People.Control.SignInForm.php
blobc42482c545af8e4e61bee642fd04f03abc372af0
1 <?php
2 /**
3 * The SignInForm control is used to validate a user's credentials and create a session.
5 * Copyright 2003 Mark O'Sullivan
6 * This file is part of Lussumo's Software Library.
7 * Lussumo's Software Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
8 * Lussumo's Software Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9 * You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
10 * The latest source code is available at www.lussumo.com
11 * Contact Mark O'Sullivan at mark [at] lussumo [dot] com
13 * @author Mark O'Sullivan
14 * @copyright 2003 Mark O'Sullivan
15 * @license http://lussumo.com/community/gpl.txt GPL 2
16 * @package People
17 * @version 1.1.8
21 /**
22 * The SignInForm control is used to validate a user's credentials and create a session.
23 * @package People
25 class SignInForm extends PostBackControl {
26 var $Username;
27 var $Password;
28 var $RememberMe;
29 var $FormName;
30 var $ApplicantCount; // The number of applicants currently awaiting approval
31 var $ReturnUrl;
33 function SignInForm(&$Context, $FormName) {
34 $this->Name = 'SignInForm';
35 $this->ValidActions = array('SignIn');
36 $this->Constructor($Context);
38 if ($this->PostBackAction == '') $this->IsPostBack = 1;
40 if ($this->IsPostBack) {
41 $this->FormName = $FormName;
42 $this->ReturnUrl = urldecode(ForceIncomingString('ReturnUrl', ''));
43 if ($this->ReturnUrl != '') $this->PostBackParams->Add('ReturnUrl', $this->ReturnUrl);
44 $this->Username = ForceIncomingString('Username', '');
45 $this->Password = ForceIncomingString('Password', '');
46 $this->RememberMe = ForceIncomingBool('RememberMe', 0);
48 // Set up the page
49 global $Banner, $Foot;
50 $Banner->Properties['CssClass'] = 'SignIn';
51 $Foot->CssClass = 'SignIn';
52 $this->Context->PageTitle = $this->Context->GetDefinition('SignIn');
54 if ($this->PostBackAction == 'SignIn') {
56 $UserManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'UserManager');
58 // Check for an already active session
59 if ($this->Context->Session->UserID != 0) {
60 $this->PostBackValidated = 1;
61 } else {
62 // Attempt to create a new session for the user
63 if ($UserManager->ValidateUserCredentials($this->Username, $this->Password, $this->RememberMe)) {
64 $this->PostBackValidated = 1;
65 //Automatically redirect if this user isn't a user administrator or there aren't any new applicants
66 $AutoRedirect = 1;
67 if ($this->Context->Session->User->Permission('PERMISSION_APPROVE_APPLICANTS')) {
68 $this->ApplicantCount = $UserManager->GetApplicantCount();
69 if ($this->ApplicantCount > 0) $AutoRedirect = 0;
71 if ($this->ReturnUrl == '') {
72 $this->ReturnUrl = $this->Context->Configuration['FORWARD_VALIDATED_USER_URL'];
73 } else {
74 $this->ReturnUrl = str_replace('&amp;', '&', $this->ReturnUrl);
76 if ($AutoRedirect && $this->ReturnUrl != '') {
77 //@todo: Should the the process die here?
78 Redirect($this->ReturnUrl, '302', '', 0);
83 $this->Context->BodyAttributes = " onload=\"Focus('txtUsername');\"";
85 $this->CallDelegate('Constructor');
88 function Render_ValidPostBack() {
89 $this->CallDelegate('PreValidPostBackRender');
90 include(ThemeFilePath($this->Context->Configuration, 'people_signin_form_validpostback.php'));
91 $this->CallDelegate('PostValidPostBackRender');
94 function Render_NoPostBack() {
95 $this->Username = FormatStringForDisplay($this->Username, 1);
96 $this->PostBackParams->Add('PostBackAction', 'SignIn');
97 $this->PostBackParams->Add('ReturnUrl', $this->ReturnUrl);
99 $this->CallDelegate('PreNoPostBackRender');
100 include(ThemeFilePath($this->Context->Configuration, 'people_signin_form_nopostback.php'));
101 $this->CallDelegate('PostNoPostBackRender');
104 // Because this form switches the user from having no session to having a session,
105 // I need to override the default render method of the PostBackForm control so
106 // that it doesn't check for a PostBackKey
107 function Render() {
108 if ($this->IsPostBack) {
109 $this->CallDelegate('PreRender');
110 // Call different render methods based on the PostBack state.
111 if ($this->PostBackValidated) {
112 $this->Render_ValidPostBack();
113 } else {
114 $this->Render_NoPostBack();
116 $this->CallDelegate('PostRender');