Skip to content

Commit c303a73

Browse files
committed
First crack at userguide documentation.
1 parent 3c0a94a commit c303a73

File tree

10 files changed

+182
-5
lines changed

10 files changed

+182
-5
lines changed

guide/auth/config.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Configuration
2+
3+
The default config file is located in `MODPATH/auth/config/auth.php`. You should copy this file to `APPPATH/config/auth.php` and make changes there, in keeping with the [cascading filesystem](../kohana/files).
4+
5+
[Config merging](../kohana/config#config-merging) allows the default config settings to apply if you don't overwrite them in your application configuration file.
6+
7+
Name | Type | Default | Description
8+
-----|------|---------|------------
9+
driver | `string` | file | The name of the auth driver to use.
10+
hash_method | `string` | sha256 | The hashing function to use.
11+
hash_key | `string` | NULL | The key to use when hashing the password.
12+
lifetime | `int` | 1209600 | The time (in seconds) that the user session is valid without activity.
13+
session_type | `string` | [Session::$default] | The type of session to use to store the auth user.
14+
session_key | `string` | auth_user | The name of the session variable to save the user.

guide/auth/driver/develop.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Developing Drivers
2+
3+
[!!] We will be developing an `example` driver. In your own driver you will substitute `example` with your driver name.
4+
5+
This example file would be saved at `APPPATH/classes/auth/example.php` (or `MODPATH` if you are creating a module).
6+
7+
## Quick Example
8+
9+
First we will show you a quick example and then break down what is going on.
10+
11+
~~~
12+
class Auth_Example extends Auth
13+
{
14+
protected function _login($username, $password, $remember)
15+
{
16+
// Do username/password check here
17+
}
18+
19+
public function password($username)
20+
{
21+
// Return the password for the username
22+
}
23+
24+
public function check_password($password)
25+
{
26+
// Check to see if the logged in user has the given password
27+
}
28+
29+
public function logged_in($role = NULL)
30+
{
31+
// Check to see if the user is logged in, and if $role is set, has all roles
32+
}
33+
34+
public function get_user($default = NULL)
35+
{
36+
// Get the logged in user, or return the $default if a user is not found
37+
}
38+
}
39+
~~~
40+
41+
## Extending Auth
42+
43+
All drivers must extend the [Auth] class.
44+
45+
class Auth_Example extends Auth
46+
47+
## Abstract Methods
48+
49+
The `Auth` class has 3 abstract methods that must be defined in your new driver.
50+
51+
~~~
52+
abstract protected function _login($username, $password, $remember);
53+
54+
abstract public function password($username);
55+
56+
abstract public function check_password($user);
57+
~~~
58+
59+
## Extending Functionality
60+
61+
Given that every auth system is going to check if users exist and if they have roles or not you will more than likely have to change some default functionality.
62+
63+
Here are a few functions that you should pay attention to.
64+
65+
~~~
66+
public function logged_in($role = NULL)
67+
68+
public function get_user($default = NULL)
69+
~~~
70+
71+
## Activating the Driver
72+
73+
After you create your driver you will want to use it. It is a easy as setting the `driver` [configuration](config) option to the name of your driver (in our case `example`).
74+
75+
## Real World Examples
76+
77+
Sometimes the best way to learn is to just read the code. Here are a auth drivers that you can take a look at.
78+
79+
* [ORM](https://github.com/kohana/orm/blob/3.2/master/classes/kohana/auth/orm.php)

guide/auth/driver/file.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# File Driver
2+
3+
The [Auth::File] driver is the default driver when you activate the auth module.
4+
5+
Below are additional configuration options that can be set for this driver.
6+
7+
Name | Type | Default | Description
8+
-----|------|---------|-------------
9+
users | `array` | array() | A user => password (hashed) array of all the users in your application
10+
11+
## Forcing Login
12+
13+
[Auth_File::force_login] allows you to force a user login without a password.
14+
15+
~~~
16+
// Force the admin user to be logged in
17+
Auth::instance()->force_login('admin');
18+
$user = Auth::instance()->get_user(); // Returns the user with the admin username.
19+
~~~
20+
21+
## Roles
22+
23+
The file driver does not have built in support for roles. If roles are important for your application you should look into a different driver or [develop](driver/develop) your own.

guide/auth/edit.md

Whitespace-only changes.

guide/auth/index.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Auth
2+
3+
User authentication and authorization is provided by the auth module.
4+
5+
The auth module is included with the Kohana 3.0 install, but needs to be enabled before you can use it. To enable, open your `application/bootstrap.php` file and modify the call to [Kohana::modules] by including the auth module like so:
6+
7+
~~~
8+
Kohana::modules(array(
9+
...
10+
'auth' => MODPATH.'auth',
11+
...
12+
));
13+
~~~
14+
15+
Next, you will then need to [configure](config) the auth module.
16+
17+
The auth module provides a [Auth::File] driver but [drivers](driver/develop) can be easily added to fit your needs.

guide/auth/login.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Log in and out
2+
3+
The auth module provides methods to help you log users in and out of your application.
4+
5+
## Log in
6+
7+
The [Auth::login] method with handle the login.
8+
9+
~~~
10+
// Handled from a form with inputs of names email / password
11+
$post = $this->request->post();
12+
$success = Auth::instance()->login($post['email'], $post['password']);
13+
14+
if ($success)
15+
{
16+
// Login successful, send to app
17+
}
18+
else
19+
{
20+
// Login failed, send back to form with error message
21+
}
22+
~~~
23+
24+
## Logged in User
25+
26+
To find the logged in use within you app you will call [Auth::get_user].
27+
28+
~~~
29+
$user = Auth::instance()->get_user();
30+
31+
// Check for a user (NULL if not user is found)
32+
if ($user !== null)
33+
{
34+
// User is found, continue on
35+
}
36+
else
37+
{
38+
// User was not found, redirect to the login form
39+
}
40+
~~~
41+
42+
## Log out
43+
44+
The [Auth::logout] method will take care of logging out a user.
45+
46+
Auth::instance()->logout();

guide/auth/menu.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
## [Auth]()
2-
- [Config](config)
3-
- [User Model](user)
4-
- [Register Users](register)
2+
- [Configuration](config)
53
- [Log in and out](login)
6-
- [Edit User](edit)
7-
- [Using Roles](roles)
4+
- [File Driver](driver/file)
5+
- [Developing Drivers](driver/develop)

guide/auth/register.md

Whitespace-only changes.

guide/auth/roles.md

Whitespace-only changes.

guide/auth/user.md

Whitespace-only changes.

0 commit comments

Comments
 (0)