docs/auth_api.html
author indvdum (gotoindvdum[at]gmail[dot]com)
Fri, 09 Mar 2012 16:11:37 +0400
changeset 12 898199d067e7
parent 0 ceef6d64c21d
permissions -rw-r--r--
Ignoring cache
indvdum@0
     1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
indvdum@0
     2
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en" xml:lang="en">
indvdum@0
     3
<head>
indvdum@0
     4
indvdum@0
     5
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
indvdum@0
     6
<meta http-equiv="content-style-type" content="text/css" />
indvdum@0
     7
<meta http-equiv="content-language" content="en" />
indvdum@0
     8
<meta http-equiv="imagetoolbar" content="no" />
indvdum@0
     9
<meta name="resource-type" content="document" />
indvdum@0
    10
<meta name="distribution" content="global" />
indvdum@0
    11
<meta name="copyright" content="phpBB Group" />
indvdum@0
    12
<meta name="keywords" content="" />
indvdum@0
    13
<meta name="description" content="This is an explanation of how to use the phpBB auth/acl API" />
indvdum@0
    14
<title>phpBB3 &bull; Auth API</title>
indvdum@0
    15
indvdum@0
    16
<link href="stylesheet.css" rel="stylesheet" type="text/css" media="screen, projection" />
indvdum@0
    17
indvdum@0
    18
</head>
indvdum@0
    19
indvdum@0
    20
<body id="phpbb" class="section-docs">
indvdum@0
    21
indvdum@0
    22
<div id="wrap">
indvdum@0
    23
	<a id="top" name="top" accesskey="t"></a>
indvdum@0
    24
	<div id="page-header">
indvdum@0
    25
		<div class="headerbar">
indvdum@0
    26
			<div class="inner"><span class="corners-top"><span></span></span>
indvdum@0
    27
indvdum@0
    28
			<div id="doc-description">
indvdum@0
    29
				<a href="../index.php" id="logo"><img src="site_logo.gif" alt="" /></a>
indvdum@0
    30
				<h1>Auth API</h1>
indvdum@0
    31
				<p>This is an explanation of how to use the phpBB auth/acl API</p>
indvdum@0
    32
				<p style="display: none;"><a href="#start_here">Skip</a></p>
indvdum@0
    33
			</div>
indvdum@0
    34
indvdum@0
    35
			<span class="corners-bottom"><span></span></span></div>
indvdum@0
    36
		</div>
indvdum@0
    37
	</div>
indvdum@0
    38
indvdum@0
    39
	<a name="start_here"></a>
indvdum@0
    40
indvdum@0
    41
	<div id="page-body">
indvdum@0
    42
indvdum@0
    43
<!-- BEGIN DOCUMENT -->
indvdum@0
    44
indvdum@0
    45
	<p>This is an explanation of how to use the phpBB auth/acl API.</p>
indvdum@0
    46
indvdum@0
    47
	<h1>Auth API</h1>
indvdum@0
    48
indvdum@0
    49
	<div class="paragraph menu">
indvdum@0
    50
		<div class="inner"><span class="corners-top"><span></span></span>
indvdum@0
    51
indvdum@0
    52
		<div class="content">
indvdum@0
    53
indvdum@0
    54
<ol>
indvdum@0
    55
	<li><a href="#intro">Introduction</a></li>
indvdum@0
    56
	<li><a href="#methods">Methods</a>
indvdum@0
    57
	<ol style="list-style-type: lower-roman;">
indvdum@0
    58
		<li><a href="#acl">acl</a></li>
indvdum@0
    59
		<li><a href="#acl_get">acl_get</a></li>
indvdum@0
    60
		<li><a href="#acl_gets">acl_gets</a></li>
indvdum@0
    61
		<li><a href="#acl_getf">acl_getf</a></li>
indvdum@0
    62
		<li><a href="#acl_getf_global">acl_getf_global</a></li>
indvdum@0
    63
		<li><a href="#acl_cache">acl_cache</a></li>
indvdum@0
    64
		<li><a href="#acl_clear_prefetch">acl_clear_prefetch</a></li>
