Beispiel #1
0
    echo Json::encode($answer);
    die;
}
if (!check_bitrix_sessid()) {
    $answer["message"] = Loc::getMessage("main_app_passwords_ajax_error_sess");
    echo Json::encode($answer);
    die;
}
$context = Bitrix\Main\Context::getCurrent();
$request = $context->getRequest();
if ($request->isPost()) {
    $post = $request->getPostList()->toArray();
    $post = Main\Text\Encoding::convertEncodingArray($post, "UTF-8", $context->getCulture()->getCharset());
    if ($post["action"] == "delete" && ($id = intval($post["ID"])) > 0) {
        //deleting the application password
        if (ApplicationPasswordTable::getRow(array("filter" => array("=ID" => $id, "=USER_ID" => $USER->GetID()))) !== null) {
            $result = ApplicationPasswordTable::delete($id);
            if ($result->isSuccess()) {
                $answer["success"] = true;
                $answer["message"] = Loc::getMessage("main_app_passwords_ajax_deleted");
            } else {
                $answer["message"] = implode("<br>", $result->getErrorMessages());
            }
        }
    } elseif ($post["action"] == "add") {
        //adding a new application password
        $appManager = ApplicationManager::getInstance();
        $applications = $appManager->getApplications();
        $password = ApplicationPasswordTable::generatePassword();
        if (isset($applications[$post['APPLICATION_ID']])) {
            $date = new Main\Type\DateTime();