<?php $form = new Form_Handler_User(!$user->exists() || !empty($_POST['password']) ? true : false); $form->validate(); $errors = $form->errors(); if ($errors) { $pm->setVariable('errors', $errors); $pm->setVariable('user', $form->input()); } else { $user->setArray($_POST, false); $user['password'] = $_POST['password']; $user->save(); if (defined('TYPEF_HOST')) { $sites = Model_User_Site::ForUserId($user['userid']); $sites->deleteQuery(); if (!empty($_POST['admin_siteid'])) { foreach ($_POST['admin_siteid'] as $siteid) { $site = Model_User_Site::Create(); $site['userid'] = $user['userid']; $site['siteid'] = $siteid; $site->save(); } } } Typeframe::Redirect('User saved.', Typeframe::CurrentPage()->applicationUri()); }
public function testUserFormHandler() { /** Assertions: * Existing email passes validation * Unset email fails validation * Matching passwords pass validation * Mismatched passwords fail validation */ $form = new Form_Handler_User(false); $input = array('username' => 'test', 'email' => '*****@*****.**'); $result = $form->validate($input); $this->assertTrue($result, "Validation of existing email requirement failed: " . $this->getErrorMessages($form)); $input = array('username' => 'test'); $result = $form->validate($input); $this->assertFalse($result, "Validation of unset email requirement failed"); $form = new Form_Handler_User(true); $input = array('email' => '*****@*****.**', 'password' => 'testpass', 'password2' => 'testpass'); $result = $form->validate($input); $this->assertTrue($result, "Validation of matching passwords failed: " . $this->getErrorMessages($form)); $input = array('email' => '*****@*****.**', 'password' => 'testpass', 'password2' => 'notright'); $result = $form->validate($input); $this->assertFalse($result, "Validation of mismatched passwords failed"); }