user.pages.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. <?php
  2. /**
  3. * @file
  4. * User page callback file for the user module.
  5. */
  6. /**
  7. * Menu callback; Retrieve a JSON object containing autocomplete suggestions for existing users.
  8. */
  9. function user_autocomplete($string = '') {
  10. $matches = array();
  11. if ($string) {
  12. $result = db_select('users')->fields('users', array('name'))->condition('name', db_like($string) . '%', 'LIKE')->range(0, 10)->execute();
  13. foreach ($result as $user) {
  14. $matches[$user->name] = check_plain($user->name);
  15. }
  16. }
  17. drupal_json_output($matches);
  18. }
  19. /**
  20. * Form builder; Request a password reset.
  21. *
  22. * @ingroup forms
  23. * @see user_pass_validate()
  24. * @see user_pass_submit()
  25. */
  26. function user_pass() {
  27. global $user;
  28. $form['name'] = array(
  29. '#type' => 'textfield',
  30. '#title' => t('Username or e-mail address'),
  31. '#size' => 60,
  32. '#maxlength' => max(USERNAME_MAX_LENGTH, EMAIL_MAX_LENGTH),
  33. '#required' => TRUE,
  34. '#default_value' => isset($_GET['name']) ? $_GET['name'] : '',
  35. );
  36. // Allow logged in users to request this also.
  37. if ($user->uid > 0) {
  38. $form['name']['#type'] = 'value';
  39. $form['name']['#value'] = $user->mail;
  40. $form['mail'] = array(
  41. '#prefix' => '<p>',
  42. // As of https://www.drupal.org/node/889772 the user no longer must log
  43. // out (if they are still logged in when using the password reset link,
  44. // they will be logged out automatically then), but this text is kept as
  45. // is to avoid breaking translations as well as to encourage the user to
  46. // log out manually at a time of their own choosing (when it will not
  47. // interrupt anything else they may have been in the middle of doing).
  48. '#markup' => t('Password reset instructions will be mailed to %email. You must log out to use the password reset link in the e-mail.', array('%email' => $user->mail)),
  49. '#suffix' => '</p>',
  50. );
  51. }
  52. $form['actions'] = array('#type' => 'actions');
  53. $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('E-mail new password'));
  54. return $form;
  55. }
  56. /**
  57. * Form validation handler for user_pass().
  58. *
  59. * @see user_pass_submit()
  60. */
  61. function user_pass_validate($form, &$form_state) {
  62. $name = trim($form_state['values']['name']);
  63. // Try to load by email.
  64. $users = user_load_multiple(array(), array('mail' => $name, 'status' => '1'));
  65. $account = reset($users);
  66. if (!$account) {
  67. // No success, try to load by name.
  68. $users = user_load_multiple(array(), array('name' => $name, 'status' => '1'));
  69. $account = reset($users);
  70. }
  71. if (isset($account->uid)) {
  72. form_set_value(array('#parents' => array('account')), $account, $form_state);
  73. }
  74. else {
  75. form_set_error('name', t('Sorry, %name is not recognized as a user name or an e-mail address.', array('%name' => $name)));
  76. }
  77. }
  78. /**
  79. * Form submission handler for user_pass().
  80. *
  81. * @see user_pass_validate()
  82. */
  83. function user_pass_submit($form, &$form_state) {
  84. global $language;
  85. $account = $form_state['values']['account'];
  86. // Mail one time login URL and instructions using current language.
  87. $mail = _user_mail_notify('password_reset', $account, $language);
  88. if (!empty($mail)) {
  89. watchdog('user', 'Password reset instructions mailed to %name at %email.', array('%name' => $account->name, '%email' => $account->mail));
  90. drupal_set_message(t('Further instructions have been sent to your e-mail address.'));
  91. }
  92. $form_state['redirect'] = 'user';
  93. return;
  94. }
  95. /**
  96. * Menu callback; process one time login link and redirects to the user page on success.
  97. */
  98. function user_pass_reset($form, &$form_state, $uid, $timestamp, $hashed_pass, $action = NULL) {
  99. global $user;
  100. // When processing the one-time login link, we have to make sure that a user
  101. // isn't already logged in.
  102. if ($user->uid) {
  103. // The existing user is already logged in. Log them out and reload the
  104. // current page so the password reset process can continue.
  105. if ($user->uid == $uid) {
  106. // Preserve the current destination (if any) and ensure the redirect goes
  107. // back to the current page; any custom destination set in
  108. // hook_user_logout() and intended for regular logouts would not be
  109. // appropriate here.
  110. $destination = array();
  111. if (isset($_GET['destination'])) {
  112. $destination = drupal_get_destination();
  113. }
  114. user_logout_current_user();
  115. unset($_GET['destination']);
  116. drupal_goto(current_path(), array('query' => drupal_get_query_parameters() + $destination));
  117. }
  118. // A different user is already logged in on the computer.
  119. else {
  120. $reset_link_account = user_load($uid);
  121. if (!empty($reset_link_account)) {
  122. drupal_set_message(t('Another user (%other_user) is already logged into the site on this computer, but you tried to use a one-time link for user %resetting_user. Please <a href="!logout">logout</a> and try using the link again.',
  123. array('%other_user' => $user->name, '%resetting_user' => $reset_link_account->name, '!logout' => url('user/logout'))), 'warning');
  124. } else {
  125. // Invalid one-time link specifies an unknown user.
  126. drupal_set_message(t('The one-time login link you clicked is invalid.'), 'error');
  127. }
  128. drupal_goto();
  129. }
  130. }
  131. else {
  132. // Time out, in seconds, until login URL expires. Defaults to 24 hours =
  133. // 86400 seconds.
  134. $timeout = variable_get('user_password_reset_timeout', 86400);
  135. $current = REQUEST_TIME;
  136. // Some redundant checks for extra security ?
  137. $users = user_load_multiple(array($uid), array('status' => '1'));
  138. if ($timestamp <= $current && $account = reset($users)) {
  139. // No time out for first time login.
  140. if ($account->login && $current - $timestamp > $timeout) {
  141. drupal_set_message(t('You have tried to use a one-time login link that has expired. Please request a new one using the form below.'), 'error');
  142. drupal_goto('user/password');
  143. }
  144. elseif ($account->uid && $timestamp >= $account->login && $timestamp <= $current && $hashed_pass == user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid)) {
  145. // First stage is a confirmation form, then login
  146. if ($action == 'login') {
  147. // Set the new user.
  148. $user = $account;
  149. // user_login_finalize() also updates the login timestamp of the
  150. // user, which invalidates further use of the one-time login link.
  151. user_login_finalize();
  152. watchdog('user', 'User %name used one-time login link at time %timestamp.', array('%name' => $account->name, '%timestamp' => $timestamp));
  153. drupal_set_message(t('You have just used your one-time login link. It is no longer necessary to use this link to log in. Please change your password.'));
  154. // Let the user's password be changed without the current password check.
  155. $token = drupal_random_key();
  156. $_SESSION['pass_reset_' . $user->uid] = $token;
  157. drupal_goto('user/' . $user->uid . '/edit', array('query' => array('pass-reset-token' => $token)));
  158. }
  159. else {
  160. $form['message'] = array('#markup' => t('<p>This is a one-time login for %user_name and will expire on %expiration_date.</p><p>Click on this button to log in to the site and change your password.</p>', array('%user_name' => $account->name, '%expiration_date' => format_date($timestamp + $timeout))));
  161. $form['help'] = array('#markup' => '<p>' . t('This login can be used only once.') . '</p>');
  162. $form['actions'] = array('#type' => 'actions');
  163. $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in'));
  164. $form['#action'] = url("user/reset/$uid/$timestamp/$hashed_pass/login");
  165. return $form;
  166. }
  167. }
  168. else {
  169. drupal_set_message(t('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.'), 'error');
  170. drupal_goto('user/password');
  171. }
  172. }
  173. else {
  174. // Deny access, no more clues.
  175. // Everything will be in the watchdog's URL for the administrator to check.
  176. drupal_access_denied();
  177. drupal_exit();
  178. }
  179. }
  180. }
  181. /**
  182. * Menu callback; logs the current user out, and redirects to the home page.
  183. */
  184. function user_logout() {
  185. user_logout_current_user();
  186. drupal_goto();
  187. }
  188. /**
  189. * Logs the current user out.
  190. */
  191. function user_logout_current_user() {
  192. global $user;
  193. watchdog('user', 'Session closed for %name.', array('%name' => $user->name));
  194. module_invoke_all('user_logout', $user);
  195. // Destroy the current session, and reset $user to the anonymous user.
  196. session_destroy();
  197. }
  198. /**
  199. * Process variables for user-profile.tpl.php.
  200. *
  201. * @param array $variables
  202. * An associative array containing:
  203. * - elements: An associative array containing the user information and any
  204. * fields attached to the user. Properties used:
  205. * - #account: The user account of the profile being viewed.
  206. *
  207. * @see user-profile.tpl.php
  208. */
  209. function template_preprocess_user_profile(&$variables) {
  210. $account = $variables['elements']['#account'];
  211. // Helpful $user_profile variable for templates.
  212. foreach (element_children($variables['elements']) as $key) {
  213. $variables['user_profile'][$key] = $variables['elements'][$key];
  214. }
  215. // Preprocess fields.
  216. field_attach_preprocess('user', $account, $variables['elements'], $variables);
  217. }
  218. /**
  219. * Process variables for user-profile-item.tpl.php.
  220. *
  221. * The $variables array contains the following arguments:
  222. * - $element
  223. *
  224. * @see user-profile-item.tpl.php
  225. */
  226. function template_preprocess_user_profile_item(&$variables) {
  227. $variables['title'] = $variables['element']['#title'];
  228. $variables['value'] = $variables['element']['#markup'];
  229. $variables['attributes'] = '';
  230. if (isset($variables['element']['#attributes'])) {
  231. $variables['attributes'] = drupal_attributes($variables['element']['#attributes']);
  232. }
  233. }
  234. /**
  235. * Process variables for user-profile-category.tpl.php.
  236. *
  237. * The $variables array contains the following arguments:
  238. * - $element
  239. *
  240. * @see user-profile-category.tpl.php
  241. */
  242. function template_preprocess_user_profile_category(&$variables) {
  243. $variables['title'] = check_plain($variables['element']['#title']);
  244. $variables['profile_items'] = $variables['element']['#children'];
  245. $variables['attributes'] = '';
  246. if (isset($variables['element']['#attributes'])) {
  247. $variables['attributes'] = drupal_attributes($variables['element']['#attributes']);
  248. }
  249. }
  250. /**
  251. * Form builder; edit a user account or one of their profile categories.
  252. *
  253. * @ingroup forms
  254. * @see user_account_form()
  255. * @see user_account_form_validate()
  256. * @see user_profile_form_validate()
  257. * @see user_profile_form_submit()
  258. * @see user_cancel_confirm_form_submit()
  259. */
  260. function user_profile_form($form, &$form_state, $account, $category = 'account') {
  261. global $user;
  262. // During initial form build, add the entity to the form state for use during
  263. // form building and processing. During a rebuild, use what is in the form
  264. // state.
  265. if (!isset($form_state['user'])) {
  266. $form_state['user'] = $account;
  267. }
  268. else {
  269. $account = $form_state['user'];
  270. }
  271. // @todo Legacy support. Modules are encouraged to access the entity using
  272. // $form_state. Remove in Drupal 8.
  273. $form['#user'] = $account;
  274. $form['#user_category'] = $category;
  275. if ($category == 'account') {
  276. user_account_form($form, $form_state);
  277. // Attach field widgets.
  278. $langcode = entity_language('user', $account);
  279. field_attach_form('user', $account, $form, $form_state, $langcode);
  280. }
  281. $form['actions'] = array('#type' => 'actions');
  282. $form['actions']['submit'] = array(
  283. '#type' => 'submit',
  284. '#value' => t('Save'),
  285. );
  286. if ($category == 'account') {
  287. $form['actions']['cancel'] = array(
  288. '#type' => 'submit',
  289. '#value' => t('Cancel account'),
  290. '#submit' => array('user_edit_cancel_submit'),
  291. '#access' => $account->uid > 1 && (($account->uid == $user->uid && user_access('cancel account')) || user_access('administer users')),
  292. );
  293. }
  294. $form['#validate'][] = 'user_profile_form_validate';
  295. // Add the final user profile form submit handler.
  296. $form['#submit'][] = 'user_profile_form_submit';
  297. return $form;
  298. }
  299. /**
  300. * Form validation handler for user_profile_form().
  301. *
  302. * @see user_profile_form_submit()
  303. */
  304. function user_profile_form_validate($form, &$form_state) {
  305. entity_form_field_validate('user', $form, $form_state);
  306. }
  307. /**
  308. * Form submission handler for user_profile_form().
  309. *
  310. * @see user_profile_form_validate()
  311. */
  312. function user_profile_form_submit($form, &$form_state) {
  313. $account = $form_state['user'];
  314. $category = $form['#user_category'];
  315. // Remove unneeded values.
  316. form_state_values_clean($form_state);
  317. // Before updating the account entity, keep an unchanged copy for use with
  318. // user_save() later. This is necessary for modules implementing the user
  319. // hooks to be able to react on changes by comparing the values of $account
  320. // and $edit.
  321. $account_unchanged = clone $account;
  322. entity_form_submit_build_entity('user', $account, $form, $form_state);
  323. // Populate $edit with the properties of $account, which have been edited on
  324. // this form by taking over all values, which appear in the form values too.
  325. $edit = array_intersect_key((array) $account, $form_state['values']);
  326. user_save($account_unchanged, $edit, $category);
  327. $form_state['values']['uid'] = $account->uid;
  328. if ($category == 'account' && !empty($edit['pass'])) {
  329. // Remove the password reset tag since a new password was saved.
  330. unset($_SESSION['pass_reset_'. $account->uid]);
  331. }
  332. // Clear the page cache because pages can contain usernames and/or profile information:
  333. cache_clear_all();
  334. drupal_set_message(t('The changes have been saved.'));
  335. }
  336. /**
  337. * Submit function for the 'Cancel account' button on the user edit form.
  338. */
  339. function user_edit_cancel_submit($form, &$form_state) {
  340. $destination = array();
  341. if (isset($_GET['destination'])) {
  342. $destination = drupal_get_destination();
  343. unset($_GET['destination']);
  344. }
  345. // Note: We redirect from user/uid/edit to user/uid/cancel to make the tabs disappear.
  346. $form_state['redirect'] = array("user/" . $form['#user']->uid . "/cancel", array('query' => $destination));
  347. }
  348. /**
  349. * Form builder; confirm form for cancelling user account.
  350. *
  351. * @ingroup forms
  352. * @see user_edit_cancel_submit()
  353. */
  354. function user_cancel_confirm_form($form, &$form_state, $account) {
  355. global $user;
  356. $form['_account'] = array('#type' => 'value', '#value' => $account);
  357. // Display account cancellation method selection, if allowed.
  358. $admin_access = user_access('administer users');
  359. $can_select_method = $admin_access || user_access('select account cancellation method');
  360. $form['user_cancel_method'] = array(
  361. '#type' => 'item',
  362. '#title' => ($account->uid == $user->uid ? t('When cancelling your account') : t('When cancelling the account')),
  363. '#access' => $can_select_method,
  364. );
  365. $form['user_cancel_method'] += user_cancel_methods();
  366. // Allow user administrators to skip the account cancellation confirmation
  367. // mail (by default), as long as they do not attempt to cancel their own
  368. // account.
  369. $override_access = $admin_access && ($account->uid != $user->uid);
  370. $form['user_cancel_confirm'] = array(
  371. '#type' => 'checkbox',
  372. '#title' => t('Require e-mail confirmation to cancel account.'),
  373. '#default_value' => ($override_access ? FALSE : TRUE),
  374. '#access' => $override_access,
  375. '#description' => t('When enabled, the user must confirm the account cancellation via e-mail.'),
  376. );
  377. // Also allow to send account canceled notification mail, if enabled.
  378. $default_notify = variable_get('user_mail_status_canceled_notify', FALSE);
  379. $form['user_cancel_notify'] = array(
  380. '#type' => 'checkbox',
  381. '#title' => t('Notify user when account is canceled.'),
  382. '#default_value' => ($override_access ? FALSE : $default_notify),
  383. '#access' => $override_access && $default_notify,
  384. '#description' => t('When enabled, the user will receive an e-mail notification after the account has been cancelled.'),
  385. );
  386. // Prepare confirmation form page title and description.
  387. if ($account->uid == $user->uid) {
  388. $question = t('Are you sure you want to cancel your account?');
  389. }
  390. else {
  391. $question = t('Are you sure you want to cancel the account %name?', array('%name' => $account->name));
  392. }
  393. $description = '';
  394. if ($can_select_method) {
  395. $description = t('Select the method to cancel the account above.');
  396. foreach (element_children($form['user_cancel_method']) as $element) {
  397. unset($form['user_cancel_method'][$element]['#description']);
  398. }
  399. }
  400. else {
  401. // The radio button #description is used as description for the confirmation
  402. // form.
  403. foreach (element_children($form['user_cancel_method']) as $element) {
  404. if ($form['user_cancel_method'][$element]['#default_value'] == $form['user_cancel_method'][$element]['#return_value']) {
  405. $description = $form['user_cancel_method'][$element]['#description'];
  406. }
  407. unset($form['user_cancel_method'][$element]['#description']);
  408. }
  409. }
  410. // Always provide entity id in the same form key as in the entity edit form.
  411. $form['uid'] = array('#type' => 'value', '#value' => $account->uid);
  412. return confirm_form($form,
  413. $question,
  414. 'user/' . $account->uid,
  415. $description . ' ' . t('This action cannot be undone.'),
  416. t('Cancel account'), t('Cancel'));
  417. }
  418. /**
  419. * Submit handler for the account cancellation confirm form.
  420. *
  421. * @see user_cancel_confirm_form()
  422. * @see user_multiple_cancel_confirm_submit()
  423. */
  424. function user_cancel_confirm_form_submit($form, &$form_state) {
  425. global $user;
  426. $account = $form_state['values']['_account'];
  427. // Cancel account immediately, if the current user has administrative
  428. // privileges, no confirmation mail shall be sent, and the user does not
  429. // attempt to cancel the own account.
  430. if (user_access('administer users') && empty($form_state['values']['user_cancel_confirm']) && $account->uid != $user->uid) {
  431. user_cancel($form_state['values'], $account->uid, $form_state['values']['user_cancel_method']);
  432. $form_state['redirect'] = 'admin/people';
  433. }
  434. else {
  435. // Store cancelling method and whether to notify the user in $account for
  436. // user_cancel_confirm().
  437. $edit = array(
  438. 'user_cancel_method' => $form_state['values']['user_cancel_method'],
  439. 'user_cancel_notify' => $form_state['values']['user_cancel_notify'],
  440. );
  441. $account = user_save($account, $edit);
  442. _user_mail_notify('cancel_confirm', $account);
  443. drupal_set_message(t('A confirmation request to cancel your account has been sent to your e-mail address.'));
  444. watchdog('user', 'Sent account cancellation request to %name %email.', array('%name' => $account->name, '%email' => '<' . $account->mail . '>'), WATCHDOG_NOTICE);
  445. $form_state['redirect'] = "user/$account->uid";
  446. }
  447. }
  448. /**
  449. * Helper function to return available account cancellation methods.
  450. *
  451. * See documentation of hook_user_cancel_methods_alter().
  452. *
  453. * @return
  454. * An array containing all account cancellation methods as form elements.
  455. *
  456. * @see hook_user_cancel_methods_alter()
  457. * @see user_admin_settings()
  458. * @see user_cancel_confirm_form()
  459. * @see user_multiple_cancel_confirm()
  460. */
  461. function user_cancel_methods() {
  462. $methods = array(
  463. 'user_cancel_block' => array(
  464. 'title' => t('Disable the account and keep its content.'),
  465. 'description' => t('Your account will be blocked and you will no longer be able to log in. All of your content will remain attributed to your user name.'),
  466. ),
  467. 'user_cancel_block_unpublish' => array(
  468. 'title' => t('Disable the account and unpublish its content.'),
  469. 'description' => t('Your account will be blocked and you will no longer be able to log in. All of your content will be hidden from everyone but administrators.'),
  470. ),
  471. 'user_cancel_reassign' => array(
  472. 'title' => t('Delete the account and make its content belong to the %anonymous-name user.', array('%anonymous-name' => variable_get('anonymous', t('Anonymous')))),
  473. 'description' => t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', array('%anonymous-name' => variable_get('anonymous', t('Anonymous')))),
  474. ),
  475. 'user_cancel_delete' => array(
  476. 'title' => t('Delete the account and its content.'),
  477. 'description' => t('Your account will be removed and all account information deleted. All of your content will also be deleted.'),
  478. 'access' => user_access('administer users'),
  479. ),
  480. );
  481. // Allow modules to customize account cancellation methods.
  482. drupal_alter('user_cancel_methods', $methods);
  483. // Turn all methods into real form elements.
  484. $default_method = variable_get('user_cancel_method', 'user_cancel_block');
  485. foreach ($methods as $name => $method) {
  486. $form[$name] = array(
  487. '#type' => 'radio',
  488. '#title' => $method['title'],
  489. '#description' => (isset($method['description']) ? $method['description'] : NULL),
  490. '#return_value' => $name,
  491. '#default_value' => $default_method,
  492. '#parents' => array('user_cancel_method'),
  493. );
  494. }
  495. return $form;
  496. }
  497. /**
  498. * Menu callback; Cancel a user account via e-mail confirmation link.
  499. *
  500. * @see user_cancel_confirm_form()
  501. * @see user_cancel_url()
  502. */
  503. function user_cancel_confirm($account, $timestamp = 0, $hashed_pass = '') {
  504. // Time out in seconds until cancel URL expires; 24 hours = 86400 seconds.
  505. $timeout = 86400;
  506. $current = REQUEST_TIME;
  507. // Basic validation of arguments.
  508. if (isset($account->data['user_cancel_method']) && !empty($timestamp) && !empty($hashed_pass)) {
  509. // Validate expiration and hashed password/login.
  510. if ($timestamp <= $current && $current - $timestamp < $timeout && $account->uid && $timestamp >= $account->login && $hashed_pass == user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid)) {
  511. $edit = array(
  512. 'user_cancel_notify' => isset($account->data['user_cancel_notify']) ? $account->data['user_cancel_notify'] : variable_get('user_mail_status_canceled_notify', FALSE),
  513. );
  514. user_cancel($edit, $account->uid, $account->data['user_cancel_method']);
  515. // Since user_cancel() is not invoked via Form API, batch processing needs
  516. // to be invoked manually and should redirect to the front page after
  517. // completion.
  518. batch_process('');
  519. }
  520. else {
  521. drupal_set_message(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), 'error');
  522. drupal_goto("user/$account->uid/cancel");
  523. }
  524. }
  525. return MENU_ACCESS_DENIED;
  526. }
  527. /**
  528. * Page callback: Displays the user page.
  529. *
  530. * Displays user profile if user is logged in, or login form for anonymous
  531. * users.
  532. *
  533. * @return
  534. * A render array for either a user profile or a login form.
  535. *
  536. * @see user_view_page()
  537. * @see user_login()
  538. */
  539. function user_page() {
  540. global $user;
  541. if ($user->uid) {
  542. menu_set_active_item('user/' . $user->uid);
  543. return menu_execute_active_handler(NULL, FALSE);
  544. }
  545. else {
  546. return drupal_get_form('user_login');
  547. }
  548. }