<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>沧蓝的最新动态 - Kohana 中文</title>
    <link>http://kohana.cn/user/1000026</link>
    <generator>KohanaPHP</generator>
    <item>
      <title>发布 Kohana v3 的 PHamlP 模块！Haml/Sass模板引擎支持</title>
      <link>http://kohana.cn/group/fashioner/topic/1000242</link>
      <description>&lt;p&gt;&lt;a href="http://forum.kohanaframework.org/comments.php?DiscussionID=6097" rel="nofollow external" class="tpa"&gt;http://forum.kohanaframework.org/comments.php?DiscussionID=6097&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://fredwu.me/post/742116307/php-releasing-phamlp-module-for-kohana-use-haml-and" rel="nofollow external" class="tpa"&gt;http://fredwu.me/post/742116307/php-releasing-phamlp-module-for-kohana-use-haml-and&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src="http://kohana.cn/media/images/icons/emoticon/smile.png" class="emoticon" /&gt;&lt;/p&gt;</description>
      <author>沧蓝</author>
      <pubDate>Sun, 27 Jun 2010 23:15:44 +0800</pubDate>
    </item>
    <item>
      <title>【视频】用Kohana快速开发的网站，视频展示下载</title>
      <link>http://kohana.cn/group/fashioner/topic/1000089</link>
      <description>&lt;p&gt;&lt;a href="http://www.namipan.com/d/e2f20dd2ab401b0357ea5f7e41fba37b677defa0431e4001" rel="nofollow external" class="tpa"&gt;点击下载&lt;/a&gt; (20MB, MOV文件)&lt;/p&gt;

&lt;p&gt;程序代码共4400行。&lt;/p&gt;

&lt;p&gt;其中——&lt;/p&gt;

&lt;p&gt;2400行PHP代码，占总代码 55%。&lt;br /&gt;
900行HTML代码，占总代码 20%。&lt;br /&gt;
1100行JavaScript代码，占总代码 25%。&lt;/p&gt;

&lt;p&gt;程序大量采用了jQuery进行本地以及远程（AJAX）的操作。&lt;/p&gt;

&lt;p&gt;文件上传部分用的是Mootools的FancyUpload。由于网站是客户公司内部使用，所以不担心JS的负载效率。&lt;/p&gt;

&lt;p&gt;Kohana的ORM大大的缩短了开发的周期与维护的难度。&lt;/p&gt;

&lt;p&gt;抛砖引玉。&lt;img src="http://kohana.cn/media/images/icons/emoticon/smile.png" class="emoticon" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.namipan.com/d/e2f20dd2ab401b0357ea5f7e41fba37b677defa0431e4001" rel="nofollow external" class="tpa"&gt;点击下载&lt;/a&gt; (20MB, MOV文件)&lt;/p&gt;</description>
      <author>沧蓝</author>
      <pubDate>Fri, 27 Feb 2009 18:43:19 +0800</pubDate>
    </item>
    <item>
      <title>用户登陆模块 Authlite （Kohana内置Auth模块简化版）</title>
      <link>http://kohana.cn/group/fashioner/topic/1000063</link>
      <description>&lt;p&gt;&lt;strong&gt;简介：&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Authlite基于Kohana 2.3版本内置Auth模块开发。Authlite仅支持Kohana 2.3版本。&lt;/p&gt;

&lt;p&gt;相比较Auth而言，Authlite的特性为——&lt;/p&gt;

&lt;p&gt;[list]&lt;br /&gt;
去除了Role（适合用于无需用户等级的登录系统）。 去除了salt安全机制（绝大部分情况下用sha1就足够了），从而使得直接批量导入用户成为可能。 可自定义用户模型、用户名列名和密码列名。 登陆成功后直接返回用户对象，从而可直接对用户对象做更多的操作（例如：设定last_login时间）。&lt;/p&gt;

&lt;p&gt;Authlite为Layerful框架中的功能模块。Layerful框架正在持续开发中。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;代码：&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://gist.github.com/26063" rel="nofollow external" class="tpa"&gt;http://gist.github.com/26063&lt;/a&gt;&lt;/p&gt;