indvdum@0
    65
		<li><a href="#acl_get_list">acl_get_list</a></li>
indvdum@0
    66
		<li><a href="#misc">Miscellaneous</a></li>
indvdum@0
    67
	</ol>
indvdum@0
    68
	</li>
indvdum@0
    69
	<li><a href="#admin_related">Admin related functions</a></li>
indvdum@0
    70
	<li><a href="#disclaimer">Copyright and disclaimer</a></li>
indvdum@0
    71
</ol>
indvdum@0
    72
indvdum@0
    73
		</div>
indvdum@0
    74
indvdum@0
    75
		<span class="corners-bottom"><span></span></span></div>
indvdum@0
    76
	</div>
indvdum@0
    77
indvdum@0
    78
	<hr />
indvdum@0
    79
indvdum@0
    80
<a name="intro"></a><h2>1. Introduction</h2>
indvdum@0
    81
indvdum@0
    82
	<div class="paragraph">
indvdum@0
    83
		<div class="inner"><span class="corners-top"><span></span></span>
indvdum@0
    84
indvdum@0
    85
		<div class="content">
indvdum@0
    86
indvdum@0
    87
	<h4>What is it?</h4>
indvdum@0
    88
indvdum@0
    89
	<p>The <code>auth</code> class contains methods related to authorisation users to access various board functions, e.g. posting, viewing, replying, logging in (and out), etc. If you need to check whether a user can carry out a task or handle user login/logouts this class is required.</p>
indvdum@0
    90
indvdum@0
    91
	<h4>Initialisation</h4>
indvdum@0
    92
indvdum@0
    93
	<p>To use any methods contained with the <code>auth</code> class it first needs to be instantiated. This is best achieved early in the execution of the script in the following manner:</p>
indvdum@0
    94
indvdum@0
    95
	<div class="codebox"><pre>
indvdum@0
    96
$auth = new auth();
indvdum@0
    97
	</pre></div>
indvdum@0
    98
indvdum@0
    99
	<p>Once an instance of the class has been created you are free to call the various methods it contains. Please note that should you wish to use the <code>auth_admin</code> methods you will need to instantiate this separately but in the same way.</p>
indvdum@0
   100
indvdum@0
   101
		</div>
indvdum@0
   102
indvdum@0
   103
		<div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
indvdum@0
   104
indvdum@0
   105
		<span class="corners-bottom"><span></span></span></div>
indvdum@0
   106
	</div>
indvdum@0
   107
indvdum@0
   108
	<hr />
indvdum@0
   109
indvdum@0
   110
<a name="methods"></a><h2>2. Methods</h2>
indvdum@0
   111
indvdum@0
   112
	<div class="paragraph">
indvdum@0
   113
		<div class="inner"><span class="corners-top"><span></span></span>
indvdum@0
   114
indvdum@0
   115
		<div class="content">
indvdum@0
   116
indvdum@0
   117
	<p>Following are the methods you are able to use.</p>
indvdum@0
   118
indvdum@0
   119
	<a name="acl"></a><h3>2.i. acl</h3>
indvdum@0
   120
	
indvdum@0
   121
	<p>The <code>acl</code> method is the initialisation routine for all the acl functions. If you intend calling any acl method you must first call this. The method takes as its one and only required parameter an associative array containing user information as stored in the database. This array must contain at least the following information; user_id, user_permissions and user_type. It is called in the following way:</p>
indvdum@0
   122
indvdum@0
   123
	<div class="codebox"><pre>
indvdum@0
   124
$auth-&gt;acl(<code>userdata</code>);
indvdum@0
   125
	</pre></div>
indvdum@0
   126
indvdum@0
   127
	<p>Where userdata is the array containing the aforementioned data.</p>
indvdum@0
   128
indvdum@0
   129
	<a name="acl_get"></a><h3>2.ii. acl_get</h3>
indvdum@0
   130
indvdum@0
   131
	<p>This method is the primary way of determining what a user can and cannot do for a given option globally or in a given forum. The method should be called in the following way:</p>
indvdum@0
   132
indvdum@0
   133
	<div class="codebox"><pre>
indvdum@0
   134
$result = $auth-&gt;acl_get(<code>option</code>[, <code>forum</code>]);
indvdum@0
   135
	</pre></div>
indvdum@0
   136
indvdum@0
   137
	<p>Where option is a string representing the required option, e.g. 'f_list', 'm_edit', 'a_adduser', etc. By adding a ! in front of the option, e.g. '!f_list' the result of this method will be negated. The optional forum term is the integer forum_id.</p>
indvdum@0
   138
indvdum@0
   139
	<p>The method returns a positive integer when the user is allowed to carry out the option and a zero if denied or the other way around if the option is prefixed with an exclamation mark.</p>
indvdum@0
   140
indvdum@0
   141
	<p>If you specify a forum and there is also a global setting for the specified option then this method will return a positive integer if one of them evaluates to a positive integer. An example would be the m_approve option which can be set per forum but also globally. If a user has the global option he will automatically have m_approve in every forum.</p>
indvdum@0
   142
indvdum@0
   143
	<p>There are some special options or <em>flags</em> which are used as prefixes for other options, e.g. 'f_' or 'm_'. These flags will automatically be set to a positive integer if the user has one or more permissions with the given prefix. A local setting will result in the flag being set only locally (so it will require a forum id to retrieve). If a user has one or more global permissions with the prefix acl_get will return a positive integer regardless of the forum id.</p>
indvdum@0
   144
indvdum@0
   145
	<a name="acl_gets"></a><h3>2.iii. acl_gets</h3>
indvdum@0
   146
indvdum@0
   147
	<p>This method is funtionally similar to <code>acl_get</code> in that it returns information on whether a user can or cannot carry out a given task. The difference here is the ability to test several different options in one go. This may be useful for testing whether a user is a moderator or an admin in one call. Rather than having to call and check <code>acl_get</code> twice.</p>
indvdum@0
   148
indvdum@0
   149
	<p>The method should be called thus:</p>
indvdum@0
   150
indvdum@0
   151
	<div class="codebox"><pre>
indvdum@0
   152
$result = $auth-&gt;acl_gets(<code>option1</code>[, <code>option2</code>, ..., <code>optionN</code>, <code>forum</code>]);
indvdum@0
   153
	</pre></div>
indvdum@0
   154
indvdum@0
   155
	<p>As with the <code>acl_get</code> method the options are strings representing the required permissions to check. The forum again is an integer representing a given forum_id.</p>
indvdum@0
   156
indvdum@0
   157
	<p>The method will return a positive integer if <code>acl_get</code> for one of the options evaluates to a positive integer (combines permissions with OR).</p>
indvdum@0
   158
indvdum@0
   159
	<a name="acl_getf"></a><h3>2.iv. acl_getf</h3>
indvdum@0
   160
indvdum@0
   161
	<p>This method is used to find out in which forums a user is allowed to carry out an operation or to find out in which forums he is not allowed to carry out an operation. The method should be called in the following way:</p>
indvdum@0
   162
indvdum@0
   163
	<div class="codebox"><pre>
indvdum@0
   164
$result = $auth-&gt;acl_getf(<code>option</code>[, <code>clean</code>]);
indvdum@0
   165
	</pre></div>
indvdum@0
   166
indvdum@0
   167
	<p>Just like in the <code>acl_get</code> method the option is a string specifying the permission which has to be checked (negation using ! is allowed). The second parameter is a boolean. If it is set to false this method returns all forums with either zero or a positive integer. If it is set to true only those forums with a positive integer as the result will be returned.</p>
indvdum@0
   168
indvdum@0
   169
	<p>The method returns an associative array of the form:</p>
indvdum@0
   170
indvdum@0
   171
	<div class="codebox"><pre>
indvdum@0
   172
array(<em>forum_id1</em> =&gt; array(<em>option</em> =&gt; <em>integer</em>), <em>forum_id2</em> =&gt; ...)
indvdum@0
   173
	</pre></div>
indvdum@0
   174
