added DbLoginModel

This commit is contained in:
hyung-hwan 2011-11-26 13:32:03 +00:00
parent d9191b9921
commit 17d72c00ef
12 changed files with 140 additions and 66 deletions

View File

@ -94,6 +94,7 @@ svn_base_url = "${REQUEST_PROTOCOL}://${SERVER_NAME}:${SERVER_PORT}/svn"
; Login model to use. ; Login model to use.
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
login_model = "LdapLoginModel" login_model = "LdapLoginModel"
#login_model = "DbLoginModel"
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; Comma separated list of system administrator IDs ; Comma separated list of system administrator IDs

View File

@ -152,3 +152,10 @@ CREATE TABLE user_settings (
code_hide_line_num CHAR(1) NOT NULL, code_hide_line_num CHAR(1) NOT NULL,
code_hide_details CHAR(1) NOT NULL code_hide_details CHAR(1) NOT NULL
) charset=utf8 engine=InnoDB; ) charset=utf8 engine=InnoDB;
CREATE TABLE user (
userid VARCHAR(32) PRIMARY KEY,
passwd VARCHAR(255) NOT NULL,
email VARCHAR(255),
enabled CHAR(1) NOT NULL DEFAULT 'N' CHECK(enabled in ('Y', 'N'))
) charset=utf8 engine=InnoDB;

View File

@ -1,12 +1,12 @@
wwwdir=$(WWWDIR)/codepot/models wwwdir=$(WWWDIR)/codepot/models
www_DATA = \ www_DATA = \
dbloginmodel.php \
filemodel.php \ filemodel.php \
index.html \ index.html \
issuemodel.php \ issuemodel.php \
ldaploginmodel.php \ ldaploginmodel.php \
loginmodel.php \ loginmodel.php \
logmodel.php \ logmodel.php \
mysqlloginmodel.php \
projectmodel.php \ projectmodel.php \
sitemodel.php \ sitemodel.php \
subversionmodel.php \ subversionmodel.php \

View File

@ -166,13 +166,13 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
wwwdir = $(WWWDIR)/codepot/models wwwdir = $(WWWDIR)/codepot/models
www_DATA = \ www_DATA = \
dbloginmodel.php \
filemodel.php \ filemodel.php \
index.html \ index.html \
issuemodel.php \ issuemodel.php \
ldaploginmodel.php \ ldaploginmodel.php \
loginmodel.php \ loginmodel.php \
logmodel.php \ logmodel.php \
mysqlloginmodel.php \
projectmodel.php \ projectmodel.php \
sitemodel.php \ sitemodel.php \
subversionmodel.php \ subversionmodel.php \

View File

@ -0,0 +1,98 @@
<?php
require_once 'loginmodel.php';
class DbLoginModel extends LoginModel
{
function DbLoginModel ()
{
parent::LoginModel ();
$this->load->database ();
}
function rand_string ($length)
{
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = '';
$size = strlen ($chars);
for( $i = 0; $i < $length; $i++ )
{
$str .= $chars[ rand( 0, $size - 1 ) ];
}
return $str;
}
function format_password_with_salt ($password, $salt)
{
return '{ssha1}' . sha1($password . $salt) . bin2hex($salt);
}
function format_password ($password, $salt_length)
{
$salt = $this->rand_string ($salt_length);
return $this->format_password_with_salt ($password, $salt);
}
function authenticate ($userid, $passwd)
{
$this->db->trans_start ();
$this->db->select ('userid,passwd,email');
$this->db->where ('userid', $userid);
$query = $this->db->get ('user');
if ($this->db->trans_status() == FALSE)
{
$this->db->trans_complete ();
return FALSE;
}
$result = $query->result ();
if (empty($result))
{
$this->db->trans_complete ();
return FALSE;
}
$this->db->trans_complete ();
if ($this->db->trans_status() == FALSE) return FALSE;
$user = $result[0];
if (strlen($user->passwd) < 10) return FALSE;
$hexsalt = substr ($user->passwd, -10);
$binsalt = pack("H*" , $hexsalt);
if (strcmp ($this->format_password_with_salt($passwd,$binsalt),$user->passwd) != 0) return FALSE;
return parent::authenticate ($userid, $user->passwd, $user->email);
}
function changePassword ($userid, $passwd)
{
$this->db->trans_start ();
$this->db->trans_complete ();
$this->db->where ('userid', $userid);
$this->db->set ('passwd', format_password($passwd,5));
$this->db->update ('user');
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback ();
return FALSE;
}
$this->db->trans_commit ();
return TRUE;
}
function queryUserInfo ($userid)
{
$user['id'] = $userid;
$user['email'] = '';
return $user;
}
}
?>

View File

@ -81,7 +81,7 @@ class LdapLoginModel extends LoginModel
if ($bind === FALSE) if ($bind === FALSE)
{ {
$this->setErrorMessage (ldap_error ($ldap)); $this->setErrorMessage (ldap_error ($ldap));
ldap_close ($ldap); @ldap_close ($ldap);
return FALSE; return FALSE;
} }
@ -127,7 +127,7 @@ class LdapLoginModel extends LoginModel
if ($bind === FALSE) if ($bind === FALSE)
{ {
$this->setErrorMessage (ldap_error ($ldap)); $this->setErrorMessage (ldap_error ($ldap));
ldap_close ($ldap); @ldap_close ($ldap);
return FALSE; return FALSE;
} }

View File

@ -87,6 +87,11 @@ class LoginModel extends Model
$this->session->sess_destroy (); $this->session->sess_destroy ();
} }
function changePassword ($userid, $passwd)
{
return FALSE;
}
function setUserSettings ($settings) function setUserSettings ($settings)
{ {
$this->session->set_userdata ('user_settings', serialize($settings)); $this->session->set_userdata ('user_settings', serialize($settings));

View File

@ -1,37 +0,0 @@
<?php
require_once 'loginmodel.php';
class MysqlLoginModel extends LoginModel
{
function LdapLoginModel ()
{
parent::LoginModel ();
$this->load->database ('auth-mysql');
}
function authenticate ($userid, $password)
{
$this->db->trans_start ();
/*
TODO:
$this->db->select ('username');
$this->db->where ('username', $userid);
$this->db->where ('passwd', $userid);
*/
$this->db->trans_complete ();
if ($this->db->trans_status() === FALSE) return FALSE;
return parent::authenticate ($userid, $password, $email);
}
function queryUserInfo ($userid)
{
$user['id'] = '';
$user['email'] = '';
return $user;
}
}
?>