public static function invite_users($users, $is_network_admin)
 {
     $errors = array();
     foreach ($users as &$user) {
         if (!ClefUtils::user_has_clef($user)) {
             $invite = new ClefInvite($user, $is_network_admin);
             $invite->persist();
             $success = $invite->send_email();
             if (!$success) {
                 $errors[] = $user->user_email;
             }
         }
     }
     if (count($errors) > 0) {
         if (count($errors) == count($filtered_users)) {
             $message = __("there was an error sending the invite email to all users. Copy and paste the preview email to your users and they'll be walked through a tutorial to connect with Clef", 'wpclef');
         } else {
             $message = __("unable to send emails to the following users: ", 'wpclef');
             $message .= join(", ", $errors);
             $message .= __(". Copy and paste the preview email to your users and they'll be walked through a tutorial to connect with Clef", 'wpclef');
         }
         throw new Exception($message);
     } else {
         return true;
     }
 }
 public function ajax_disconnect_clef_account()
 {
     $user = wp_get_current_user();
     $passwords_disabled = $this->settings->passwords_are_disabled_for_user($user);
     if (current_user_can('manage_options') && $passwords_disabled) {
         return new WP_Error('passwords_disabled', __("your passwords are currently disabled. <br/> If you disconnect your Clef account, you won't be able to log in. Please enable passwords for yourself before disconnecting your Clef account", 'clef'));
     }
     ClefUtils::dissociate_clef_id();
     return array("success" => true);
 }
Пример #3
0
 function send_email($from_email)
 {
     if (empty($this->user_email)) {
         return true;
     }
     $subject = '[' . $this->site_name . '] ' . __('Set up Clef for your account', "wpclef");
     $template = 'invite_email.tpl';
     $vars = array("invite_link" => $this->get_link(), "site_name" => $this->site_name);
     return ClefUtils::send_email($this->user_email, $subject, $template, $vars);
 }
 function send_email($from_email)
 {
     if (empty($this->user_email)) {
         return true;
     }
     $invite_link = $this->get_link();
     $subject = '[' . $this->site_name . '] ' . __('Set up Clef for your account', "clef");
     $message = ClefUtils::render_template('invite_email.tpl', array("invite_link" => $this->get_link(), "site_name" => $this->site_name), false);
     $headers = "From: WordPress <" . $from_email . "> \r\n";
     add_filter('wp_mail_content_type', array('ClefUtils', 'set_html_content_type'));
     $sent = wp_mail($this->user_email, $subject, $message, $headers);
     remove_filter('wp_mail_content_type', array('ClefUtils', 'set_html_content_type'));
     return $sent;
 }
 public static function validate(array $input)
 {
     $input = parent::validate($input);
     // sanitize inputs as text fields
     foreach ($input as $key => &$value) {
         $input[$key] = sanitize_text_field($value);
     }
     $attrs_to_escape = array('clef_settings_app_id', 'clef_settings_app_secret', 'customization_message', 'customization_logo');
     foreach ($attrs_to_escape as $attr) {
         if (isset($input[$attr])) {
             $input[$attr] = esc_attr($input[$attr]);
         }
     }
     if (isset($input['clef_password_settings_force']) && $input['clef_password_settings_force'] == "1") {
         if (!ClefUtils::user_has_clef()) {
             unset($input['clef_password_settings_force']);
             $url = admin_url('admin.php?page=' . ClefAdmin::CONNECT_CLEF_PAGE);
             add_settings_error(CLEF_OPTIONS_NAME, 'clef_password_settings_force', sprintf(__("Please link your Clef account before you fully disable passwords. You can do this <a href='%s'>here</a>", "clef"), $url), "error");
         }
     }
     return $input;
 }
 public static function verify_state()
 {
     $state = ClefUtils::isset_GET('state') ? ClefUtils::isset_GET('state') : ClefUtils::isset_POST('state');
     $session = ClefSession::start();
     if ($session->get('state') && $state && $session->get('state') == $state) {
         $session->set('state', null);
         return true;
     } else {
         throw new ClefStateException('The state parameter is not verified. Please refresh your page and try again, you may be experiencing a CSRF attempt');
     }
 }
Пример #7
0
 public function ajax_connect_clef_account_with_clef_id()
 {
     if (!ClefUtils::isset_POST('identifier')) {
         return new WP_Error("invalid_clef_id", __("invalid Clef ID", "wpclef"));
     }
     $result = ClefUtils::associate_clef_id($_POST["identifier"]);
     if (is_wp_error($result)) {
         return $result;
     } else {
         $session = ClefSession::start();
         $session->set('logged_in_at', time());
         return array("success" => true);
     }
 }
?>
</h3>
            <p><?php 
_e("If you lose your device, don't fret! Just visit <a href='https://getclef.com/lost'>getclef.com/lost</a>, deactivate with your PIN, and reactivate on a new device.", "wpclef");
?>
</p>
            <div class="button button-primary button-hero next"><?php 
_e("Got it!", "wpclef");
?>
</div>
        </div>

        <?php 
if (is_admin()) {
    ?>
        <?php 
    echo ClefUtils::render_template('admin/waltz-prompt.tpl', array("next_href" => '#', "next_text" => __("Go to Clef settings", "wpclef"), "class" => "setup"));
    ?>

        <?php 
    echo ClefUtils::render_template('admin/waltz-prompt.tpl', array("next_href" => admin_url(), "next_text" => __("Go to dashboard", "wpclef"), "class" => "connect"));
    ?>

        <?php 
}
?>

    </div>