indvdum@0
   175
	<p>Where option is the option passed to the method and integer is either zero or a positive integer and the same <code>acl_get(option, forum_id)</code> would return.</p>
indvdum@0
   176
indvdum@0
   177
	<a name="acl_getf_global"></a><h3>2.v. acl_getf_global</h3>
indvdum@0
   178
indvdum@0
   179
	<p>This method is used to find out whether a user has a permission in at least one forum or globally. This method is similar to checking whether <code>acl_getf(option, true)</code> returned one or more forums but it's faster. It should be called in the following way:</p>
indvdum@0
   180
indvdum@0
   181
	<div class="codebox"><pre>
indvdum@0
   182
$result = $auth-&gt;acl_getf_global(<code>option</code>)
indvdum@0
   183
	</pre></div>
indvdum@0
   184
indvdum@0
   185
	<p>As with the previous methods option is a string specifying the permission which has to be checked.</p>
indvdum@0
   186
indvdum@0
   187
	<p>This method returns either zero or a positive integer.</p>
indvdum@0
   188
indvdum@0
   189
	<a name="acl_cache"></a><h3>2.vi. acl_cache</h3>
indvdum@0
   190
indvdum@0
   191
	<p>This should be considered a private method and not be called externally. It handles the generation of the user_permissions data from the basic user and group authorisation data. When necessary this method is called automatically by <code>acl</code>.</p>
indvdum@0
   192
indvdum@0
   193
	<a name="acl_clear_prefetch"></a><h3>2.vii. acl_clear_prefetch</h3>
indvdum@0
   194
indvdum@0
   195
	<p>This method clears the user_permissions column in the users table for the given user.  If the user ID passed is zero, the permissions cache is cleared for all users.  This method should be called whenever permissions are set.</p>
indvdum@0
   196
indvdum@0
   197
	<div class="codebox"><pre>
indvdum@0
   198
// clear stored permissions for user 2
indvdum@0
   199
$user_id = 2;
indvdum@0
   200
$auth->acl_clear_prefetch($user_id);
indvdum@0
   201
</pre></div>
indvdum@0
   202
indvdum@0
   203
	<p>This method returns void.</p>
indvdum@0
   204
indvdum@0
   205
	<a name="acl_get_list"></a><h3>2.viii. acl_get_list</h3>
indvdum@0
   206
indvdum@0
   207
	<p>This method returns an an array describing which users have permissions in given fora.  The resultant array contains an entry for permission that every user has in every forum when no arguments are passed.</p>
indvdum@0
   208
indvdum@0
   209
	<div class="codebox"><pre>
indvdum@0
   210
$user_id = array(2, 53);
indvdum@0
   211
$permissions = array('f_list', 'f_read');
indvdum@0
   212
$forum_id = array(1, 2, 3);
indvdum@0
   213
$result = $auth-&gt;acl_get_list($user_id, $permissions, $forum_id);
indvdum@0
   214
</pre></div>
indvdum@0
   215
indvdum@0
   216
	<p>The parameters may be of the following legal types:</p>
indvdum@0
   217
		<ul>
indvdum@0
   218
			<li><strong>$user_id</strong>: <code>false</code>, int, array(int, int, int, ...)</li>
indvdum@0
   219
			<li><strong>$permissions</strong>: <code>false</code>, string, array(string, string, ...)</li>
indvdum@0
   220
			<li><strong>$forum_id</strong>: <code>false</code>, int, array(int, int, int, ...)</li>
indvdum@0
   221
		</ul>
indvdum@0
   222
indvdum@0
   223
	<a name="misc"></a><h3>2.ix. Miscellaneous</h3>
indvdum@0
   224
indvdum@0
   225
	<p>There are other methods defined in the auth class which serve mostly as private methods, but are available for use if needed.  Each of them is used to pull data directly from the database tables.  They are:</p>
indvdum@0
   226
		<ul>
indvdum@0
   227
			<li><pre>function acl_group_raw_data($group_id = false, $opts = false, $forum_id = false)</pre></li>
indvdum@0
   228
			<li><pre>function acl_user_raw_data($user_id = false, $opts = false, $forum_id = false)</pre></li>
