diff options
author | Dries Buytaert <dries@buytaert.net> | 2003-05-29 09:15:00 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2003-05-29 09:15:00 +0000 |
commit | 8d2b1238b4d8ebd57848fde665b7f93c3a03cd90 (patch) | |
tree | 8f6c64926b931489dd73f3075aad2ffd549009da /modules/user/user.module | |
parent | 3cebcdf636f7eb47d6304a48057b34ddbaf43f04 (diff) | |
download | brdo-8d2b1238b4d8ebd57848fde665b7f93c3a03cd90.tar.gz brdo-8d2b1238b4d8ebd57848fde665b7f93c3a03cd90.tar.bz2 |
- Michael Frankowski's excellent help text improvements!
Diffstat (limited to 'modules/user/user.module')
-rw-r--r-- | modules/user/user.module | 392 |
1 files changed, 125 insertions, 267 deletions
diff --git a/modules/user/user.module b/modules/user/user.module index ac6666a20..acb08673b 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -6,6 +6,7 @@ session_start(); function user_system($field){ $system["description"] = t("Enables the user registration and login system."); +- $system["admin_help"] = t("In order to use the full power of Drupal a vistor must sign up for an account. This page lets you setup how a user signs up, logs out, what password \"words\" the system uses, the guidelines from the system about user subscriptions, and the E-Mails the system will send to the user."); return $system[$field]; } @@ -408,33 +409,39 @@ function user_link($type) { } if ($type == "admin" && user_access("administer users")) { - $help["user"] = "Drupal allows users to register, login, logout, maintain user profiles, etc. No participant can use his own name to post content until he signs up for a user account. There are several configuration pages that help administrators manage user accounts."; - $help["create"] = "If your site is completely private, and doesn't allow public registration, then you can add new users manually. This web page allows administrator to register a new users."; - $help["view"] = "This page allows you to review and edit any user's profile."; - $help["access"] = "Access rules enable administrators to filter out usernames and e-mail addresses which are not allowed in Drupal. An administrator creates a 'mask' against which each new registration is checked. Disallowed names and e-mail addresses are denied access to the site."; - $help["permission"] = "Each user role has certain things that its users are allowed to do, and some that are disallowed. For example, authenticated users may usually post a story but anonymous users may not. Each permission describes a fine-grained logical operation such as access administration pages or add and modify user accounts. You could say a permission represents access granted to a user to perform a set of operations."; - $help["role"] = "Roles allow you to fine tune the security and administration of drupal. A role defines a group of users which have certain privileges. Examples of roles include: anonymous user, authenticated user, moderator, administrator and so on. By default, Drupal comes with two user roles: <ul><li>Anonymous user: this role is used for users that don't have a user account or that are not authenticated.</li><li>Registered user: this role is assigned automatically to authenticated users. Most registered users will belong to this user role unless specified otherwise.</li></ul>"; - $help["search"] = "On this page you can query any username. For example, one may search for 'br' and Drupal might return 'brian', 'brad', and 'brenda'."; - $help["setting"] = "Administrators may choose to restrict registration to their site. That restriction may be accomplished on this page. Also, the list of words which may be included in a system generated password is also listed on this page. Drupal generates passwords by joining small words from the password list until the new password is greater than 6 characters."; +- $help["user"] = t("Drupal allows users to register, login, logout, maintain user profiles, etc. No participant can use his own name to post content until he signs up for a user account.<br />Click on either the \"username\" or \"edit account\" to edit a user's information."); +- $help["create"] = t("This web page allows the administrators to register a new users by hand.<br />Note:<ul><li>You cannot have a user where either the E-Mail address or the username match another user in the system</li></ul>"); +- $help["view"] = t("This page allows you to review and edit any user's profile. To edit a profile click on either the \"username\" or \"edit account\"."); +- $help["view-active"] = t("This page allows you to review and edit an active user's profile. To edit a profile click on either the \"username\" or \"edit account\"."); +- $help["view-new"] = t("This page allows you to review and edit a new user's profile. To edit a profile click on either the \"username\" or \"edit account\"."); +- $help["view-block"] = t("This page allows you to review and edit a blocked user's profile. To edit a profile click on either the \"username\" or \"edit account\"."); +- $help["view-role"] = "This page allows you to review and edit a user with role '%role's profile. To edit a profile click on either the \"username\" or \"edit account\"."; +- $help["access-overview"] = t("Access rules allow Drupal administrators to choose usernames and E-Mail address that are prevented from using drupal. To enter the mask for E-Mail addresses click on <a href=\"%e-mail\">e-mail rules</a>, for the username mask click on <a href=\"%username\">username rules</a>", array("%e-mail" => url("admin/user/access/mail"), "%username" => url("admin/user/access/user"))); +- $help["access-email"] = t("Setup and test the E-Mail access rules. The access function checks if you match a deny and <b>not</b> an allow. If you match <b>only</b> a deny then it is denied. Any other case, such as both a deny and an allow pattern matching, allows the pattern.<br />Notes: <ul><li>To delete a rule click on \"delete rule\".</li><li>The order of the rules does <b>not</b> matter.</li></ul>"); +- $help["access-name"] = t("Setup and test the Username access rules. The access function checks if you match a deny and <b>not</b> an allow. If you do then it is denied. Any other case, such as a deny pattern and an allow pattern, allows the pattern.<br />Notes: <ul><li>To delete a rule click on \"delete rule\".</li><li>The order of the rules does <b>not</b> matter.</li></ul>"); +- $help["permission"] = t("In this area you will define the <b>permissions</b> for each user role (Role names are defined in <a href=\"%role\">user roles</a>). Each permission describes a fine-grained logical operation, such as being able to access the administration pages, or adding/modifing a user account. You could say a permission represents access granted to a user to perform a set of operations.", array("%role" => url("admin/user/role"))); +- $help["role"] = t("Roles allow you to fine tune the security and administration of drupal. A role defines a group of users that have certain privileges as defined in <a href=\"%permission\">user permissions</a>. Examples of roles include: anonymous user, authenticated user, moderator, administrator and so on. In this area you will define the <b>names</b> of the various roles. To delete a role choose \"edit role\"<br />By default, Drupal comes with two user roles: <ul><li>Anonymous user: this role is used for users that don't have a user account or that are not authenticated.</li><li>Authenticated user: this role is assigned automatically to authenticated users. Most registered users will belong to this user role unless specified otherwise.</li></ul>", array("%permission" => url("admin/user/permission"))); +- $help["search"] = t("Enter a simple pattern ( '*' may be user as a wildcard match) to search for a username. For example, one may search for 'br' and Drupal might return 'brian', 'brad', and 'brenda'."); menu("admin/user", "user management", "user_admin", $help["user"], 2); menu("admin/user/create", "create new account", "user_admin", $help["create"], 1); menu("admin/user/account", "view user accounts", "user_admin", $help["view"], 2); - menu("admin/user/access", "access rules", NULL, $help["access"], 3); - menu("admin/user/access/mail", "e-mail rules", "user_admin", $help["access"]); - menu("admin/user/access/user", "username rules", "user_admin", $help["access"]); + menu("admin/user/access", "access rules", NULL, $help["access-overview"], 3); + menu("admin/user/access/mail", "e-mail rules", "user_admin", $help["access-email"]); + menu("admin/user/access/user", "username rules", "user_admin", $help["access-name"]); menu("admin/user/role", "user roles", "user_admin", $help["role"], 4); menu("admin/user/permission", "user permissions", "user_admin", $help["permission"], 5); menu("admin/user/search", "search accounts", "user_admin", $help["search"], 8); menu("admin/user/help", "help", "user_help", NULL, 9); menu("admin/user/edit", "edit user account", "user_admin", NULL, 0, 1); // hidden menu - menu("admin/user/account/0", "active users", "user_admin", $help["view"], 1); - menu("admin/user/account/1", "new users", "user_admin", $help["view"], 2); - menu("admin/user/account/2", "blocked users", "user_admin", $help["view"], 3); + menu("admin/user/account/0", "active users", "user_admin", $help["view-active"], 1); + menu("admin/user/account/1", "new users", "user_admin", $help["view-new"], 2); + menu("admin/user/account/2", "blocked users", "user_admin", $help["view-block"], 3); $i = 3; foreach (user_roles(1) as $key => $value) { - menu("admin/user/account/". $i++, "users with role '$value'", "user_admin", $help["view"], 4); + $help_msg = t($help["view-role"], array("%role" => $value)); + menu("admin/user/account/". $i++, "users with role '$value'", "user_admin", $help_msg, 4); } } @@ -710,7 +717,7 @@ function user_pass($edit = array()) { $variables = array("%username" => $account->name, "%site" => variable_get("site_name", "drupal"), "%password" => $pass, "%uri" => $base_url, "%uri_brief" => substr($base_url, strlen("http://")), "%mailto" => $account->mail, "%date" => format_date(time())); $subject = strtr(variable_get("user_mail_pass_subject", t("Replacement login information for %username at %site")), $variables); - $body = strtr(variable_get("user_mail_pass_body", t("%username,\n\nHere is your new password for %site. You may now login to ". url("user/login") ." using the following username and password:\n\nusername: %username\npassword: %password\n\nAfter logging in, you may wish to change your password at ". url("user/edit") .".\n\nYour new %site membership also enables you to login to other Drupal powered websites (e.g. http://www.drop.org/) without registering. Just use the following Drupal ID and password:\n\nDrupal ID: %username@%uri_brief\npassword: %password\n\n\n-- %site team")), $variables); + $body = strtr(variable_get("user_mail_pass_body", t("%username,\n\nHere is your new password for %site. You may now login to ". url("user/login") ." using the following username and password:\n\nusername: %username\npassword: %password\n\nAfter logging in, you may wish to change your password at ". url("user/edit") .".\n\nYour new %site membership also enables you to login to other Drupal powered web sites (e.g. http://www.drop.org/) without registering. Just use the following Drupal ID and password:\n\nDrupal ID: %username@%uri_brief\npassword: %password\n\n\n-- %site team")), $variables); $headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from"; user_mail($account->mail, $subject, $body, $headers); @@ -1616,304 +1623,155 @@ function user_help_users_da() { // the following functions comprise help for admins and developers function user_help() { - user_help_admin(); - user_help_admin_da(); - user_help_devel_da(); - user_help_devel_userhook(); + $output .= user_help_admin(); + $output .= user_help_admin_da(); + $output .= user_help_devel_da(); + $output .= user_help_devel_userhook(); + return t($output); } function user_help_admin() { - ?> -<h3>Introduction</h3> -<p>Drupal offers a powerful and open user system. This system allows users to - register, login, logout, maintain user profiles, etc. No participant can use - his own name to post comments until he signs up and submits his e-mail address. - Those who do not register may participate as anonymous users, but they will - suffer numerous disadvantages, for example their posts beginning at a lower - score. </p> -<p>In contrast, those with a user account can use their own name or handle and - are granted various privileges: the most important are probably the ability - to moderate new submissions, to rate comments, and to fine-tune the site to - their personal liking. Drupal themes make fine tuning quite a pleasure.</p> -<p>Registered users need to authenticate by supplying a username and password. - Users may authenticate locally or via an external authentication source like - <a href="http://www.jabber.org/">Jabber</a>, <a href="http://www.delphiforums.com/">Delphi</a>, - and other <a href="http://www.drupal.org/">Drupal</a> websites. See <a href="#da">distributed - authentication</a> for more information on this innovative feature. The username - and password are kept in your database, where the password is hashed so that - no one can read nor use it. When a username and password needs to be checked - the system goes down the list of registered users until it finds a matching - username, and then hashes the password that was supplied and compares it to - the listed value. If the hashes match, the username and password are correct. - Once a user authenticated session is started, and until that session is over, - the user won't have to re-authenticate. To keep track of the individual sessions, - Drupal relies on <a href="http://www.php.net/manual/en/ref.session.php">PHP's - session support</a>. A visitor accessing your website is assigned an unique - ID, the so-called session ID, which is stored in a cookie. For security's sake, - the cookie does not contain personal information but acts as a key to retrieve - the information stored on your server's side. When a visitor accesses your site, - Drupal will check whether a specific session ID has been sent with the request. - If this is the case, the prior saved environment is recreated.</p> -<p>Authenticated users can select entirely different appearances for the site, - utilizing their own preferences for how the pages are structured, how navigation - lists and other page components are presented and much more. <br /> -</p> -<h3>User preferences and profiles</h3> -<p>Drupal comes with a set of user preferences and profile which a user may edit by - clicking on the user account link. Of course, a user must be logged into reach those pages. - There, users will find a page for changing their preferred time zone, language, username, e-mail address, password, theme, signature, homepage, and <a href="#da">distributed authentication</a> names. - Changes made here take effect immediately. Also, administrators may make profile and preferences changes in the Admin Center on behalf of their users.</p> - <p>Module developers are provided several hooks for adding custom fields to the user view/edit pages. These hooks are described in the Developer section of the <a href="http://www.drupal.org">Drupal Handbook</a>. For an example, see the <code>jabber_user()</code> function in <i>/modules/jabber.module</i>. -</p> - <?php + $output .= "<h3>Introduction</h3><p>Drupal offers a powerful access system that allows users to register, login, logout, maintain user profiles, etc. By using \"". l ("roles", "admin/user/role") ."\" you can setup fine grained ". l("permissions", "admin/user/permission") ." allowing each role to do only what you want them to. Each user is assigned to a role. By default there are two roles \"anonymous\" - a user who has not logged in, and \"authorized\" a user who has signed up and who has been authorized. As anonymous users, participants suffer numerous disadvantages, for example they cannot sign their names to nodes, and their moderated posts beginning at a lower score.</p>"; + $output .= "<p>In contrast, those with a user account can use their own name or handle and are granted various privileges: the most important is probably the ability to moderate new submissions, to rate comments, and to fine-tune the site to their personal liking, with saved personal settings. Drupal themes make fine tuning quite a pleasure.</p>"; + $output .= "<p>Registered users need to authenticate by supplying either a local username and password, or a remote username and password such as a ". l("jabber", "www.jabber.org") .", ". l("Delphi", "www.delphiforums.com") .", or one from another ". l("Drupal", "www.drupal.org") ." website. See ". l("distributed authentication", "#da") ." for more information on this innovative feature."; + $output .= "The local username and password, hashed with Message Digest 5 (MD5), are stored in your database. When you enter a password it is also hashed with MD5 and compaired with what is in the database. If the hashes match, the username and password are correct. Once a user authenticated session is started, and until that session is over, the user won't have to re-authenticate. To keep track of the individual sessions, Drupal relies on ". l("PHP's session support", "www.php.net/manual/en/ref.session.php") .". A visitor accessing your website is assigned an unique ID, the so-called session ID, which is stored in a cookie. For security's sake, the cookie does not contain personal information but acts as a key to retrieve the information stored on your server's side. When a visitor accesses your site, Drupal will check whether a specific session ID has been sent with the request. If this is the case, the prior saved environment is recreated.</p>"; + $output .= "<h3>User preferences and profiles</h3><p>Each Drupal user has a profile, and a set of preferences which may be edited by clicking on the ". l("user account", "user") ." link. Of course, a user must be logged into reach those pages. There, users will find a page for changing their preferred time zone, language, username, e-mail address, password, theme, signature, homepage, and ". l("distributed authentication", "#da") ." names. Changes made here take effect immediately. Also, administrators may make profile and preferences changes in the ". l("Admin Center", "admin/user") ." on behalf of their users.</p>"; + $output .= "<p>Module developers are provided several hooks for adding custom fields to the user view/edit pages. These hooks are described in the Developer section of the ". l("Drupal Handbook", "drupal.org/node/view/316") .". For an example, see the <code>jabber_user()</code> function in <i>/modules/jabber.module</i>.</p>"; + return $output; } function user_help_admin_da() { -?> -<h3>Distributed authentication<a name="da"> </a></h3> -<p>One of the more tedious moments in visiting a new website is filling out the - registration form. The reg form provides helpful information to the website - owner, but not much value for the user. The value for the end user is usually - a the ability to post a messages or receive personalized news, etc. Distributed - authentication (DA) gives the user what he wants without having to fill out - the reg form. Removing this obstacle yields more registered and active users - for the website.</p> -<p>DA enables a new user to input a username and password into the login box and - immediately be recognized, even if that user never registered on your site. - This works because Drupal knows how to communicate with external registration - databases. For example, lets say that your new user 'Joe' is already a registered - member of Delphi Forums. If your Drupal has delphi.module installed, then Drupal - will inform Joe on the registration and login screens that he may login with - his Delphi ID instead of registering with your Drupal instance. Joe likes that - idea, and logs in with a username of joe@remote.delphiforums.com and his usual - Delphi password. Drupal then communicates with remote.delphiforums.com (usually using <a href="http://www.xmlrpc.com/">XML-RPC</a>, - <a href="http://www.w3.org/Protocols/">HTTP POST</a>, or <a href="http://www.soapware.org/">SOAP</a>) behind - the scenes and asks "is this password for username=joe? If Delphi replies - yes, then Drupal will create a new local account for joe and log joe into it. - Joe may keep on logging into your Drupal instance in the same manner, and he - will be logged into the same joe@remote.delphiforums.com account.</p> -<p>One key element of DA is the 'authmap' table, which maps a user's authname - (e.g. joe@remote.delphiforums.com) to his local UID (i.e. universal identification - number). This map is checked whenever a user successfully logs into an external - authentication source. Once Drupal knows that the current user is definately - joe@remote.delphiforums.com (because Delphi says so), he looks up Joe's UID - and logs Joe into that account.</p> -<p>To disable distributed authentication, simply disable or remove all DA modules. For a virgin -install, that means removing/disabling <i>jabber.module</i> and <i>drupal.module</i> -</p> -<p>Drupal is setup so that it is very easy to add support for any external authentication - source. You currently have the following authentication modules installed ...</p> - <?php + $output .= "<h3>Distributed authentication<a name=\"da\"> </a></h3><p>One of the more tedious moments in visiting a new website is filling out the registration form. The reg form provides helpful information to the website owner, but not much value for the user. The value for the end user is usually the ability to post a messages or receive personalized news, etc. Distributed authentication (DA) gives the user what they want without having to fill out the reg form. Removing this obstacle yields more registered and active users for the website.</p>"; + $output .= "<p>DA enables a new user to input a username and password into the login box and immediately be recognized, even if that user never registered on your site. This works because Drupal knows how to communicate with external registration databases. For example, lets say that your new user 'Joe' is already a registered member of Delphi Forums. If your Drupal has delphi.module installed, then Drupal will inform Joe on the registration and login screens that he may login with his Delphi ID instead of registering with your Drupal instance. Joe likes that idea, and logs in with a username of joe@remote.delphiforums.com and his usual Delphi password. Drupal then communicates with remote.delphiforums.com (usually using ". l("XML-RPC","www.xmlrpc.com") ." ". l("HTTP POST", "www.w3.org/Protocols/") .", or ". l("SOAP", "www.soapware.org") .") behind the scenes and asks "is this password for username=joe?" If Delphi replies yes, then Drupal will create a new local account for joe and log joe into it. Joe may keep on logging into your Drupal instance in the same manner, and he will be logged into the same joe@remote.delphiforums.com account.</p>"; + $output .= "<p>One key element of DA is the 'authmap' table, which maps a user's authname (e.g. joe@remote.delphiforums.com) to his local UID (i.e. universal identification number). This map is checked whenever a user successfully logs into an external authentication source. Once Drupal knows that the current user is definately joe@remote.delphiforums.com (because Delphi says so), he looks up Joe's UID and logs Joe into that account.</p>"; + $output .= "<p>To disable distributed authentication, simply ". l("disable", "admin/system/modules") ." or remove all DA modules. For a virgin install, that means removing/disabling <i>jabber.module</i> and <i>drupal.module</i></p>"; + $output .= "<p>Drupal is setup so that it is very easy to add support for any external authentication source. You currently have the following authentication modules installed ...</p>"; + foreach (module_list() as $module) { if (module_hook($module, "auth")) { - print "<h4>" . module_invoke($module, "info", "name") . "</h4>"; - print module_invoke($module, "auth_help"); + $output .= "<h4>" . module_invoke($module, "info", "name") . "</h4>"; + $output .= module_invoke($module, "auth_help"); } } + return $output; } function user_help_devel_da() { - ?> - <h3>Writing distributed authentication modules</h3> -<p>Drupal is specifically architected to enable easy authoring of new authentication - modules. I'll deconstruct the <a href="http://www.blogger.com">Blogger</a> authentication - module here, and hopefully provide all the details you'll need to write a new - auth module. If you want to download the full text of this module, visit the - <a href="http://cvs.drupal.org/viewcvs.cgi/contributions/modules/authentication/Blogger/?cvsroot=contrib">Drupal contributions CVS repository</a>.</p> -<h4>Code review</h4> -<pre><?php</pre> -<p>The first line of every authentication module is the same. It is the standard - processing instruction for any PHP file. Authentication modules are always written - in PHP, although they typically interact with systems written in many different - programming languages and operating systems languages.</p> -<pre>function blogger_info($field = NULL) { - $info["name"] = "Blogger"; - $info["protocol"] = "XML-RPC"; - $info["link"] = l("Blogger", "user/help#blogger"); - $info["maintainer"] = "Moshe Weitzman"; - $info["maintaineremail"] = "weitzman at tejasa.com"; - - if ($field) { - return $info[$field]; - } - else { - return $info; - } -}</pre> -<p>The <i>_info</i> function is always the first function defined in your module. - This function populates an array called <i>$info</i> with various pieces of - data. Some of this data is used by Drupal ("name", "link"), - and some of it just informs the users of your module. Your goal is to simply - copy the b<i>logger_info</i> function in your module - but wherever it says - <i>blogger</i> here, substitute your own module name.</p> -<pre>function blogger_auth($name, $pass, $server) { - if ($server !== "blogger.com") { - return 0; // user did not present a Blogger ID so don't bother trying. - } - - $appkey = "6D4A2D6811A6E1F75148DC1155D33C0C958107BC"; //provided to Drupal by Ev@Blogger - $message = new xmlrpcmsg("blogger.getUsersBlogs", array(new xmlrpcval($appkey, "string"), new xmlrpcval($name, "string"), new xmlrpcval($pass, "string"))); - $client = new xmlrpc_client("/api/RPC2", "plant.blogger.com"); - $result = $client->send($message, 5); - + $output .= "<h3>Writing distributed authentication modules</h3><p>Drupal is specifically architected to enable easy authoring of new authentication modules. I'll deconstruct the ". l("Blogger", "www.blogger.com") ." authentication module, and hopefully provide all the details you'll need to write your own auth module. If you want to download the full text of this module, visit the ". l("Blogger source", "cvs.drupal.org/viewcvs.cgi/contributions/modules/authentication/Blogger/?cvsroot=contrib") ." in the ". l("Drupal contributions CVS repository", "cvs.drupal.org/viewcvs/contributions/?cvsroot=contrib") .".</p>"; + $output .= "<h4>Code review</h4><pre><?php</pre><p>The first line of every Drupal module, including the authentication modules, is the same. It is the standard processing instruction for any PHP file. Authentication modules are always written in PHP, although they typically interact with systems written in many different programming languages and operating systems languages.</p>"; + $output .= "<pre>function blogger_info(\$field = NULL) { + \$info[\"name\"] = \"Blogger\"; + \$info[\"protocol\"] = \"XML-RPC\"; + \$info[\"link\"] = \"<a href=\\\"module.php?mod=user&op=sa_help#blogger\\\">Blogger</a>\"; + \$info[\"maintainer\"] = \"Moshe Weitzman\"; + \$info[\"maintaineremail\"] = \"weitzman at tejasa.com\"; + if (\$field) return \$info[\$field]; + else return \$info; +}</pre>"; + $output .= "<p>The <i>_info</i> function is always the first function defined in your module. This function populates an array called <i>\$info</i> with various pieces of data. Some of this data is used by Drupal ("name", "link"), and some of it just informs the users of your module. Simply copy the <i>blogger_info</i> function in your module - but wherever it says <i>blogger</i> here, substitute your own module name.</p>"; + $output .= "<pre>function blogger_auth(\$name, \$pass, \$server) { + if (\$server !== "blogger.com") return 0; // user did not present a Blogger ID so don't bother trying. + + \$appkey = "6D4A2D6811A6E1F75148DC1155D33C0C958107BC"; //provided to Drupal by Ev@Blogger + \$message = new xmlrpcmsg("blogger.getUsersBlogs", array(new xmlrpcval(\$appkey, "string"), new xmlrpcval(\$name, "string"), new xmlrpcval(\$pass, "string"))); + \$client = new xmlrpc_client("/api/RPC2", "plant.blogger.com"); + // \$client->setDebug(1); + \$result = \$client->send(\$message, 5); // Since Blogger doesn't return a properly formed FaultCode, we just search for the string 'fault'. - if ($result && !stristr($result->serialize(), "fault")) { - $result->serialize()); + if (\$result && !stristr(\$result->serialize(), "fault")) { + // watchdog(\"user\", \"Success Blogger Auth. Response: \" . \$result->serialize()); return 1; } - else if ($result) { + else if (\$result) { + // watchdog(\"user\", \"Blogger Auth failure. Response was \" . \$result->serialize()); return 0; } else { + // watchdog(\"user\", \"Blogger Auth failure. Could not connect.\"); return 0; } -}</pre> -<p>The <i>_auth</i> function is the heart of any authentication module. This function - is called whenever a user is attempting to login using your authentication module. - For successful authentications, this function returns TRUE. Otherwise, it returns - FALSE. This function always accepts 3 parameters, as shown above. These parameters - are passed by the user system (user.module). The user system parses the username - as typed by the user into 2 substrings - $name and $server. The parsing rules - are:</p> -<table width="80%" border="0" cellspacing="4" cellpadding="4" align="center"> - <tr> - <th colspan="2" align="left"> - _auth function parameters - </th> - </tr> - <tr> - <th>$name</th> - <td>The substring before the final <i>'@'</i> character in the username field</td> - </tr> - <tr> - <th>$pass</th> - <td>The whole string submitted by the user in the password field</td> - </tr> - <tr> - <th>$server</th> - <td>The substring after the final <i>'@'</i> symbol in the username field</td> - </tr> -</table> -<p>So now lets use that $name, $pass, and $server which has been passed to our - <i>_auth</i> function. Blogger authenticates users via <a href="http://www.xmlrpc.com">XML-RPC</a>. - Your module may authenticate using a different technique. Drupal doesn't reallly - care how your module communicates with its registration source. It just <b>trusts</b> - the module. </p> -<p>The lines above illustrate a typical <a href="http://www.xmlrpc.com/">XML-RPC</a> - method call. Here we build up a message and send it to Blogger, storing the - response in a variable called <i>$response</i>. The message we pass conforms - to the published <a href="http://plant.blogger.com/API">Blogger XML-RPC API</a>. - Your module will no doubt implement a different API. One peculiarity of this - module is that we don't actually use the $server parameter. Blogger only accepts - authentication at <i>plant.blogger.com</i>, so we hard-code that value into - the <i>xmlrpc_client()</i> function. A more typical example might be the jabber - module, which uses the <i>$server</i> parameter to determine where to send the - authentication request. Also of note is the '5' parameter in the <i>$client->send()</i> - call. This is a timeout value in seconds. All authentication modules should - implement a timeout on their external calls. This makes sure to return control - to the user.module if your registration database has become inoperable or unreachable.</p> -<pre> - if ($result && !stristr($result->serialize(), "fault")) { +}</pre>"; + $output .= "<p>The <i>_auth</i> function is the heart of any authentication module. This function is called whenever a user is attempting to login using your authentication module. For successful authentications, this function returns TRUE. Otherwise, it returns FALSE. This function always accepts 3 parameters, as shown above. These parameters are passed by the user system (user.module). The user system parses the username as typed by the user into 2 substrings - \$name and \$server. The parsing rules are:</p>"; + $output .= "<table width=\"80%\" border=\"0\" cellspacing=\"4\" cellpadding=\"4\" align=\"center\"><tr><th colspan=\"2\" align=\"left\">_auth function parameters</th></tr><tr><th>\$name</th><td>The substring before the final <i>'@'</i> character in the username field</td></tr><tr><th>\$pass</th><td>The whole string submitted by the user in the password field</td></tr><tr><th>\$server</th><td>The substring after the final <i>'@'</i> symbol in the username field</td></tr></table>"; + $output .= "<p>So now lets use that \$name, \$pass, and \$server which was passed to our <i>_auth</i> function. Blogger authenticates users via ". l("XML-RPC", "www.xmlrpc.org") .". Your module may authenticate using a different technique. Drupal doesn't reallly care how your module communicates with its registration source. It just <b>trusts</b> the module.</p>"; + $output .= "<p>The lines above illustrate a typical ". l("XML-RPC", "www.xmlrpc.org") ." method call. Here we build up a message and send it to Blogger, storing the response in a variable called <i>\$response</i>. The message we pass conforms to the published ". l("Blogger XML-RPC Application Programmers Interface (API)", "plant.blogger.com/API") .". Your module will no doubt implement a different API. One peculiarity of this module is that we don't actually use the $server parameter. Blogger only accepts authentication at <i>plant.blogger.com</i>, so we hard-code that value into the <i>xmlrpc_client()</i> function. A more typical example might be the jabber module, which uses the <i>\$server</i> parameter to determine where to send the authentication request. Also of note is the '5' parameter in the <i>\$client->send\(\)</i> call. This is a timeout value in seconds. All authentication modules should implement a timeout on their external calls. This makes sure to return control to the user.module if your registration database has become inoperable or unreachable.</p>"; + $output .= "<pre> + if (\$result && !stristr(\$result->serialize(), "fault")) { + // watchdog(\"user\", \"Success Blogger Auth. Response: \" . \$result->serialize()); return 1; } - else if ($result) { + else if (\$result) { + // watchdog(\"user\", \"Blogger Auth failure. Response was \" . \$result->serialize()); return 0; } else { + // watchdog(\"user\", \"Blogger Auth failure. Could not connect.\"); return 0; } -</pre> -<p>This second half of the <i>_auth</i> function examines the <i>$response</i> - from plant.blogger.com and returns a TRUE or FALSE as appropriate. This is a - critical decision, so do be sure you have good logic here, and perform sufficient - testing for all cases. In the case of Blogger, we search for the string 'fault' - in the response. If that string is present, or there is no repsonse, our function - returns FALSE. Otherwise, Blogger has returned valid data to our method request - and we return TRUE. -</p> -<pre>function blogger_page() { +</pre>"; + $output .= "<p>This second half of the <i>_auth</i> function examines the <i>\$response</i> from plant.blogger.com and returns a TRUE (1) or FALSE (0) as appropriate. This is a critical decision, so be sure that you have good logic here, and perform sufficient testing for all cases. In the case of Blogger, we search for the string 'fault' in the response. If that string is present, or there is no repsonse, our function returns FALSE. Otherwise, Blogger has returned valid data to our method request and we return TRUE. Note: Everything starting with \"//\" is a comment and is not executed.</p>"; + $output .= "<pre>function blogger_page() { theme("header"); theme("box", "Blogger", blogger_auth_help()); theme("footer"); -}</pre> -<p>The _page function is not currently used, but it might be in the future. For - now, just copy what you see here, substituting your module name for <i>blogger</i>.</p> -<pre>function blogger_auth_help() { - $site = variable_get("site_name", "this web site"); - $output = " - <p>You may login to <i>%s</i> using a <b>Blogger ID</b> - and password. A Blogger ID consists of your Blogger username followed by <i>@blogger.com</i>. - So a valid blogger ID is mwlily@blogger.com. If you are a Blogger member, go - ahead and login now.</p><br /> - <p>Blogger offers you instant communication power by letting you post - your thoughts to the web whenever the urge strikes. - Blogger will publish to your current web site or help you create one. <a - href=\"http://www.blogger.com/about.pyra\">Learn more about it</a>."; - - return sprintf(t($output), $site); +}</pre>"; + $output .= "<p>The _page function is not currently used, but it might be in the future. For now, just copy what you see here, substituting your module name for <i>blogger</i>.</p>"; + $output .= "<pre>function blogger_auth_help() { + \$site = variable_get("site_name", "this web site"); + \$html_output = " + <p>You may login to <i>%s</i> using a <b>Blogger ID</b> and password. A Blogger ID consists of your Blogger username followed by <i>@blogger.com</i>. So a valid blogger ID is mwlily@blogger.com. If you are a Blogger member, go ahead and login now.</p> + <p>Blogger offers you instant communication power by letting you post your thoughts to the web whenever the urge strikes. + Blogger will publish to your current web site or help you create one. <a href=\"http://www.blogger.com/about.pyra\">Learn more about it</a>."; + return sprintf(t(\$html_output), \$site); } -</pre> -<p>The <i>_auth_help</i> function is prominently linked within Drupal, so you'll - want to write the best possible user help here. You'll want to tell users what - a proper username looks like for your authentication module. Also, you may advertise - a bit about your service at the end. Note that your help text is passed through - a t() function in the last line. This is Drupal's localization function. Translators - may localize your help text just like any other text in Drupal.</p> -<h4>Publishing your module</h4> -<p>Once you've written and tested your authentication module, you'll have to usually - want to share it with the world. The best way to do this is to add the module - to the <a href="http://cvs.drupal.org/viewcvs.cgi/contributions/modules/authentication/Blogger/?cvsroot=contrib">Drupal - contributions CVS repository</a>. You'll need to request priveleges in this repository - see <a href="http://cvs.drupal.org/viewcvs.cgi/contributions/README?rev=HEAD&cvsroot=contrib&content-type=text/vnd.viewcvs-markup">README</a> - for the details. Then you'll want to announce your contribution on the <a href="http://list.drupal.org/>drupal-devel and drupal-support mailing lists</a>. You might also want to post a story on - <a href="http://www.drupal.org/">Drupal.org</a>.<br> -</p> - <?php +</pre>"; + $output .= "<p>The <i>_auth_help</i> function is prominently linked within Drupal, so you'll want to write the best possible user help here. You'll want to tell users what a proper username looks like and you may also want to advertise a bit about your service at the end. Note that your help text is passed through a t() function in the last line. This is Drupal's localization function. Translators may localize your help text just like any other text in Drupal.</p>"; + $output .= "<h4>Publishing your module</h4><p>Once you've written and tested your authentication module, you'll usually want to share it with the world. The best way to do this is to add the module to the ". l("Drupal contributions CVS repository", "cvs.drupal.org/viewcvs.cgi/contributions/modules/authentication?cvsroot=contrib") .". You'll need to request priveleges to this repository - see ". l("the README file", "cvs.drupal.org/viewcvs.cgi/contributions/README?rev=HEAD&cvsroot=contrib&content-type=text/vnd.viewcvs-markup") ." for the details. Then you should announce your contribution on the ". l("drupal-devel and drupal-support mailing lists", "drupal.org/node/view/322") .". You might also want to post a story on ". l("Drupal.org", "www.drupal.org") .".</p>"; + return $output; } function user_help_devel_userhook() { - ?> - <h3><a name="userhook">module_user()</a></h3> - <p>The <b>_user()</b> hook provides to module authors a mechanism for inserting text and form fields into the registration page, the user account view/edit pages, and the administer users page. This is useful if you want to add a custom field for your particular community. This is best illustrated by an example called <a href="http://cvs.drupal.org/viewcvs.cgi/contributions/modules/profile/?cvsroot=contrib">profile.module</a> in the contributions CVS repository. Profile.module is meant to be customized for your needs. Please download it and hack away until it does what you need.</p> - -<p>Consider this simpler example from a fictional recipe community web site called Julia's Kitchen. Julia customizes her Drupal powered site by creating a new file called <i>julia.module</i>. That file does the following:<ul> -<li>new members must agree to Julia's Privacy Policy on the reg page.</li> -<li>members may list their favorite ingredients on their public user profile page</li></ul></p> - -<p>Julia achieves this with the following code. The comments below should help you understand what is going on.</p> - -<pre> -function julia_user($type, $edit, &$user) { - switch ($type) { - case "register_form": - $output .= form_item("Privacy Policy", "Julia would never sell your user information. She is just nice old French chef who lives near me in Cambridge, Massachussetts USA."); - $output .= form_checkbox("Accept <i>Julia's Kitchen</i> privacy policy.", julia_accept, 1, $edit["julia_accept"]); - return $output; - case "register_validate": - if ($edit["julia_accept"] == "1") { + + $output .= "<h3><a name=\"userhook\">module_user()</a></h3><p>The <b>_user()</b> hook provides a mechanism for inserting text and form fields into the ". l("registration","user/register") .", ". l("user account view/edit", "user") .", and ". l("administer users", "admin/user") ." pages. This is useful if you want to add a custom field for your particular community. This is best illustrated by the ". l("profile.module", "cvs.drupal.org/viewcvs/drupal/modules/profile.module") .". The profile.module is meant to be customized for your needs. Please download it and hack away until it does what you need.</p>"; + + $output .= "<p>Consider this simpler example from a fictional recipe community web site called Julia's Kitchen. Julia customizes her Drupal powered site by creating a new file called <i>julia.module</i>. That file does the following:<ul><li>new members must agree to Julia's Privacy Policy on the reg page.</li><li>members may list their favorite ingredients on their public user profile page</li></ul></p>"; + + $output .= "<p>Julia achieves this with the following code. The comments below should help you understand what is going on.</p>"; + + $output .= "<pre> +function julia_user(\$type, \$edit, &\$user) { + + switch (\$type) { // What type of registration action are we taking. + case t(\"register_form\"): // Add the two items below to the resigtration form. + \$output .= form_item(\"Privacy Policy\", \"Julia would never sell your user information. She is just nice old French chef who lives near me in Cambridge, Massachussetts USA.\"); + \$output .= form_checkbox(\"Accept <i>Julia's Kitchen</i> privacy policy.\", julia_accept, 1, \$edit[\"julia_accept\"]); + return \$output; + case t(\"register_validate\"): // Okay, the user has filled out the form, did they agree. + if (\$edit[\"julia_accept\"] == \"1\") { // on success return the values you want to store - return array("julia_accept" => 1); + return array(\"julia_accept\" => 1); } else { // on error return an error message - return "You must accept the Julia's Kitchen privacy policy to register."; + return \"You must accept the Julia's Kitchen privacy policy to register.\"; } - case "view_public": + case t(\"view_public\"): // when others look at user data - return form_item("Favorite Ingredient", $user->julia_favingredient); - case "view_private": + return form_item(\"Favorite Ingredient\", \$user->julia_favingredient); + case t(\"view_private\"): // when user tries to view his own user page. - return form_item("Favorite Ingredient", $user->julia_favingredient); - case "edit_form": + return form_item(\"Favorite Ingredient\", \$user->julia_favingredient); + case t(\"edit_form\"): // when user tries to edit his own user page. - return form_textfield("Favorite Ingredient", "julia_favingredient", $user->julia_favingredient, 50, 65, "Tell everyone your secret spice"); - case "edit_validate": - return user_save($user, array("julia_favingredient" => $edit["julia_favingredient"])); + return form_textfield(\"Favorite Ingredient\", \"julia_favingredient\", \$user->julia_favingredient, 50, 65, \"Tell everyone your secret spice\"); + case t(\"edit_validate\"): // Make sure the data they edited is \"valid\". + return user_save(\$user, array(\"julia_favingredient\" => \$edit[\"julia_favingredient\"])); } } -</pre> - <?php +</pre>"; + return $output; } ?> |