Framework  3.9
password_field_renderer.inc
Go to the documentation of this file.
1 <?php
6 /**************************************************************
7 
8  Copyright (c) 2007-2010 Sonjara, Inc
9 
10  Permission is hereby granted, free of charge, to any person
11  obtaining a copy of this software and associated documentation
12  files (the "Software"), to deal in the Software without
13  restriction, including without limitation the rights to use,
14  copy, modify, merge, publish, distribute, sublicense, and/or sell
15  copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following
17  conditions:
18 
19  The above copyright notice and this permission notice shall be
20  included in all copies or substantial portions of the Software.
21 
22  Except as contained in this notice, the name(s) of the above
23  copyright holders shall not be used in advertising or otherwise
24  to promote the sale, use or other dealings in this Software
25  without prior written authorization.
26 
27  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
29  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
32  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
34  OTHER DEALINGS IN THE SOFTWARE.
35 
36 *****************************************************************/
37 
38 require_once realpath(dirname(__FILE__))."/../field_renderers.inc";
39 
47 {
48  var $encryptor; //< Custom encryptor
49  var $forceReset = false;
50  var $numeric = false; //< numeric code (PIN)
51  var $allowEmpty = false;
52 
54  {
55  $this->FieldRenderer($parent);
56 
57  }
58 
59  function addValidatorsToForm($field, $required = false)
60  {
61  $label = str_replace("*", "", $this->parent->prettifyFieldName($field));
62  $this->parent->match($field, $label, "{$field}_confirm", "Confirmation");
63  $this->parent->password($field, $label);
64  }
65 
66  function renderScript($field)
67  {
68  if (!$this->_includedPasswordScript)
69  {
70 ?>
71 <script type='text/javascript'>
72 <!--
73 function <?echo $this->parent->id?>_<?echo $field?>_showPassword()
74 {
75  var link = document.getElementById("<?echo $this->parent->id?>_<?echo $field?>_link");
76  var block = document.getElementById("<?echo $this->parent->id?>_<?echo $field?>_block");
77  document.id("<?echo $this->parent->id ?>_<?echo $field?>_reset_password").value = 1;
78 
79  link.style.display = "none";
80  block.style.display = "block";
81  ModalDialog.recenterActiveDialog();
82 }
83 //-->
84 </script>
85 <? $this->_includedPasswordScript = true;
86  }
87  }
88 
89  function renderPasswordBlock($field, $display = "block")
90  {
91  $enter = $this->parent->passwordEnterLabel;
92  $confirm = $this->parent->passwordConfirmLabel;
93  $size = $this->numeric ? "6" : "20";
94  $onKeyPress = $this->numeric ? " onkeypress='return maskInput(event, $allowneg);'" : ""
95 ?>
96  <table border="0" cellspacing="0" cellpadding="0" id="<?echo $this->parent->id ?>_<?echo $field?>_block" style="padding: 0px; display: <?echo $display ?>">
97  <tr>
98  <td style="vertical-align: top; text-align: left"><?echo $enter?>&nbsp;</td>
99  <td style="padding-bottom: 2px"><input type="password" autocomplete="new-password" name="<?echo $field?>" id="<?echo $this->parent->id?>_<?echo $field?>" size="<?echo $size?>"<?echo $onKeyPress?> value=""/></td>
100  </tr>
101  <tr>
102  <td style="vertical-align: top; text-align: left"><?echo $confirm?>&nbsp;</td>
103  <td><input type="password" name="<?echo $field?>_confirm" id="<?echo $this->parent->id?>_<?echo $field?>_confirm" size="<?echo $size?>"<?echo $onKeyPress?> value=""/></td>
104  </tr>
105  </table>
106 <?
107  }
108 
109  function renderField($field)
110  {
111  $pk = $this->parent->data->getPrimaryKey();
112 
113  $this->_startField($field);
114 
115  if (($this->parent->data->get($pk) && !$this->forceReset) || $this->allowEmpty)
116  {
117  $verb = ($this->allowEmpty && !$this->parent->data->get($pk)) ? "set" : "reset";
118 
119  echo "<a id='{$this->parent->id}_{$field}_link' href='#' onclick='{$this->parent->id}_{$field}_showPassword();return false;'>Click to {$verb} password</a>\n";
120  $this->renderPasswordBlock($field, "none");
121  echo "<input type='hidden' id='{$this->parent->id}_{$field}_reset_password' name='{$this->parent->id}_{$field}_reset_password' value=''/>\n";
122  }
123  else
124  {
125  $this->renderPasswordBlock($field);
126  echo "<input type='hidden' id='{$this->parent->id}_{$field}_reset_password' name='{$this->parent->id}_{$field}_reset_password' value='1'/>\n";
127  }
128 
129  $this->_endField($field);
130 
131  }
132 
133  function renderReadOnly($field)
134  {
135  $this->_startField($field);
136 
137  echo "<i>Password is hidden</i>\n";
138 
139  $this->_endField($field);
140  }
141 
142  function preProcess($field = "")
143  {
144  $pk = $this->parent->data->getPrimaryKey();
145 
146  if (!$this->parent->data->$pk || $_POST["{$this->parent->id}_{$field}_reset_password"])
147  {
148  $password = $_POST[$field];
149  }
150  else
151  {
152  if ($this->parent->data->getFilter() == null)
153  {
154  $this->parent->data->setFilter(new ExclusionFilter());
155  }
156 
157  $filter = $this->parent->data->getFilter();
158 
159  if ($filter->type == "ExclusionFilter")
160  {
161  $filter->add($field);
162  }
163  else
164  {
165  $filter->remove($field);
166  }
167  }
168 
169  if ($this->allowEmpty && !$password)
170  {
171  $this->parent->data->set($field, "");
172  }
173  else
174  {
175  $encryptor = $this->parent->passwordEncryptor;
176 
177  trace("Encryptor: $encryptor", 3);
178 
179  if ($encryptor)
180  {
181  $password = $this->parent->data->$encryptor($password);
182  }
183  else
184  {
185  $password = crypt($password);
186  }
187 
188  $this->parent->data->set($field, $password);
189  }
190  }
191 }
192 ?>
Used to place a filter on the contents of a DataItem-derived object.
FieldRenderer is the abstract base class for all FieldRenderers.
_startField($field, $styles="")
Internal method to generate the starting HTML for the field (including the label)
_endField($field)
Internal method to generate the closing HTML for the field.
FieldRenderer($parent)
Constructor.
Field renderer for password data fields.
addValidatorsToForm($field, $required=false)
This method is called by the AutoForm to add any default input validators that are required by the Fi...
renderPasswordBlock($field, $display="block")
renderScript($field)
FieldRenderers can override this method to provide any Javascript that their control requires for an ...
preProcess($field="")
FieldRenderers can override this method to provide behavior that occurs prior to the saving of the pa...
renderField($field)
FieldRenderers must override this method to provide the HTML implementation of the control used to ed...
$forceReset
true if user logged in with a temporary token
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010