indvdum@0
   229
			<li><pre>function acl_raw_data_single_user($user_id)</pre></li>
indvdum@0
   230
			<li><pre>function acl_raw_data($user_id = false, $opts = false, $forum_id = false)</pre></li>
indvdum@0
   231
			<li><pre>function acl_role_data($user_type, $role_type, $ug_id = false, $forum_id = false)</pre></li>
indvdum@0
   232
		</ul>
indvdum@0
   233
indvdum@0
   234
	<p>Of these, <code>acl_raw_data</code> is the most general, but the others will be faster if you need a smaller amount of data.</p>
indvdum@0
   235
indvdum@0
   236
		</div>
indvdum@0
   237
indvdum@0
   238
		<div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
indvdum@0
   239
indvdum@0
   240
		<span class="corners-bottom"><span></span></span></div>
indvdum@0
   241
	</div>
indvdum@0
   242
indvdum@0
   243
	<hr />
indvdum@0
   244
indvdum@0
   245
<a name="admin_related"></a><h2>3. Admin related functions</h2>
indvdum@0
   246
indvdum@0
   247
	<div class="paragraph">
indvdum@0
   248
		<div class="inner"><span class="corners-top"><span></span></span>
indvdum@0
   249
indvdum@0
   250
		<div class="content">
indvdum@0
   251
indvdum@0
   252
	<p>A number of additional methods are available related to <code>auth</code>. These handle more basic functions such as adding user and group permissions, new options and clearing the user cache. These methods are contained within a separate class, <code>auth_admin</code>. This can be found in <code>includes/acp/auth.php</code>.</p>
indvdum@0
   253
indvdum@0
   254
	<p>To use any methods this class contains it first needs to be instantiated separately from <code>auth</code>. This is achieved in the same way as <code>auth</code>:</p>
indvdum@0
   255
indvdum@0
   256
	<div class="codebox"><pre>
indvdum@0
   257
$auth_admin = new auth_admin();
indvdum@0
   258
	</pre></div>
indvdum@0
   259
indvdum@0
   260
	<p>This instance gives you access to both the methods of this specific class and that of <code>auth</code>.</p>
indvdum@0
   261
indvdum@0
   262
		</div>
indvdum@0
   263
indvdum@0
   264
		<div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
indvdum@0
   265
indvdum@0
   266
		<span class="corners-bottom"><span></span></span></div>
indvdum@0
   267
	</div>
indvdum@0
   268
indvdum@0
   269
	<hr />
indvdum@0
   270
indvdum@0
   271
<a name="disclaimer"></a><h2>4. Copyright and disclaimer</h2>
indvdum@0
   272
indvdum@0
   273
	<div class="paragraph">
indvdum@0
   274
		<div class="inner"><span class="corners-top"><span></span></span>
indvdum@0
   275
indvdum@0
   276
		<div class="content">
indvdum@0
   277
indvdum@0
   278
	<p>This application is opensource software released under the <a href="http://opensource.org/licenses/gpl-license.php">GPL</a>. Please see source code and the docs directory for more details. This package and its contents are Copyright (c) <a href="http://www.phpbb.com/">phpBB Group</a>, All Rights Reserved.</p>
indvdum@0
   279
indvdum@0
   280
		</div>
indvdum@0
   281
indvdum@0
   282
		<div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
indvdum@0
   283
indvdum@0
   284
		<span class="corners-bottom"><span></span></span></div>
indvdum@0
   285
	</div>
indvdum@0
   286
indvdum@0
   287
<!-- END DOCUMENT -->
indvdum@0
   288
indvdum@0
   289
	<div id="page-footer">
indvdum@0
   290
		<div class="version">&nbsp;</div>
indvdum@0
   291
	</div>
indvdum@0
   292
</div></div>
indvdum@0
   293
indvdum@0
   294
<div>
indvdum@0
   295
	<a id="bottom" name="bottom" accesskey="z"></a>
indvdum@0
   296
</div>
indvdum@0
   297
indvdum@0
   298
</body>
indvdum@0
   299
</html>