firebase-authentication
/
admin
/
partials
/
config
/
class-mo-firebase-authentication-admin-config.php
class-mo-firebase-authentication-admin-advsettings.php
3 days ago
class-mo-firebase-authentication-admin-config.php
3 days ago
class-mo-firebase-authentication-admin-licensing-plans.php
3 days ago
class-mo-firebase-authentication-admin-loginsettings.php
3 days ago
class-mo-firebase-authentication-admin-config.php
198 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Firebase Authentication Config |
| 4 | * |
| 5 | * @package firebase-authentication |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Initial configuration screen handler |
| 14 | */ |
| 15 | class Mo_Firebase_Authentication_Admin_Config { |
| 16 | |
| 17 | /** |
| 18 | * Display basic configuration |
| 19 | * |
| 20 | * @return void |
| 21 | */ |
| 22 | public static function mo_firebase_authentication_config() { |
| 23 | ?> |
| 24 | <!-- <div id="mo_firebase_authentication_support_layout" class="mo_firebase_authentication_support_layout"> --> |
| 25 | <div class="row"> |
| 26 | <div class="col-md-12" > |
| 27 | <div> |
| 28 | <div class="mo_table_layout" style="padding-top: 0px;"> |
| 29 | <form action="" method="post" id="mo_enable_firebase_auth_form"> |
| 30 | <?php wp_nonce_field( 'mo_firebase_auth_enable_form', 'mo_firebase_auth_enable_field' ); ?> |
| 31 | <!-- <div style="display:inline"><div style="display:inline-block;padding:0px 10px 10px 0px"><strong>Enable Firebase Authentication:</strong></div> --> |
| 32 | <div style="display:inline-block; margin-top: 0"><label class="mo_firebase_auth_switch"> |
| 33 | <input value="1" name="mo_enable_firebase_auth" type="checkbox" id="mo_enable_firebase_auth" <?php echo esc_attr( get_option( 'mo_enable_firebase_auth' ) ) ? 'checked' : ''; ?>> |
| 34 | <span class="mo_firebase_auth_slider round"></span> |
| 35 | <input type="hidden" name="option" value="mo_enable_firebase_auth"> |
| 36 | </label> |
| 37 | </div> |
| 38 | <div style="display:inline"><div style="display:inline-block;padding:0px 10px 10px 0px"><h3>Enable Firebase Authentication</h3></div> |
| 39 | <span style="float: right; font-size: 14px; margin-top: 10px;"> |
| 40 | <a href="https://plugins.miniorange.com/login-into-wordpress-using-firebase-authentication" target="_blank" rel="noopener" class="mo_firebase_setup_guide_style" style="text-decoration: none;"> How to configure?</a></span> |
| 41 | </div> |
| 42 | </form> |
| 43 | <form action="" method="post" id="mo_firebase_auth_form" style="margin-top: 0px;"> |
| 44 | <?php wp_nonce_field( 'mo_firebase_auth_config_form', 'mo_firebase_auth_config_field' ); ?> |
| 45 | <table class="mo_settings_table"> |
| 46 | <tr><td colspan="2"><strong style="padding-left: 0px; ">Allow users to login with :</strong> |
| 47 | </td></tr> |
| 48 | <tr><td> |
| 49 | <input style="margin-left: 5px;"type="radio" name="disable_wordpress_login" id="enable_wordpress_login" |
| 50 | <?php |
| 51 | if ( false === get_option( 'mo_enable_firebase_auth' ) ) { |
| 52 | echo ''; |
| 53 | } else { |
| 54 | echo esc_attr( get_option( 'mo_firebase_auth_disable_wordpress_login' ) ) ? '' : 'checked';} |
| 55 | ?> |
| 56 | value="0"onclick="mo_firebase_auth_hideDiv();">Both Firebase and WordPress |
| 57 | </td><td> |
| 58 | <input type="radio" name="disable_wordpress_login" id="disable_wordpress_login" |
| 59 | <?php |
| 60 | if ( false === get_option( 'mo_enable_firebase_auth' ) ) { |
| 61 | echo ''; |
| 62 | } else { |
| 63 | echo esc_attr( get_option( 'mo_firebase_auth_disable_wordpress_login' ) ) ? 'checked' : '';} |
| 64 | ?> |
| 65 | value="1"onclick="mo_firebase_auth_showDiv();">Only Firebase</td></tr> |
| 66 | <tr><td colspan="2"> |
| 67 | <div style="padding:5px;"></div> |
| 68 | <div style=" |
| 69 | <?php |
| 70 | if ( 1 === (int) get_option( 'mo_firebase_auth_disable_wordpress_login' ) ) { |
| 71 | echo 'display: block'; |
| 72 | } else { |
| 73 | echo 'display: none'; |
| 74 | } |
| 75 | ?> |
| 76 | "id="mo_firebase_auth_enable_admin_wp_login_div"> |
| 77 | <p>Enabling Firebase login will restrict logins with only Firebase credentials and won't allow WP login. <b>Please enable this only after you have successfully tested your configuration</b> as the default WordPress login will stop working. |
| 78 | </p><div style="margin-bottom: 15px;"> |
| 79 | <input type="checkbox" id="mo_firebase_auth_enable_admin_wp_login" name="mo_firebase_auth_enable_admin_wp_login" value="1" |
| 80 | <?php |
| 81 | if ( get_option( 'mo_firebase_auth_enable_admin_wp_login' ) ) { |
| 82 | echo 'checked'; } |
| 83 | ?> |
| 84 | /> Allow Administrators to use WordPress login<div class="mo-firebase-auth-tooltip"><i class="fa fa-info-circle" aria-hidden="true"></i><div class="mo-firebase-auth-tooltip-text mo-tt-right">Selecting this option will only allow WordPress Administrators to log in.</div> </div></div> |
| 85 | </div></td></tr> |
| 86 | </table> |
| 87 | <div style="margin-top: 10px;"> |
| 88 | <font color="#FF0000">*</font><strong>Project Id</strong><div class="mo-firebase-auth-tooltip"><i class="fa fa-info-circle" aria-hidden="true"></i><div class="mo-firebase-auth-tooltip-text mo-tt-right">collect project Id from your firebase project</div> </div></div><div style="margin-top: 10px;"> |
| 89 | <input type="text" id="project_id" name="projectid" value= "<?php echo esc_attr( get_option( 'mo_firebase_auth_project_id' ) ); ?>" placeholder="Enter Project Id.." required="" style = "width:50%; font-size: 14px;"></div><br> |
| 90 | <font color="#FF0000">*</font><strong>API Key</strong><div class="mo-firebase-auth-tooltip"><i class="fa fa-info-circle" aria-hidden="true"></i><div class="mo-firebase-auth-tooltip-text mo-tt-right">collect API key from your firebase project</div> </div><br> |
| 91 | <input style = "width:50%; font-size: 14px;" type="password" id="api_key" name="apikey" value="<?php echo esc_attr( get_option( 'mo_firebase_auth_api_key' ) ); ?>" placeholder="Enter your API Key.." required=""> |
| 92 | <i class="fa fa-eye" id="show_button" onclick="passwordShowButton('api_key', this.id)" style="margin-left: -30px; cursor: pointer; "></i> |
| 93 | <br><br> |
| 94 | <input type="submit" class="button button-primary button-large" style="margin-top: 10px; width:140px;" name="verify_user" value=" Save Configuration" id = "mo_auth_configure_button"> |
| 95 | </form> |
| 96 | </div> |
| 97 | </div> |
| 98 | <div> |
| 99 | <div class="mo_table_layout" id ="test_authentication" style="width:100%" > |
| 100 | <h3 style="margin: 0px;">Test Authentication</h3> |
| 101 | <form name="test_configuration_form" id="mo_firebasetestconfig" method="post" target="firebasetestconfig" style="margin-top: 0px;"> |
| 102 | <?php wp_nonce_field( 'mo_firebase_auth_test_config_form', 'mo_firebase_auth_test_config_field' ); ?> |
| 103 | <input type="hidden" name="option" value="mo_firebase_auth_test_configuration"> |
| 104 | <table class="mo_settings_table" > |
| 105 | <tr><td> |
| 106 | <font color="#FF0000">* </font><strong>Username</strong></td><td><input type="text" id="test_username" name="test_username" value="" placeholder="Username" required="" class="mo_table_short_textbox" style="width:40%;"></td></tr> <tr><td></td></tr><tr><td> |
| 107 | <font color="#FF0000">* </font><strong>Password</strong></td><td><input type="password" id="test_password" name="test_password" value="" placeholder="Password" required="" class="mo_table_short_textbox" style="width:40%;" autocomplete="on"> |
| 108 | <i class="fa fa-eye" id="show_button1" onclick="passwordShowButton('test_password', this.id)" style="margin-left: -30px; cursor: pointer; "></i> |
| 109 | </td></tr><br></table> |
| 110 | <input type="hidden" id="test_check_field" name="test_check_field" value="test_check_true"> |
| 111 | <br> |
| 112 | <input type="submit" id="mo_firebase_auth_test_config_button" name="test_configuration" value="Test Authentication" |
| 113 | <?php |
| 114 | if ( ! get_option( 'mo_firebase_auth_project_id' ) && ! get_option( 'mo_firebase_auth_api_key' ) ) { |
| 115 | echo 'disabled class="btn btn-primary" style="font-size: 14px; font-weight: 400;"'; |
| 116 | } else { |
| 117 | echo 'class="button button-primary button-large"';} |
| 118 | ?> |
| 119 | > |
| 120 | </form> |
| 121 | </div> |
| 122 | </div> |
| 123 | <div class="mo_table_layout" style="width:100%" > |
| 124 | <h3 style="margin: 0px;">Attribute Mapping <small style="color: #FF0000;font-size: 60%"><a href="admin.php?page=mo_firebase_authentication&tab=licensing_plans">[PREMIUM]</a></small></h3> |
| 125 | <form name="mo_firebase_attr_mapping_form" id="mo_firebase_attr_mapping_form" method="post"> |
| 126 | <input type="hidden" name="option" value="mo_firebase_attr_mapping"> |
| 127 | <table class="mo_settings_table" style="margin-top: 10px;"> |
| 128 | <tr><td><strong><font color="#FF0000">* </font>Username Attribute:</strong></td> |
| 129 | <td><input class="mo_table_short_textbox" type="text" id="mo_firebase_username" name="username_attr" value="" placeholder="Username Attribute Name" disabled style="width:40%;"></td></tr> |
| 130 | <tr><td><span class="mo_premium_feature"></span><strong>Email Attribute:</strong></td> |
| 131 | <td><input type="text" class="mo_table_short_textbox" id="mo_firebase_email" name="email_attr" value="" placeholder="Email Attribute Name" disabled style="width:40%;"></td></tr> |
| 132 | </table><br> |
| 133 | <small style="margin:9px;color: #686868;"><b>Note: </b>The firebase UID is stored in the user meta of the user with key <b> mo_firebase_user_uid. </b> </small><br/><br/> |
| 134 | <input type="submit" class="btn btn-primary" id="mo_firebase_save_attr_mapping_button" name="save_settings" value="Save Settings" disabled style="font-size: 14px; font-weight: 400;"> |
| 135 | </form> |
| 136 | </div> |
| 137 | |
| 138 | <div class="mo_table_layout" style="width:100%" > |
| 139 | <h3 style="margin: 0px">Role Mapping <small style="color: #FF0000;font-size: 60%"><a href="admin.php?page=mo_firebase_authentication&tab=licensing_plans">[PREMIUM]</a></small></h3> |
| 140 | <form name="mo_firebase_role_mapping_form" id="mo_firebase_role_mapping_form" method="post"> |
| 141 | <input type="hidden" name="option" value="mo_firebase_role_mapping"> |
| 142 | <table class="mo_settings_table" style="margin-top: 20px;"> |
| 143 | <tr><td colspan="2" style="padding-top: 10px;"><strong> <input type="checkbox" name="keep_existing_user_roles" value="1" disabled />Keep existing user roles</strong> <br><strong></strong><small>Role mapping won't apply to existing WordPress users</small></td></tr> |
| 144 | <tr><td><strong>WordPress Role:</strong></td> |
| 145 | <td style="padding-top:15px;"> |
| 146 | <select name="mo_firebase_default_role" id="mo_firebase_default_role" disabled> |
| 147 | <?php |
| 148 | $mo_fb_role = isset( $role_mappings['mo_firebase_default_role'] ) && $role_mappings['mo_firebase_default_role'] ? $role_mappings['mo_firebase_default_role'] : 'subscriber'; |
| 149 | wp_dropdown_roles( $mo_fb_role ); |
| 150 | ?> |
| 151 | </select> |
| 152 | </td> |
| 153 | </tr> |
| 154 | <tr><td colspan="2"><strong></strong><small>This role will be assigned to all the users who login with firebase.</small></td></tr> |
| 155 | </table> |
| 156 | <input type="submit" class="btn btn-primary" id="mo_firebase_save_role_mapping_button" style="font-size: 14px; font-weight: 400; margin-top: 2%;" name="save_settings" disabled value="Save Settings"> |
| 157 | </form> |
| 158 | </div> |
| 159 | </div> |
| 160 | </div> |
| 161 | <script> |
| 162 | |
| 163 | function passwordShowButton(id1, id2){ |
| 164 | var field = document.getElementById(id1); |
| 165 | var show_button = document.getElementById(id2); |
| 166 | if(field.type == "password"){ |
| 167 | field.type = "text"; |
| 168 | show_button.className = "fa fa-eye-slash"; |
| 169 | } |
| 170 | else{ |
| 171 | field.type = "password"; |
| 172 | show_button.className = "fa fa-eye"; |
| 173 | } |
| 174 | } |
| 175 | jQuery("#mo_firebase_auth_test_config_button").on("click", function(event) { |
| 176 | var test_username = document.forms["test_configuration_form"]["test_username"].value; |
| 177 | var test_password = document.forms["test_configuration_form"]["test_password"].value; |
| 178 | if( test_username == "" || test_password == "" ){ |
| 179 | return; |
| 180 | } |
| 181 | event.preventDefault(); |
| 182 | let url = "<?php echo esc_url( site_url() ); ?>/?mo_action=firebaselogin&test=true"; |
| 183 | jQuery("#mo_firebasetestconfig").attr("action", url); |
| 184 | let newwindow = window.open("about:blank", 'firebasetestconfig', 'location=yes,height=700,width=600,scrollbars=yes,status=yes'); |
| 185 | jQuery("#mo_firebasetestconfig").submit(); |
| 186 | }); |
| 187 | function mo_firebase_auth_showDiv(){ |
| 188 | document.getElementById("mo_firebase_auth_enable_admin_wp_login_div").style.display = "block"; |
| 189 | } |
| 190 | function mo_firebase_auth_hideDiv(){ |
| 191 | document.getElementById("mo_firebase_auth_enable_admin_wp_login_div").style.display = "none"; |
| 192 | } |
| 193 | |
| 194 | </script> |
| 195 | <?php |
| 196 | } |
| 197 | } |
| 198 |