Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.0 KiB

10 years ago
10 years ago
  1. <?php
  2. function manage_post(&$a) {
  3. if(! local_user() || ! is_array($a->identities))
  4. return;
  5. $identity = ((x($_POST['identity'])) ? intval($_POST['identity']) : 0);
  6. if(! $identity)
  7. return;
  8. $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `email` = '%s' AND `password` = '%s' LIMIT 1",
  9. intval($identity),
  10. dbesc($a->user['email']),
  11. dbesc($a->user['password'])
  12. );
  13. if(! count($r))
  14. return;
  15. unset($_SESSION['authenticated']);
  16. unset($_SESSION['uid']);
  17. unset($_SESSION['visitor_id']);
  18. unset($_SESSION['administrator']);
  19. unset($_SESSION['cid']);
  20. unset($_SESSION['theme']);
  21. unset($_SESSION['page_flags']);
  22. $_SESSION['uid'] = $r[0]['uid'];
  23. $_SESSION['theme'] = $r[0]['theme'];
  24. $_SESSION['authenticated'] = 1;
  25. $_SESSION['page_flags'] = $r[0]['page-flags'];
  26. $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $r[0]['nickname'];
  27. info( sprintf( t("Welcome back %s") , $r[0]['username']) . EOL);
  28. $a->user = $r[0];
  29. if(strlen($a->user['timezone'])) {
  30. date_default_timezone_set($a->user['timezone']);
  31. $a->timezone = $a->user['timezone'];
  32. }
  33. $r = q("SELECT `uid`,`username` FROM `user` WHERE `password` = '%s' AND `email` = '%s'",
  34. dbesc($a->user['password']),
  35. dbesc($a->user['email'])
  36. );
  37. if(count($r))
  38. $a->identities = $r;
  39. $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
  40. intval($_SESSION['uid']));
  41. if(count($r)) {
  42. $a->contact = $r[0];
  43. $a->cid = $r[0]['id'];
  44. $_SESSION['cid'] = $a->cid;
  45. }
  46. q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d LIMIT 1",
  47. dbesc(datetime_convert()),
  48. intval($_SESSION['uid'])
  49. );
  50. header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] .'"');
  51. goaway($a->get_baseurl() . '/profile/' . $a->user['nickname']);
  52. // NOTREACHED
  53. }
  54. function manage_content(&$a) {
  55. if(! local_user() || ! is_array($a->identities)) {
  56. notice( t('Permission denied.') . EOL);
  57. return;
  58. }
  59. $r = q("SELECT * FROM `user` WHERE `email` = '%s' AND `password` = '%s'",
  60. dbesc($a->user['email']),
  61. dbesc($a->user['password'])
  62. );
  63. if(! count($r))
  64. return;
  65. $o = '<h3>' . t('Manage Identities and/or Pages') . '</h3>';
  66. $o .= '<div id="identity-manage-desc">' . t("\x28Toggle between different identities or community/group pages which share your account details.\x29") . '</div>';
  67. $o .= '<div id="identity-manage-choose">' . t('Select an identity to manage: ') . '</div>';
  68. $o .= '<div id="identity-selector-wrapper">' . "\r\n";
  69. $o .= '<form action="manage" method="post" >' . "\r\n";
  70. $o .= '<select name="identity" size="4">' . "\r\n";
  71. foreach($r as $rr) {
  72. $selected = (($rr['nickname'] === $a->user['nickname']) ? ' selected="selected" ' : '');
  73. $o .= '<option ' . $selected . 'value="' . $rr['uid'] . '">' . $rr['username'] . ' (' . $rr['nickname'] . ')</option>' . "\r\n";
  74. }
  75. $o .= '</select>' . "\r\n";
  76. $o .= '<div id="identity-select-break"></div>' . "\r\n";
  77. $o .= '<input id="identity-submit" type="submit" name="submit" value="' . t('Submit') . '" /></div></form>' . "\r\n";
  78. return $o;
  79. }