fields['key'] = new Pluf_Form_Field_Varchar( array('required' => true, 'label' => __('Your verification key'), 'initial' => '', 'widget_attrs' => array( 'size' => 50, ), )); } function clean_key() { self::validateKey($this->cleaned_data['key']); return $this->cleaned_data['key']; } /** * Validate the key. * * Throw a Pluf_Form_Invalid exception if the key is not valid. * * @param string Key * @return array array($new_email, $user_id, time(), [primary|secondary]) */ public static function validateKey($key) { $hash = substr($key, 0, 2); $encrypted = substr($key, 2); if ($hash != substr(md5(Pluf::f('secret_key').$encrypted), 0, 2)) { throw new Pluf_Form_Invalid(__('The validation key is not valid. Please copy/paste it from your confirmation email.')); } $cr = new Pluf_Crypt(md5(Pluf::f('secret_key'))); return explode(':', $cr->decrypt($encrypted), 4); } /** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit=true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } return Pluf::f('url_base').Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailDo', array($this->cleaned_data['key'])); } }