&lt;pre class="code"&gt;
&lt;?php
/**
* Authlite library
*
* Based on Kohana's Auth library.
*
* @package                Layerful
* @subpackage        Modules
* @author                Layerful Team &lt;http://layerful.org/&gt;
* @author                Fred Wu &lt;fred@beyondcoding.com&gt;
* @copyright        BeyondCoding
* @license                http://layerful.org/license MIT
* @since                0.3.0
*/
class Authlite_Core {


protected $session;
protected $config;
protected $username_column;
protected $password_column;


/**
* Create an instance of Auth.
*
* @return object
*/
public static function factory()
{
return new Authlite();
}


/**
* Return a static instance of Auth.
*
* @return object
*/
public static function instance()
{
static $instance;


// Load the Authlite instance
empty($instance) and $instance = new Authlite();


return $instance;
}


public function __construct()
{
$this-&gt;session = Session::instance();
$this-&gt;config  = Kohana::config('authlite');


$this-&gt;username_column = $this-&gt;config['username'];
$this-&gt;password_column = $this-&gt;config['password'];


Kohana::log('debug', 'Authlite Library loaded');
}


/**
* Check if there is an active session.
*
* @return boolean
*/
public function logged_in()
{
// Get the user from the session
$user = $this-&gt;session-&gt;get($this-&gt;config['session_key']);


$status = is_object($user) ? true : false;


// Get the user from the cookie
if ($status == false)
{
$token = cookie::get('authautologin');


if (is_string($token) &amp;&amp; $token === $this-&gt;hash($user-&gt;{$this-&gt;username_column}.$user-&gt;{$this-&gt;password_column}))
{
$status = true;
$this-&gt;login($user-&gt;{$this-&gt;username_column}, $user-&gt;{$this-&gt;password_column});
}
}


return $status;
}


/**
* Returns the currently logged in user, or FALSE.
*
* @return object|false
*/
public function get_user()
{
if ($this-&gt;logged_in())
{
return $_SESSION[$this-&gt;config['session_key']];
}


return false;
}


/**
* Attempt to log in a user by using an ORM object and plain-text password.
*
* @param string username to log in
* @param string password to check against
* @param boolean enable auto-login
* @return object|false
*/
public function login($username, $password, $remember = false)
{
if (empty($password))
{
return false;
}


$user = ORM::factory($this-&gt;config['user_model'])-&gt;where($this-&gt;username_column, $username)-&gt;find();


if ($user-&gt;{$this-&gt;password_column} === $this-&gt;hash($password))
{
$this-&gt;session-&gt;set($this-&gt;config['session_key'], $user);


if ($remember == true)
{
$token = $this-&gt;hash($user-&gt;{$this-&gt;username_column}.$user-&gt;{$this-&gt;password_column});
cookie::set('authlite_autologin', $token, $this-&gt;config['lifetime']);
}


return $user;
}
else
{
return false;
}
}


/**
* Log out a user by removing the related session variables.
*
* @param boolean $destroy completely destroy the session
* @return boolean
*/
public function logout($destroy = false)
{
if (cookie::get('authlite_autologin'))
{
cookie::delete('authlite_autologin');
}


if ($destroy === true)
{
// Destroy the session completely
Session::instance()-&gt;destroy();
}
else
{
// Remove the user from the session
$this-&gt;session-&gt;delete($this-&gt;config['session_key']);


// Regenerate session_id
$this-&gt;session-&gt;regenerate();
}


return ! $this-&gt;logged_in();
}


protected function hash($str)
{
return hash($this-&gt;config['hash_method'], $str);
}


} // End Authlite&lt;/pre&gt;

&lt;pre class="code"&gt;
&lt;?php


/**
* User model
*/
$config['user_model'] = 'user';


/**
* Username column
*/
$config['username'] = 'username';


/**
* Password column
*/
$config['password'] = 'password';


/**
* Type of hash to use for passwords. Any algorithm supported by the hash function
* can be used here.
* @see http://php.net/hash
* @see http://php.net/hash_algos
*/
$config['hash_method'] = 'sha1';


/**
* Set the auto-login (remember me) cookie lifetime, in seconds. The default
* lifetime is two weeks.
*/
$config['lifetime'] = 1209600;


/**
* Set the session key that will be used to store the current user.
*/
$config['session_key'] = 'authlite_user';&lt;/pre&gt;

&lt;p&gt;[&lt;em&gt; 本帖最后由 沧蓝 于 2008-11-18 17:47 编辑 &lt;/em&gt;]&lt;/p&gt;</description>
      <author>沧蓝</author>
      <pubDate>Tue, 18 Nov 2008 17:41:53 +0800</pubDate>
    </item>
  </channel>
</rss>