</div>

Пример #9
0
 public static function send_email($email, $subject, $template, $vars)
 {
     // Get the site domain and get rid of www.
     $sitename = strtolower($_SERVER['SERVER_NAME']);
     if (substr($sitename, 0, 4) == 'www.') {
         $sitename = substr($sitename, 4);
     }
     $from_email = 'wordpress@' . $sitename;
     $message = ClefUtils::render_template($template, $vars, false);
     $headers = "From: WordPress <" . $from_email . "> \r\n";
     add_filter('wp_mail_content_type', array('ClefUtils', 'set_html_content_type'));
     $sent = wp_mail($email, $subject, $message, $headers);
     remove_filter('wp_mail_content_type', array('ClefUtils', 'set_html_content_type'));
     return $sent;
 }
Пример #10
0
 public static function verify_state()
 {
     $request_state = ClefUtils::isset_GET('state') ? ClefUtils::isset_GET('state') : ClefUtils::isset_POST('state');
     $correct_state = ClefUtils::get_state();
     if ($request_state && $correct_state && $correct_state == $request_state) {
         ClefUtils::initialize_state(true);
         return true;
     } else {
         throw new ClefStateException('The state parameter is not verified. This may be due to this page being cached by another WordPress plugin. Please refresh your page and try again');
     }
 }
Пример #11
0
 public function initialize_state()
 {
     ClefUtils::initialize_state();
 }
 public function initialize_state_on_login_page()
 {
     if (in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) {
         ClefUtils::initialize_state();
     }
 }
 /**
  * Returns whether passwords are disabled for a specific user based on
  * user roles.
  *
  * @param WP_User $user
  * @return bool
  */
 public function passwords_are_disabled_for_user($user)
 {
     if (!$this->is_configured()) {
         return false;
     }
     if ($this->get('clef_password_settings_force')) {
         return true;
     }
     if ($this->get('clef_password_settings_disable_passwords') && ClefUtils::user_has_clef($user)) {
         return true;
     }
     $disable_certain_passwords = $this->get('clef_password_settings_disable_certain_passwords');
     if ($disable_certain_passwords && $disable_certain_passwords != "") {
         $max_role = strtolower($disable_certain_passwords);
         if (ClefUtils::user_fulfills_role($user, $max_role)) {
             return true;
         }
     }
     $potential_custom_user_roles = (array) $user->roles;
     foreach ($potential_custom_user_roles as $role) {
         if ($this->get("clef_password_settings_disable_passwords_custom_role_{$role}")) {
             return true;
         }
     }
     return false;
 }
Пример #14
0
 public function register_scripts()
 {
     $ident = ClefUtils::register_script('badge');
     wp_enqueue_script($ident);
 }
Пример #15
0
 public function connect_clef_account_on_login($user)
 {
     if (ClefUtils::isset_POST('clef_id') && $user && !is_wp_error($user)) {
         ClefUtils::associate_clef_id(ClefUtils::isset_POST('clef_id'), $user->ID);
         $session = ClefSession::start();
         $session->set('clef_account_connected_on_login', true);
         $session->set('logged_in_at', time());
     }
     return $user;
 }
 public function send_override_link($user)
 {
     $site_name = get_bloginfo('name');
     $subject = '[' . $site_name . '] ' . __('Clef override URL - keep safe', 'wpclef');
     return ClefUtils::send_email($user->user_email, $subject, 'override_link_email.tpl', array("site_url" => get_site_url(), "override_link" => $this->get_override_link()));
 }
Пример #17
0
 public function load_base_styles()
 {
     $ident = ClefUtils::register_style('main');
     wp_enqueue_style($ident);
 }
Пример #18
0
:</b></span>
                <div class="support-html-container hide-if-js">
                    <h4><?php 
_e('Copy this HTML where you want to add the badge', 'wpclef');
?>
</h4>
                    <textarea class="ajax-ignore"><?php 
echo esc_textarea(ClefUtils::render_template('badge.tpl', array("pretty" => true)));
?>
</textarea>
                    <h4><?php 
_e('Copy this HTML where you want to add the link', 'wpclef');
?>
</h4>
                    <textarea class="ajax-ignore"><?php 
echo esc_textarea(ClefUtils::render_template('badge.tpl', array("pretty" => false)));
?>
</textarea>
                </div>
            </div>
            <div class="preview-container hide-if-no-js">
               <div class="ftr-preview">
                   <h4><?php 
_e("Preview of your support", "wpclef");
?>
</h4>
                   <a href="https://bit.ly/wordpress-login-clef" class="clef-badge pretty" ><?php 
_e("WordPress Login Protected by Clef", "wpclef");
?>
</a>
                   <span class="hide-if-js">
Пример #19
0
<div class="clef-button-to-render" data-app-id='<?php 
echo $app_id;
?>
'
    data-type="<?php 
echo $type;
?>
"
    <?php 
if ($embed) {
    ?>
 data-embed="true" <?php 
}
?>
    data-state="<?php 
echo ClefUtils::get_state();
?>
"
    data-redirect-url='<?php 
echo $redirect_url;
?>
'
    <?php 
if (isset($custom['logo'])) {
    ?>
data-custom-logo="<?php 
    echo $custom['logo'];
    ?>
"<?php 
}
?>