/** * 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'); }
/** * Look in the DB for a password change token matching the current request. * * @param string $token * @return \Dewdrop\Db\Row|null */ private function findToken($token) { $tokenTable = new UserPasswordChangeTokensTableGateway(); return $tokenTable->fetchRow($tokenTable->select()->from($tokenTable->getTableName())->where('token = ?', $token)->where('used')); }