added DbLoginModel
This commit is contained in:
parent
d9191b9921
commit
17d72c00ef
@ -94,6 +94,7 @@ svn_base_url = "${REQUEST_PROTOCOL}://${SERVER_NAME}:${SERVER_PORT}/svn"
|
||||
; Login model to use.
|
||||
;------------------------------------------------------------------------------
|
||||
login_model = "LdapLoginModel"
|
||||
#login_model = "DbLoginModel"
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Comma separated list of system administrator IDs
|
||||
|
@ -152,3 +152,10 @@ CREATE TABLE user_settings (
|
||||
code_hide_line_num CHAR(1) NOT NULL,
|
||||
code_hide_details CHAR(1) NOT NULL
|
||||
) 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;
|
||||
|
@ -1,12 +1,12 @@
|
||||
wwwdir=$(WWWDIR)/codepot/models
|
||||
www_DATA = \
|
||||
dbloginmodel.php \
|
||||
filemodel.php \
|
||||
index.html \
|
||||
issuemodel.php \
|
||||
ldaploginmodel.php \
|
||||
loginmodel.php \
|
||||
logmodel.php \
|
||||
mysqlloginmodel.php \
|
||||
projectmodel.php \
|
||||
sitemodel.php \
|
||||
subversionmodel.php \
|
||||
|
@ -166,13 +166,13 @@ top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
wwwdir = $(WWWDIR)/codepot/models
|
||||
www_DATA = \
|
||||
dbloginmodel.php \
|
||||
filemodel.php \
|
||||
index.html \
|
||||
issuemodel.php \
|
||||
ldaploginmodel.php \
|
||||
loginmodel.php \
|
||||
logmodel.php \
|
||||
mysqlloginmodel.php \
|
||||
projectmodel.php \
|
||||
sitemodel.php \
|
||||
subversionmodel.php \
|
||||
|
98
codepot/src/codepot/models/dbloginmodel.php
Normal file
98
codepot/src/codepot/models/dbloginmodel.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -81,7 +81,7 @@ class LdapLoginModel extends LoginModel
|
||||
if ($bind === FALSE)
|
||||
{
|
||||
$this->setErrorMessage (ldap_error ($ldap));
|
||||
ldap_close ($ldap);
|
||||
@ldap_close ($ldap);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ class LdapLoginModel extends LoginModel
|
||||
if ($bind === FALSE)
|
||||
{
|
||||
$this->setErrorMessage (ldap_error ($ldap));
|
||||
ldap_close ($ldap);
|
||||
@ldap_close ($ldap);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -87,6 +87,11 @@ class LoginModel extends Model
|
||||
$this->session->sess_destroy ();
|
||||
}
|
||||
|
||||
function changePassword ($userid, $passwd)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function setUserSettings ($settings)
|
||||
{
|
||||
$this->session->set_userdata ('user_settings', serialize($settings));
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user