/** * * * @param SettingsController $sender * @param array $Args */ protected function settings_addEdit($sender, $Args) { $sender->addJsFile('jsconnect-settings.js', 'plugins/jsconnect'); $client_id = $sender->Request->get('client_id'); Gdn::locale()->setTranslation('AuthenticationKey', 'Client ID'); Gdn::locale()->setTranslation('AssociationSecret', 'Secret'); Gdn::locale()->setTranslation('AuthenticateUrl', 'Authentication Url'); /* @var Gdn_Form $form */ $form = $sender->Form; $model = new Gdn_AuthenticationProviderModel(); $form->setModel($model); $generate = false; if ($form->authenticatedPostBack()) { if ($form->getFormValue('Generate') || $sender->Request->post('Generate')) { $generate = true; $key = mt_rand(); $secret = md5(mt_rand()); $sender->setFormSaved(false); } else { $form->validateRule('AuthenticationKey', 'ValidateRequired'); $form->validateRule('AuthenticationKey', 'regex:`^[a-z0-9_-]+$`i', T('The client id must contain only letters, numbers and dashes.')); $form->validateRule('AssociationSecret', 'ValidateRequired'); $form->validateRule('AuthenticateUrl', 'ValidateRequired'); $form->setFormValue('AuthenticationSchemeAlias', 'jsconnect'); if ($form->save(['ID' => $client_id])) { $sender->RedirectUrl = url('/settings/jsconnect'); } } } else { if ($client_id) { $provider = self::getProvider($client_id); touchValue('Trusted', $provider, 1); } else { $provider = array(); } $form->setData($provider); } // Set up the form controls for editing the connection. $hashTypes = hash_algos(); $hashTypes = array_combine($hashTypes, $hashTypes); $controls = ['AuthenticationKey' => ['LabelCode' => 'Client ID', 'Description' => t('The client ID uniquely identifies the site.', 'The client ID uniquely identifies the site. You can generate a new ID with the button at the bottom of this page.')], 'AssociationSecret' => ['LabelCode' => 'Secret', 'Description' => t('The secret secures the sign in process.', 'The secret secures the sign in process. Do <b>NOT</b> give the secret out to anyone.')], 'Name' => ['LabelCode' => 'Site Name', 'Description' => t('Enter a short name for the site.', 'Enter a short name for the site. This is displayed on the signin buttons.')], 'AuthenticateUrl' => ['LabelCode' => 'Authentication URL', 'Description' => t('The location of the JSONP formatted authentication data.')], 'SignInUrl' => ['LabelCode' => 'Sign In URL', 'Description' => t('The url that users use to sign in.') . ' ' . t('Use {target} to specify a redirect.')], 'RegisterUrl' => ['LabelCode' => 'Registration URL', 'Description' => t('The url that users use to register for a new account.')], 'SignOutUrl' => ['LabelCode' => 'Sign Out URL', 'Description' => t('The url that users use to sign out of your site.')], 'Trusted' => ['Control' => 'toggle', 'LabelCode' => 'This is trusted connection and can sync roles & permissions.'], 'IsDefault' => ['Control' => 'toggle', 'LabelCode' => 'Make this connection your default signin method.'], 'Advanced' => ['Control' => 'callback', 'Callback' => function ($form) { return subheading(t('Advanced')); }], 'HashType' => ['Control' => 'dropdown', 'LabelCode' => 'Hash Algorithm', 'Items' => $hashTypes, 'Description' => T('Choose md5 if you\'re not sure what to choose.', "You can select a custom hash algorithm to sign your requests. The hash algorithm must also be used in your client library. Choose md5 if you're not sure what to choose."), 'Options' => ['Default' => 'md5']], 'TestMode' => ['Control' => 'toggle', 'LabelCode' => 'This connection is in test-mode.']]; $sender->setData('_Controls', $controls); $sender->setData('Title', sprintf(T($client_id ? 'Edit %s' : 'Add %s'), T('Connection'))); // Throw a render event as this plugin so that handlers can call our methods. Gdn::pluginManager()->callEventHandlers($this, __CLASS__, 'addedit', 'render'); if ($generate && $sender->deliveryType() === DELIVERY_TYPE_VIEW) { $sender->setJson('AuthenticationKey', $key); $sender->setJson('AssociationSecret', $secret); $sender->render('Blank', 'Utility', 'Dashboard'); } else { $sender->render('Settings_AddEdit', '', 'plugins/jsconnect'); } }