Changeset 22091 for extensions/Register_FluxBB/include/functions.inc.php
- Timestamp:
- Apr 9, 2013, 6:17:32 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Register_FluxBB/include/functions.inc.php
r22039 r22091 15 15 } 16 16 17 /**18 * Add new registered user in FluxBB user table19 */20 function Register_FluxBB_Adduser($register_user)21 {22 global $errors, $conf;23 24 // Exclusion of Adult_Content users25 if ($register_user['username'] != "16" and $register_user['username'] != "18")26 {27 // Warning : FluxBB uses Sha1 hash instead of a salted md5 for Piwigo! // TODO: Reset password28 FluxBB_Adduser($register_user['id'], $register_user['username'], sha1($_POST['password']), $register_user['email']);29 }30 }31 32 /**33 * Delete registered user in FluxBB user table34 */35 function Register_FluxBB_Deluser($user_id)36 {37 FluxBB_Deluser(FluxBB_Searchuser($user_id), true);38 }39 17 40 18 /** 41 19 * Change user's password in FluxBB user table if a new password is set in Piwigo 42 */ 43 function Register_FluxBB_InitPage() 44 { 45 global $conf, $user; 20 * or an account synchronization was set 21 */ 22 function Register_FluxBB_InitProfile() 23 { 24 global $template, $conf, $user; 25 26 if (Reg_FluxBB_PwdSynch($user['id'])) 27 { 28 $template->append('errors', l10n('RegFluxBB_Password_Reset_Msg')); 29 } 46 30 47 31 if (isset($_POST['validate'])) … … 57 41 58 42 list($username) = pwg_db_fetch_row(pwg_query($query)); 59 // Warning : FluxBB uses Sha1 hash instead of a salted md5 for Piwigo! // TODO: Reset password60 43 FluxBB_Updateuser($user['id'], stripslashes($username), sha1($_POST['use_new_pwd']), $_POST['mail_address']); 61 44 } 62 45 } 46 } 47 48 49 /** 50 * Triggered on login_success 51 * 52 * Redirect user to profile page and displays a message to make him change his password for synch with FluxBB 53 * 54 */ 55 function Register_FluxBB_Login() 56 { 57 global $conf, $user; 58 59 if (Reg_FluxBB_PwdSynch($user['id'])) 60 { 61 redirect(PHPWG_ROOT_PATH.'profile.php'); 62 } 63 } 64 65 66 /** 67 * Checks special users exclusion befaore add new registered user in FluxBB user table 68 */ 69 function Register_FluxBB_Adduser($register_user) 70 { 71 global $errors, $conf; 72 73 // Exclusion of Adult_Content users 74 if ($register_user['username'] != "16" and $register_user['username'] != "18") 75 { 76 FluxBB_Adduser($register_user['id'], $register_user['username'], sha1($_POST['password']), $register_user['email']); 77 } 78 } 79 80 /** 81 * Delete registered user in FluxBB user table 82 */ 83 function Register_FluxBB_Deluser($user_id) 84 { 85 FluxBB_Deluser(FluxBB_Searchuser($user_id), true); 63 86 } 64 87 … … 85 108 86 109 list($username,$mail_address) = pwg_db_fetch_row(pwg_query($query)); 87 // Warning : FluxBB uses Sha1 hash instead of a salted md5 for Piwigo! // TODO: Reset password88 110 FluxBB_Updateuser($user_id, stripslashes($username), sha1($_POST['use_new_pwd']), $mail_address); 89 111 } … … 199 221 * Users linking in a dedicated links table 200 222 */ 201 function FluxBB_Linkuser($pwg_id, $bb_id) 202 { 223 function FluxBB_Linkuser($pwg_id, $bb_id, $PwdSync) 224 { 225 global $conf; 226 227 $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']); 228 203 229 $query = ' 204 230 SELECT pwg.id as pwg_id, bb.id as bb_id … … 209 235 AND pwg.username NOT IN ("18","16") 210 236 ;'; 211 237 212 238 $data = pwg_db_fetch_row(pwg_query($query)); 213 214 if (!empty($data) )239 240 if (!empty($data) and !is_null($PwdSync)) 215 241 { 216 242 $subquery = ' … … 220 246 ;'; 221 247 222 $subresult =pwg_query($subquery);248 pwg_query($subquery); 223 249 224 250 $subquery = ' 225 251 INSERT INTO '.Register_FluxBB_ID_TABLE.' 226 (id_user_pwg, id_user_FluxBB) 227 VALUES ('.$pwg_id.', '.$bb_id.') 228 ;'; 229 230 $subresult = pwg_query($subquery); 252 (id_user_pwg, id_user_FluxBB, PwdSynch) 253 VALUES ('.$pwg_id.', '.$bb_id.', "'.$PwdSync.'") 254 ;'; 255 256 pwg_query($subquery); 257 } 258 else 259 { 260 $PwdSync = NULL; 261 $subquery = ' 262 DELETE FROM '.Register_FluxBB_ID_TABLE.' 263 WHERE id_user_pwg = "'.$pwg_id.'" 264 OR id_user_FluxBB = "'.$bb_id.'" 265 ;'; 266 267 pwg_query($subquery); 268 269 $subquery = ' 270 INSERT INTO '.Register_FluxBB_ID_TABLE.' 271 (id_user_pwg, id_user_FluxBB, PwdSynch) 272 VALUES ('.$pwg_id.', '.$bb_id.', "'.$PwdSync.'") 273 ;'; 274 275 pwg_query($subquery); 231 276 } 232 277 } … … 243 288 ;'; 244 289 245 $result =pwg_query($query);290 pwg_query($query); 246 291 } 247 292 … … 259 304 $registred = time(); 260 305 $registred_ip = $_SERVER['REMOTE_ADDR']; 261 262 // Check if UAM is installed and if bridge is set - Exception for admins and webmasters306 307 // Set default FluxBB group - Check if UAM is installed and if bridge is set 263 308 if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB['FLUXBB_UAM_LINK']) and $conf_Register_FluxBB['FLUXBB_UAM_LINK'] == 'true') 264 309 { … … 276 321 } 277 322 278 // Check for FluxBB version 1.4.x or higher and get the correct value323 // Check for timezone settings in FluxBB version 1.4.x or higher 279 324 $query1 = ' 280 325 SELECT conf_value … … 285 330 $count1 = pwg_db_num_rows(pwg_query($query1)); 286 331 287 // Check for FluxBB version 1.2.x and get the correct value332 // Check for timezone settings in FluxBB version 1.2.x 288 333 $query2 = ' 289 334 SELECT conf_value … … 293 338 294 339 $count2 = pwg_db_num_rows(pwg_query($query2)); 295 340 341 // Set timezone var according of FluxBB version 296 342 if ($count1 == 1 and $count2 == 0) 297 343 { … … 302 348 $o_default_timezone = pwg_db_fetch_assoc(pwg_query($query2)); 303 349 } 304 305 350 351 // Get FluxBB default language 306 352 $query = ' 307 353 SELECT conf_value … … 311 357 312 358 $o_default_lang = pwg_db_fetch_assoc(pwg_query($query)); 313 359 360 // Get FluxBB default style 314 361 $query = ' 315 362 SELECT conf_value … … 320 367 $o_default_style = pwg_db_fetch_assoc(pwg_query($query)); 321 368 322 // Check if UAM is installed and if bridge is set - Exception for admins and webmasters369 // Add user - Check if UAM is installed and if bridge is set 323 370 if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB['FLUXBB_UAM_LINK']) and $conf_Register_FluxBB['FLUXBB_UAM_LINK'] == 'true') 324 371 { … … 349 396 );"; 350 397 351 $result =pwg_query($query);398 pwg_query($query); 352 399 } 353 400 else … … 379 426 ) 380 427 ;"; 381 $result =pwg_query($query);428 pwg_query($query); 382 429 } 383 430 384 431 $bb_id = pwg_db_insert_id(); 385 386 FluxBB_Linkuser($pwg_id, $bb_id); 387 } 388 389 390 /** 391 * Search linked users 392 */ 393 function FluxBB_Searchuser($id_user_pwg) 394 { 395 $query = ' 396 SELECT id_user_FluxBB, id_user_pwg 397 FROM '.Register_FluxBB_ID_TABLE.' 398 WHERE id_user_pwg = '.$id_user_pwg.' 399 LIMIT 1 400 ;'; 401 402 $data = pwg_db_fetch_assoc(pwg_query($query)); 403 404 if (!empty($data)) 405 return $data['id_user_FluxBB']; 406 else 407 return '0'; 408 } 409 410 411 /** 412 * Delete user from FluxBB users table 413 * Called from Register_FluxBB_Deluser() 414 */ 415 function FluxBB_Deluser($id_user_FluxBB, $SuppTopicsPosts) 432 433 FluxBB_Linkuser($pwg_id, $bb_id, "OK"); 434 } 435 436 437 /** 438 * Update user information in FluxBB users table 439 */ 440 function FluxBB_Updateuser($pwg_id, $username, $password, $adresse_mail) 416 441 { 417 442 global $conf; 418 443 444 include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); 419 445 $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']); 420 446 421 $query0 = ' 422 SELECT username, id 423 FROM '.FluxBB_USERS_TABLE.' 424 WHERE id = '.$id_user_FluxBB.' 425 LIMIT 1 426 ;'; 427 428 $data0 = pwg_db_fetch_assoc(pwg_query($query0)); 429 430 // If True, delete related topics and posts 431 if ($SuppTopicsPosts and $conf_Register_FluxBB['FLUXBB_DEL_PT']) 432 { 433 // Delete posts and topics of this user 434 $subquery = ' 435 DELETE FROM '.FluxBB_POSTS_TABLE.' 436 WHERE poster_id = '.$id_user_FluxBB.' 437 ;'; 438 439 $subresult = pwg_query($subquery); 440 441 // Delete topics of this user 442 $subquery = ' 443 DELETE FROM '.FluxBB_TOPICS_TABLE.' 444 WHERE BINARY poster = BINARY "'.pwg_db_real_escape_string($data0['username']).'" 445 ;'; 446 447 $subresult = pwg_query($subquery); 448 } 449 450 // Delete user's subscriptions 451 $subquery = ' 452 DELETE FROM '.FluxBB_SUBSCRIPTIONS_TABLE.' 453 WHERE user_id = '.$id_user_FluxBB.' 454 ;'; 455 456 $subresult = pwg_query($subquery); 457 458 // Delete user's account 459 $subquery = ' 460 DELETE FROM '.FluxBB_USERS_TABLE.' 461 WHERE id = '.$id_user_FluxBB.' 462 ;'; 463 464 $subresult = pwg_query($subquery); 465 466 FluxBB_Unlinkuser($id_user_FluxBB); 467 } 468 469 470 /** 471 * Update user information in FluxBB users table 472 */ 473 function FluxBB_Updateuser($pwg_id, $username, $password, $adresse_mail) 474 { 475 include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); 476 447 // Select users to update in ID link table 477 448 $query = ' 478 449 SELECT id_user_FluxBB as FluxBB_id … … 491 462 AND "'.pwg_db_real_escape_string($username).'" NOT IN ("18","16") 492 463 ;'; 493 494 $result =pwg_query($query);495 496 FluxBB_Linkuser($pwg_id, $row['FluxBB_id'] );464 465 pwg_query($query); 466 467 FluxBB_Linkuser($pwg_id, $row['FluxBB_id'], "OK"); 497 468 } 498 469 else … … 505 476 506 477 $row = pwg_db_fetch_assoc(pwg_query($query)); 507 478 508 479 if (!empty($row)) 509 480 { … … 514 485 AND "'.pwg_db_real_escape_string($username).'" NOT IN ("18","16") 515 486 ;'; 516 517 $result =pwg_query($query);518 519 FluxBB_Linkuser($pwg_id, $row['FluxBB_id'] );487 488 pwg_query($query); 489 490 FluxBB_Linkuser($pwg_id, $row['FluxBB_id'], "OK"); 520 491 } 521 492 } 522 493 } 494 495 496 /** 497 * Add new registered user in fluxBB users table from audit/synch action 498 * Standard FluxBB_Adduser() function is not used because of existing password mismatch 499 * To solve password synch problem, passwords are reset to NULL to force users to get a new password on their profile page 500 */ 501 function Synch_FluxBB_Adduser($pwg_id, $login, $adresse_mail) 502 { 503 global $errors, $conf; 504 505 $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']); 506 507 $registred = time(); 508 $registred_ip = $_SERVER['REMOTE_ADDR']; 509 $password = NULL; 510 511 // Set default FluxBB group - Check if UAM is installed and if bridge is set 512 if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB['FLUXBB_UAM_LINK']) and $conf_Register_FluxBB['FLUXBB_UAM_LINK'] == 'true') 513 { 514 $o_default_user_group1 = $conf_Register_FluxBB['FLUXBB_GROUP']; 515 } 516 else 517 { 518 $query = ' 519 SELECT conf_value 520 FROM '.FluxBB_CONFIG_TABLE.' 521 WHERE conf_name = "o_default_user_group" 522 ;'; 523 524 $o_default_user_group = pwg_db_fetch_assoc(pwg_query($query)); 525 } 526 527 // Check for timezone settings in FluxBB version 1.4.x or higher 528 $query1 = ' 529 SELECT conf_value 530 FROM '.FluxBB_CONFIG_TABLE.' 531 WHERE conf_name = "o_default_timezone" 532 ;'; 533 534 $count1 = pwg_db_num_rows(pwg_query($query1)); 535 536 // Check for timezone settings in FluxBB version 1.2.x 537 $query2 = ' 538 SELECT conf_value 539 FROM '.FluxBB_CONFIG_TABLE.' 540 WHERE conf_name = "o_server_timezone" 541 ;'; 542 543 $count2 = pwg_db_num_rows(pwg_query($query2)); 544 545 // Set timezone var according of FluxBB version 546 if ($count1 == 1 and $count2 == 0) 547 { 548 $o_default_timezone = pwg_db_fetch_assoc(pwg_query($query1)); 549 } 550 else if ($count1 == 0 and $count2 == 1) 551 { 552 $o_default_timezone = pwg_db_fetch_assoc(pwg_query($query2)); 553 } 554 555 // Get FluxBB default language 556 $query = ' 557 SELECT conf_value 558 FROM '.FluxBB_CONFIG_TABLE.' 559 WHERE conf_name = "o_default_lang" 560 ;'; 561 562 $o_default_lang = pwg_db_fetch_assoc(pwg_query($query)); 563 564 // Get FluxBB default style 565 $query = ' 566 SELECT conf_value 567 FROM '.FluxBB_CONFIG_TABLE.' 568 WHERE conf_name = "o_default_style" 569 ;'; 570 571 $o_default_style = pwg_db_fetch_assoc(pwg_query($query)); 572 573 // Add user - Check if UAM is installed and if bridge is set 574 if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB['FLUXBB_UAM_LINK']) and $conf_Register_FluxBB['FLUXBB_UAM_LINK'] == 'true') 575 { 576 $query = " 577 INSERT INTO ".FluxBB_USERS_TABLE." ( 578 username, 579 ". ( isset($o_default_user_group1) ? 'group_id' : '' ) .", 580 password, 581 email, 582 ". ( isset($o_default_timezone['conf_value']) ? 'timezone' : '' ) .", 583 ". ( isset($o_default_lang['conf_value']) ? 'language' : '' ) .", 584 ". ( isset($o_default_style['conf_value']) ? 'style' : '' ) .", 585 registered, 586 registration_ip, 587 last_visit 588 ) 589 VALUES( 590 '".pwg_db_real_escape_string($login)."', 591 ". ( isset($o_default_user_group1) ? "'".$o_default_user_group1."'" : '' ) .", 592 '".$password."', 593 '".$adresse_mail."', 594 ". ( isset($o_default_timezone['conf_value']) ? "'".$o_default_timezone['conf_value']."'" : '' ) .", 595 ". ( isset($o_default_lang['conf_value']) ? "'".$o_default_lang['conf_value']."'" : '' ) .", 596 ". ( isset($o_default_style['conf_value']) ? "'".$o_default_style['conf_value']."'" : '' ) .", 597 '".$registred."', 598 '".$registred_ip."', 599 '".$registred."' 600 );"; 601 602 pwg_query($query); 603 } 604 else 605 { 606 $query = " 607 INSERT INTO ".FluxBB_USERS_TABLE." ( 608 username, 609 ". ( isset($o_default_user_group['conf_value']) ? 'group_id' : '' ) .", 610 password, 611 email, 612 ". ( isset($o_default_timezone['conf_value']) ? 'timezone' : '' ) .", 613 ". ( isset($o_default_lang['conf_value']) ? 'language' : '' ) .", 614 ". ( isset($o_default_style['conf_value']) ? 'style' : '' ) .", 615 registered, 616 registration_ip, 617 last_visit 618 ) 619 VALUES( 620 '".pwg_db_real_escape_string($login)."', 621 ". ( isset($o_default_user_group['conf_value']) ? "'".$o_default_user_group['conf_value']."'" : '' ) .", 622 '".$password."', 623 '".$adresse_mail."', 624 ". ( isset($o_default_timezone['conf_value']) ? "'".$o_default_timezone['conf_value']."'" : '' ) .", 625 ". ( isset($o_default_lang['conf_value']) ? "'".$o_default_lang['conf_value']."'" : '' ) .", 626 ". ( isset($o_default_style['conf_value']) ? "'".$o_default_style['conf_value']."'" : '' ) .", 627 '".$registred."', 628 '".$registred_ip."', 629 '".$registred."' 630 ) 631 ;"; 632 pwg_query($query); 633 } 634 635 $bb_id = pwg_db_insert_id(); 636 637 FluxBB_Linkuser($pwg_id, $bb_id, "NOK"); 638 } 639 640 641 /** 642 * Search linked users 643 */ 644 function FluxBB_Searchuser($id_user_pwg) 645 { 646 $query = ' 647 SELECT id_user_FluxBB, id_user_pwg 648 FROM '.Register_FluxBB_ID_TABLE.' 649 WHERE id_user_pwg = '.$id_user_pwg.' 650 LIMIT 1 651 ;'; 652 653 $data = pwg_db_fetch_assoc(pwg_query($query)); 654 655 if (!empty($data)) 656 return $data['id_user_FluxBB']; 657 else 658 return '0'; 659 } 660 661 662 /** 663 * Delete user from FluxBB users table 664 * Called from Register_FluxBB_Deluser() 665 */ 666 function FluxBB_Deluser($id_user_FluxBB, $SuppTopicsPosts) 667 { 668 global $conf; 669 670 $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']); 671 672 $query0 = ' 673 SELECT username, id 674 FROM '.FluxBB_USERS_TABLE.' 675 WHERE id = '.$id_user_FluxBB.' 676 LIMIT 1 677 ;'; 678 679 $data0 = pwg_db_fetch_assoc(pwg_query($query0)); 680 681 // If True, delete related topics and posts 682 if ($SuppTopicsPosts and $conf_Register_FluxBB['FLUXBB_DEL_PT']) 683 { 684 // Delete posts and topics of this user 685 $subquery = ' 686 DELETE FROM '.FluxBB_POSTS_TABLE.' 687 WHERE poster_id = '.$id_user_FluxBB.' 688 ;'; 689 690 $subresult = pwg_query($subquery); 691 692 // Delete topics of this user 693 $subquery = ' 694 DELETE FROM '.FluxBB_TOPICS_TABLE.' 695 WHERE BINARY poster = BINARY "'.pwg_db_real_escape_string($data0['username']).'" 696 ;'; 697 698 $subresult = pwg_query($subquery); 699 } 700 701 // Delete user's subscriptions 702 $subquery = ' 703 DELETE FROM '.FluxBB_SUBSCRIPTIONS_TABLE.' 704 WHERE user_id = '.$id_user_FluxBB.' 705 ;'; 706 707 $subresult = pwg_query($subquery); 708 709 // Delete user's account 710 $subquery = ' 711 DELETE FROM '.FluxBB_USERS_TABLE.' 712 WHERE id = '.$id_user_FluxBB.' 713 ;'; 714 715 $subresult = pwg_query($subquery); 716 717 FluxBB_Unlinkuser($id_user_FluxBB); 718 } 719 523 720 524 721 /**
Note: See TracChangeset
for help on using the changeset viewer.