$certId = (int) $_POST['certId']; $cert = $scert->getCert($certId); if ($cert === null) { $tplVars['error'] = T_('Certificate not found.'); } else { if ($cert->uId != $currentUser->getId()) { $tplVars['error'] = T_('The certificate does not belong to you.'); } else { if (false === $scert->delete($certId)) { $tplVars['error'] = T_('Failed to delete SSL client certificate.'); } else { $tplVars['msg'] = T_('SSL client certificate deleted.'); } } } } } //Token Init $_SESSION['token'] = md5(uniqid(rand(), true)); $_SESSION['token_stamp'] = time(); $templatename = 'editprofile.tpl.php'; $tplVars['formaction'] = createURL('profile', $user); $tplVars['token'] = $_SESSION['token']; $tplVars['sslClientCerts'] = $scert->getUserCerts($currentUser->getId()); $tplVars['currentCert'] = null; if ($scert->hasValidCert()) { $tplVars['currentCert'] = SemanticScuttle_Model_User_SslClientCert::fromCurrentCert(); } } $tplVars['objectUser'] = $userinfo; $templateservice->loadTemplate($templatename, $tplVars);
/** * Fetches all registered certificates for the user from the database * and returns it. * * @return array Array with all certificates for the user. Empty if * there are none, SemanticScuttle_Model_User_SslClientCert * objects otherwise. */ public function getUserCerts($uId) { $query = 'SELECT * FROM ' . $this->getTableName() . ' WHERE uId = ' . (int) $uId . ' ORDER BY sslSerial DESC'; if (!($dbresult = $this->db->sql_query($query))) { message_die(GENERAL_ERROR, 'Could not load SSL client certificates', '', __LINE__, __FILE__, $query, $this->db); return array(); } $certs = array(); while ($row = $this->db->sql_fetchrow($dbresult)) { $certs[] = SemanticScuttle_Model_User_SslClientCert::fromDb($row); } $this->db->sql_freeresult($dbresult); return $certs; }