Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /application/bootstrap.php
- Kohana::modules(array(
- 'auth' => MODPATH.'auth', // Basic authentication
- // 'codebench' => MODPATH.'codebench', // Benchmarking tool
- 'database' => MODPATH.'database', // Database access
- // 'image' => MODPATH.'image', // Image manipulation
- 'orm' => MODPATH.'orm', // Object Relationship Mapping
- // 'pagination' => MODPATH.'pagination', // Paging of results
- // 'userguide' => MODPATH.'userguide', // User guide and API documentation
- ));
- application/config/auth.php
- <?php defined('SYSPATH') OR die('No direct access allowed.');
- return array
- (
- 'driver' => 'ORM',
- 'hash_method' => 'sha1',
- 'salt_pattern' => '1, 3, 5, 9, 14, 15, 20, 21, 28, 30',
- 'lifetime' => 1209600, //2 weeks
- 'session_key' => 'auth_user',
- 'users' => array
- (
- // 'admin' => 'b3154acf3a344170077d11bdb5fff31532f679a1919e716a02',
- ),
- );
- application/classes/controller/register.php
- <?php defined('SYSPATH') OR die('No direct access allowed.');
- class Controller_Register extends Controller_Common
- {
- public function action_index()
- {
- $user = ORM::factory('user');
- $post = Validate::factory($_POST)
- ->filter(TRUE, 'trim')
- ->filter('username', 'strtolower')
- ->rule('username', 'not_empty')
- ->rule('username', 'regex', array('/^[a-z_.0-9]++$/iD'))
- ->callback('username', array($user, 'username_available'))
- ->rule('password', 'not_empty')
- ->rule('confirm', 'not_empty')
- ->rule('confirm', 'matches', array('password'))
- ->rule('email', 'not_empty')
- ->rule('email', 'email')
- ->callback('email', array($user, 'email_available'));
- if ($post->check())
- {
- // Create a new user record in the database
- $user = Model_Auth_User::factory('user');
- $user->username = $_POST['username'];
- $user->email = $_POST['email'];
- $user->password = $_POST['email'];
- $user->save();
- $login_role = new Model_Role(array('name' =>'login'));
- $user->add('roles',$login_role);
- $this->request->redirect('/?msg='.urldecode('please log in now. sorry!'));
- }
- // Validation failed, collect the errors
- $errors = $post->errors('user');
- // Display the registration form
- $this->template
- ->bind('post', $post)
- ->bind('errors', $errors);
- }
- }
- application/classes/controller/default.php
- <?php defined('SYSPATH') OR die('No direct access allowed.');
- class Controller_Default extends Controller_Common
- {
- public function action_index()
- {
- $msg = '';
- $auth = Auth::instance();
- if ($auth->logged_in()) {
- $this->request->redirect('/chat');
- }
- $post = Validate::factory($_POST)
- ->filter(TRUE, 'trim')
- ->filter('username', 'strtolower')
- ->rule('username', 'not_empty')
- ->rule('password', 'not_empty');
- if ($post->check()) {
- $login = $auth->login($_POST['username'], $_POST['password'], true);
- if ($login) {
- $this->request->redirect('/chat');
- } else {
- $msg = 'wrong password.';
- }
- }
- $msg = !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : $msg;
- $this->template->post = $post;
- $this->template->errors = $post->errors('user');
- $this->template->msg = $msg;
- }
- }
- /application/classes/controller/common.php (simple extension that sets up my templates based on the requested path)
- <?php defined('SYSPATH') or die('No direct script access.');
- class Controller_Common extends Controller_Template {
- public function __construct(Kohana_Request $request)
- {
- parent::__construct($request);
- $this->template = $request->controller . '/' . $request->action;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement