Changeset 2887327
- Timestamp:
- 03/27/2023 05:59:02 AM (3 years ago)
- Location:
- jvh-easy-login
- Files:
-
- 6 edited
-
assets/icon-128x128.jpg (modified) (previous)
-
assets/icon-256x256.jpg (modified) (previous)
-
assets/icon.svg (modified) (1 diff)
-
trunk/EasyLogin.php (modified) (7 diffs)
-
trunk/jvh-easy-login.php (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
jvh-easy-login/assets/icon.svg
r2260703 r2887327 1 <svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 98.68 98.67"><defs><style>.cls-1{fill:#afcb37;}.cls-2{fill:#454644;}</style></defs><title>iconsvg</title><path class="cls-1" d="M90.88,26.84l.3-8.42c0-3.06-1.88-4.37-5.58-5.51L54.72,3.17,50,6.94s27,8.35,30.48,9.59,2.38,3.62.33,5.52c0,0-25.24,20.76-26.09,21.23a4.41,4.41,0,0,1-3.72.25L24.32,36c-2.93-.6-5.55,2.48-5.55,5.55L20.31,69.7c0,3.06.67,6.21,5.54,8.13s25.85,10,27.42,10.6c2,.86,4.18,1.11,7.41-1.43l28-21.94c1-1.1,1.27-1.91,1-5.5l.18-5L63.53,75.41v-9l26.69-21,.33-9.22-27,21.22v-9ZM38.46,62.7l.3,9.84a2,2,0,0,1-1.89,2.19,2.16,2.16,0,0,1-2-2.19l-.3-9.79c-2-1.07-3.52-3.78-3.62-7-.13-4.12,2.13-7.46,5-7.46s5.77,3.43,5.84,7.55C41.86,59,40.42,61.61,38.46,62.7Z"/><path class="cls-2" d="M73.89,19.26l-6.77-2.2c-9.76-3.25-24.3-8.17-31.36-10.48-1.43-.47-5.07-.49-7,.7L11.7,19.79c-2.61,2-4.37,4.07-4.19,8.41s.62,14.74.62,14.74l1,23.3.3,5.4a15.43,15.43,0,0,0,1.75,7.48,13.45,13.45,0,0,0,4.26,4.64,18.78,18.78,0,0,0,3.68,1.93c1.82.71,13.37,5.13,21.84,8.37l2.77,1a6.13,6.13,0,0,0,3.49.24c1.55-.34,2.73-1.17,3.69-1.4-.46-.2-3.25-1.28-6.67-2.6L38.05,89C32.11,86.69,26,84.33,23.58,83.39a14.33,14.33,0,0,1-7.64-6.32,14.79,14.79,0,0,1-1.69-7.2l-1.1-20.2-.43-7.84c0-.11,0-.22,0-.32,0-6.29,4.94-11.6,10.79-11.6a9.56,9.56,0,0,1,1.77.17l17.92,5.1L49.64,37a5.72,5.72,0,0,0,1,.24,4,4,0,0,0,2.62-.44s9.27-7,16.4-12.53L74,20.86C74.64,20.36,74.84,19.64,73.89,19.26Z"/><path class="cls-2" d="M71.76,93a14.19,14.19,0,0,0,6.5-26.87l.24-26.72-5.89-5.36L67,39.34V40l2.22,2.26L67,44.44v.46l2.29,2.33-2.33,2.28v.9l1.93,2-2,1.93v.85l2,2.08-2.08,2,0,3.27L64.7,65l0,1.59A14.2,14.2,0,0,0,71.76,93Zm2.1-29.27.2-22a.74.74,0,0,1,.76-.74h.66a.75.75,0,0,1,.74.75L76,63.79a.76.76,0,0,1-.76.74H74.6A.73.73,0,0,1,73.86,63.77ZM68.12,85.6a3.71,3.71,0,1,1,3.67,3.73A3.71,3.71,0,0,1,68.12,85.6Z"/></svg>1 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 196.99 196.99"><defs><style>.a{fill:url(#a);}.b{fill:#3c3c3b;}.c{fill:#fff;}.d{fill:#afca0b;}</style><radialGradient id="a" cx="98.5" cy="98.5" r="98.5" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#afca0b"/><stop offset="1" stop-color="#90ae00"/></radialGradient></defs><rect class="a" width="196.99" height="196.99"/><path class="b" d="M175.07,64.92c0,66.75-41,103.94-66.84,114.71a14.51,14.51,0,0,1-11.13,0C64.83,166.18,30.29,124.8,30.29,64.92a14.46,14.46,0,0,1,8.93-13.36L97.13,27.43a17.41,17.41,0,0,1,5.57-1.11,17.35,17.35,0,0,1,5.56,1.11l57.91,24.13A14.48,14.48,0,0,1,175.07,64.92Z"/><path class="c" d="M175.45,59.34c0,68.1-41.82,106-68.19,117a14.81,14.81,0,0,1-11.36,0C63,162.65,27.74,120.43,27.74,59.34a14.76,14.76,0,0,1,9.1-13.63L95.93,21.09A17.55,17.55,0,0,1,101.61,20a17.55,17.55,0,0,1,5.68,1.13l59.08,24.62A14.77,14.77,0,0,1,175.45,59.34Zm-9.88,0a4.9,4.9,0,0,0-3-4.55L103.47,30.17a4.88,4.88,0,0,0-3.79,0L40.6,54.79a4.94,4.94,0,0,0-3,4.55c0,54.16,32,96,62.14,108a5,5,0,0,0,3.78,0C133.6,155.36,165.6,113.5,165.57,59.34Z"/><path class="d" d="M165.59,59.35a4.9,4.9,0,0,0-3-4.56L103.49,30.17a4.93,4.93,0,0,0-3.79,0L40.61,54.79a5,5,0,0,0-3,4.56c0,54.16,32,96,62.13,108a5.07,5.07,0,0,0,3.79,0C133.61,155.36,165.62,113.51,165.59,59.35Z"/><path class="b" d="M90.34,116.1,62,98.79a13.6,13.6,0,0,1-2.57-2,14.29,14.29,0,0,1-4.51-10.46A14.48,14.48,0,0,1,61.92,74L100.4,50.36a15.73,15.73,0,0,1,15.46-.54,16,16,0,0,1,3.55,2.57,14.07,14.07,0,0,1,4.42,10.37,12.32,12.32,0,0,1-3.92,9.05l-6.37,6.09L109.85,74l6.37-6.12a7,7,0,0,0,2.26-5.16,9,9,0,0,0-2.82-6.54,9.8,9.8,0,0,0-2.31-1.64,10.35,10.35,0,0,0-10.18.34L64.71,78.52a9.2,9.2,0,0,0-4.48,7.84,9,9,0,0,0,2.82,6.54,8.16,8.16,0,0,0,1.63,1.24l28.42,17.4Z"/><path class="d" d="M94.85,141.73A15.86,15.86,0,0,1,87.58,140a15.53,15.53,0,0,1-3.53-2.54A14.11,14.11,0,0,1,79.6,127a12.47,12.47,0,0,1,3.92-9l8.26-7.89a9.13,9.13,0,0,0,.42-12.91l-.42-.43-8.24-7.86a12.43,12.43,0,0,1-3.91-9.08,14.38,14.38,0,0,1,8-12.86,15,15,0,0,1,15.22.45L141.51,91a17.68,17.68,0,0,1,2.57,2,14.39,14.39,0,0,1,.4,20.33,14.13,14.13,0,0,1-3,2.37L103,139.42A15.45,15.45,0,0,1,94.85,141.73Zm0-71.3a10.41,10.41,0,0,0-4.79,1.24A9.14,9.14,0,0,0,85,79.82h0A7.2,7.2,0,0,0,87.21,85l8.26,7.86a14.5,14.5,0,0,1,.58,20.49c-.19.2-.38.39-.58.57l-8.26,7.9A7.22,7.22,0,0,0,85,127a8.94,8.94,0,0,0,2.82,6.52,11.54,11.54,0,0,0,2.32,1.66,10.28,10.28,0,0,0,10.17-.37l38.49-23.59a9.15,9.15,0,0,0,4.48-7.81,8.89,8.89,0,0,0-2.82-6.54,9.91,9.91,0,0,0-1.66-1.3L100,72A9.7,9.7,0,0,0,94.85,70.43Z"/><path class="b" d="M90.34,116.1,62,98.79a13.6,13.6,0,0,1-2.57-2,14.29,14.29,0,0,1-4.51-10.46A14.48,14.48,0,0,1,61.92,74L100.4,50.36a15.73,15.73,0,0,1,15.46-.54,16,16,0,0,1,3.55,2.57,14.07,14.07,0,0,1,4.42,10.37,12.32,12.32,0,0,1-3.92,9.05l-6.37,6.09L109.85,74l6.37-6.12a7,7,0,0,0,2.26-5.16,9,9,0,0,0-2.82-6.54,9.8,9.8,0,0,0-2.31-1.64,10.35,10.35,0,0,0-10.18.34L64.71,78.52a9.2,9.2,0,0,0-4.48,7.84,9,9,0,0,0,2.82,6.54,8.16,8.16,0,0,0,1.63,1.24l28.42,17.4Z"/><path class="c" d="M94.85,141.73A15.86,15.86,0,0,1,87.58,140a15.53,15.53,0,0,1-3.53-2.54A14.11,14.11,0,0,1,79.6,127a12.47,12.47,0,0,1,3.92-9l8.26-7.89a9.13,9.13,0,0,0,.42-12.91l-.42-.43-8.24-7.86a12.43,12.43,0,0,1-3.91-9.08,14.38,14.38,0,0,1,8-12.86,15,15,0,0,1,15.22.45L141.51,91a17.68,17.68,0,0,1,2.57,2,14.39,14.39,0,0,1,.4,20.33,14.13,14.13,0,0,1-3,2.37L103,139.42A15.45,15.45,0,0,1,94.85,141.73Zm0-71.3a10.41,10.41,0,0,0-4.79,1.24A9.14,9.14,0,0,0,85,79.82h0A7.2,7.2,0,0,0,87.21,85l8.26,7.86a14.5,14.5,0,0,1,.58,20.49c-.19.2-.38.39-.58.57l-8.26,7.9A7.22,7.22,0,0,0,85,127a8.94,8.94,0,0,0,2.82,6.52,11.54,11.54,0,0,0,2.32,1.66,10.28,10.28,0,0,0,10.17-.37l38.49-23.59a9.15,9.15,0,0,0,4.48-7.81,8.89,8.89,0,0,0-2.82-6.54,9.91,9.91,0,0,0-1.66-1.3L100,72A9.7,9.7,0,0,0,94.85,70.43Z"/><circle class="c" cx="159.3" cy="42" r="22.04"/><path class="b" d="M159.21,58.34a7.87,7.87,0,0,0,3.61-14.9L163,28.63l-3.26-3-3.12,2.94V29l1.24,1.26-1.24,1.2v.26L157.84,33l-1.29,1.27v.49l1.07,1.11-1.11,1.07v.47l1.11,1.16-1.15,1.11v1.81l-1.17,1.36v.89a7.87,7.87,0,0,0,3.91,14.64Zm1.17-16.23.11-12.2a.41.41,0,0,1,.41-.41h.38a.43.43,0,0,1,.41.42l-.13,12.22a.41.41,0,0,1-.42.41h-.35a.39.39,0,0,1-.41-.4v0ZM157.2,54.23a2.06,2.06,0,1,1,2,2.07h0A2,2,0,0,1,157.2,54.23Z"/></svg> -
jvh-easy-login/trunk/EasyLogin.php
r2369973 r2887327 4 4 5 5 use JsonException; 6 use function get_user_by;7 use function get_user_meta;8 use function is_wp_error;9 use function update_user_meta;10 use function wp_die;11 6 12 7 class EasyLogin { … … 21 16 } 22 17 23 if ( isset( $_GET['jvh-login-check-approval'] ) ) {24 header( 'Content-Type: application/json' );25 echo json_encode( $this->getApprovalRequestData( $token, $_GET['jvh-login-check-approval'] ), JSON_THROW_ON_ERROR );26 exit;27 }28 29 18 $userData = $this->requestUserInformation( $token ); 30 $role = $this->getUserRole( $userData );31 32 $userExists = $this->checkIfUserExists( $userData['data']['user_email'] );33 if ( $userExists ) {34 $this->loginAsUser( $this->getUserId( $userData['data']['user_email'] ) );35 }36 37 if ( in_array( $role, [ 'intern', 'limited_employee' ], true ) && ! $this->isRequestAuthorized() ) {38 $approvalUuid = $this->generateApprovalRequest( $token );39 include __DIR__ . '/templates/login.php';40 exit;41 }42 19 43 20 $userExists = $this->checkIfUserExists( $userData['data']['user_email'], false ); 44 21 if ( ! $userExists ) { 45 $this->createUser( $userData , in_array( $role, [ 'intern', 'limited_employee' ], true ));22 $this->createUser( $userData ); 46 23 } 47 24 $this->loginAsUser( $this->getUserId( $userData['data']['user_email'] ) ); 48 49 25 } 50 26 … … 77 53 /** 78 54 * @param string $token 79 * @param string $uuid80 55 * 81 56 * @return mixed 82 57 * @throws JsonException 83 58 */ 84 private function getApprovalRequestData( string $token, string $uuid ) { 85 $response = wp_remote_get( 'https://api2.workspace.jvhwebbouw.nl/wp-json/jvh/v1/approval?uuid=' . $uuid, [ 86 'method' => 'GET', 87 'timeout' => 10000, 88 'redirection' => 5, 89 'headers' => [ 90 'Authorization' => 'Bearer ' . $token, 91 ], 92 ] ); 93 94 if ( is_wp_error( $response ) ) { 95 $this->die( 'Could not get approval information: ' . $response->get_error_message() ); 96 } 97 98 if ( ! isset( $response['body'] ) ) { 99 $this->die( 'Could not get approval information. Body of call not present' ); 100 } 101 102 $data = json_decode( $response['body'], true, 512, JSON_THROW_ON_ERROR ); 103 if ( ! isset( $data['status'] ) || $data['status'] !== 'OK' ) { 104 $this->die( 'Could not get approval information. Status is not OK, so authentication token must be wrong.' ); 105 } 106 107 return $data; 108 } 109 110 /** 111 * @param string $token 112 * 113 * @return mixed 114 * @throws JsonException 115 */ 116 private function requestUserInformation( string $token ) { 59 private function requestUserInformation( string $token ): mixed { 117 60 $response = wp_remote_get( 'https://api2.workspace.jvhwebbouw.nl/wp-json/jvh/v1/user/me', [ 118 61 'method' => 'GET', … … 141 84 142 85 /** 143 * @param array $userInformation144 *145 * @return string146 */147 private function getUserRole( array $userInformation ): string {148 $roles = $userInformation['roles'];149 if ( in_array( 'administrator', $roles, true ) ) {150 return 'administrator';151 }152 if ( in_array( 'manager', $roles, true ) ) {153 return 'manager';154 }155 if ( in_array( 'employee', $roles, true ) ) {156 return 'employee';157 }158 if ( in_array( 'limited_employee', $roles, true ) ) {159 return 'limited_employee';160 }161 162 return 'intern';163 }164 165 /**166 86 * @param string $email 167 87 * … … 174 94 175 95 if ( $user !== false && ! is_wp_error( $user ) ) { 176 if ( ! $checkExpiration ) { 177 return true; 178 } 179 $expiration = get_user_meta( $user->ID, 'jvh-login-expiration', true ); 180 if ( empty( $expiration ) ) { 181 return true; 182 } 183 $expiration = (int) $expiration; 184 185 return ! ( (int) microtime( true ) > $expiration ); 96 return true; 186 97 } 187 98 … … 213 124 214 125 /** 215 * @return bool 216 * @throws JsonException 126 * @param array $userData 127 * 128 * @return void 217 129 */ 218 private function isRequestAuthorized(): bool { 219 if ( ! isset( $_POST['jvh-login-employee-user'], $_POST['jvh-login-employee-password'] ) && ! isset( $_POST['jvh-login-tool-token'] ) ) { 220 return false; 221 } 222 223 if ( isset( $_POST['jvh-login-tool-token'] ) ) { 224 $token = $_POST['jvh-login-tool-token']; 225 $userData = $this->requestUserInformation( $token ); 226 $role = $this->getUserRole( $userData ); 227 228 if ( in_array( $role, [ 'employee', 'manager', 'administrator' ] ) ) { 229 return true; 230 } 231 232 return false; 233 } 234 235 return $this->loginAndCheckRole( $_POST['jvh-login-employee-user'], $_POST['jvh-login-employee-password'] ); 236 } 237 238 /** 239 * @param string $username 240 * @param string $password 241 * 242 * @return bool 243 * @throws JsonException 244 */ 245 private function loginAndCheckRole( string $username, string $password ): bool { 246 $response = wp_remote_post( 'https://api2.workspace.jvhwebbouw.nl/wp-json/jwt-auth/v1/token', [ 247 'method' => 'POST', 248 'timeout' => 10000, 249 'redirection' => 5, 250 'body' => [ 251 'username' => $username, 252 'password' => $password, 253 ], 254 ] ); 255 256 if ( is_wp_error( $response ) ) { 257 $this->die( 'Could not get employee information: ' . $response->get_error_message() ); 258 } 259 260 if ( ! isset( $response['body'] ) ) { 261 $this->die( 'Could not get employee information. Body of call not present' ); 262 } 263 264 $data = json_decode( $response['body'], true, 512, JSON_THROW_ON_ERROR ); 265 if ( ! isset( $data['status'] ) || $data['status'] !== 'OK' ) { 266 $this->die( 'Could not get employee information. Status is not OK, so authentication token must be wrong.' ); 267 } 268 269 $token = $data['token']; 270 271 $userData = $this->requestUserInformation( $token ); 272 $role = $this->getUserRole( $userData ); 273 274 if ( in_array( $role, [ 'employee', 'manager', 'administrator' ] ) ) { 275 return true; 276 } 277 278 return false; 279 } 280 281 /** 282 * @param string $token 283 * 284 * @return mixed 285 * @throws JsonException 286 */ 287 private function generateApprovalRequest( string $token ) { 288 $response = wp_remote_post( 'https://api2.workspace.jvhwebbouw.nl/wp-json/jvh/v1/approval', [ 289 'method' => 'POST', 290 'timeout' => 10000, 291 'redirection' => 5, 292 'body' => [ 293 'reason' => 'Toegang tot ' . site_url(), 294 ], 295 'headers' => [ 296 'Authorization' => 'Bearer ' . $token, 297 ], 298 ] ); 299 300 if ( is_wp_error( $response ) ) { 301 $this->die( 'Could not request approval: ' . $response->get_error_message() ); 302 } 303 304 if ( ! isset( $response['body'] ) ) { 305 $this->die( 'Could not request approval. Body of call not present' ); 306 } 307 308 $data = json_decode( $response['body'], true, 512, JSON_THROW_ON_ERROR ); 309 310 if ( ! isset( $data['status'] ) || $data['status'] !== 'OK' ) { 311 $this->die( 'Could not request approval. Status is not OK, so authentication token must be wrong.' ); 312 } 313 314 return $data['data']['uuid']; 315 } 316 317 /** 318 * @param array $userData 319 * @param bool $withExpiration 320 * 321 * @return int 322 */ 323 private function createUser( array $userData, bool $withExpiration = false ): int { 130 private function createUser( array $userData ): void { 324 131 $userId = wp_insert_user( [ 325 132 'user_login' => $userData['data']['user_login'] . '@jvh', … … 338 145 } 339 146 340 if ( $withExpiration ) {341 update_user_meta( $userId, 'jvh-login-expiration', (int) microtime( true ) + WEEK_IN_SECONDS );342 }343 344 return $userId;345 147 } 346 148 } -
jvh-easy-login/trunk/jvh-easy-login.php
r2369976 r2887327 3 3 Plugin Name: JVH webbouw - Easy login 4 4 Description: This plugin is for JVH webbouw to securely login to this website. 5 Version: 1. 2.15 Version: 1.3.0 6 6 Author: JVH webbouw | Lars Jansen 7 7 Author URI: https://www.jvhwebbouw.nl 8 8 License: GPL v3 9 Requires PHP: 7.310 Requires at least: 5.09 Requires PHP: 8.0 10 Requires at least: 6.0 11 11 */ 12 12 -
jvh-easy-login/trunk/readme.txt
r2369976 r2887327 6 6 Author URI: https://www.jvhwebbouw.nl 7 7 Author: JVH webbouw 8 Requires at least: 5.09 Tested up to: 5.510 Stable tag: 1. 2.111 Requires PHP: 7.312 Version: 1. 2.18 Requires at least: 6.0 9 Tested up to: 6.2 10 Stable tag: 1.3.0 11 Requires PHP: 8.0 12 Version: 1.3.0 13 13 14 14 == Description ==
Note: See TracChangeset
for help on using the changeset viewer.