/** * Returns an array of the user and token rows for the given token string, or throws an Exception on failure * * @param string $token * @return array * @throws \Dewdrop\Exception */ protected function getUserAndTokenRows($token) { do { if (null === $token) { break; } $tokenTable = new UserPasswordChangeTokensTableGateway(); $tokenRow = $tokenTable->fetchRow($tokenTable->select()->from($tokenTable->getTableName())->where('token = ?', $token)->where('NOT used')); if (null === $tokenRow) { break; } $usersTable = new UsersTableGateway(); $userRow = $usersTable->find($tokenRow->get('user_id')); return ['token' => $tokenRow, 'user' => $userRow]; } while (false); throw new Exception('Invalid token'); }
/** * Create any resources that need to be accessible both for processing * and rendering. * * @return void */ public function init() { $this->model = Pimple::getResource('users-gateway'); $this->fields = new Fields(); $this->row = $this->model->find($this->request->getQuery('user_id')); $this->fields->add('password')->setLabel('Password')->setEditable(true)->add('confirm_password')->setLabel('Confirm Password')->setEditable(true); $this->inputFilter = new InputFilter(); $password = new Input('password'); $this->inputFilter->add($password); $password->setRequired(true)->getValidatorChain()->attach(new StringLength(array('min' => 6))); $confirm = new Input('confirm_password'); $this->inputFilter->add($confirm); $validator = new Callback(array('callback' => function ($value) { return $value === $this->request->getPost('password'); })); $validator->setMessage('Passwords do not match.'); $confirm->setRequired(true)->getValidatorChain()->attach($validator); }