Skip to content

Commit b8ec78d

Browse files
author
ifsale
committed
new release
1 parent 3caee98 commit b8ec78d

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

PtcAuth.php

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static function once( $userID , $expires = false )
3333
return static::_processLogin( $rand , 'none' , $expires );
3434
}
3535
if ( !$user = static::user( $userID ) ){ return false; }
36-
return static::_processLogin( $user->{$columns[ 'unique_key' ] } , 'none' , $expires );
36+
return static::_processLogin( $user->{ $columns[ 'unique_key' ] } , 'none' , $expires );
3737
}
3838
/**
3939
*
@@ -171,7 +171,7 @@ public static function user( $value = null )
171171
$value = ( $value ) ? $value : @$_SESSION[ 'user_id' ];
172172
if ( !$value ){ return null; } // no user id set
173173
$columns = static::$_tableColumns;
174-
$column = ( is_numeric( $value ) ) ? $columns[ 'unique_key' ] : $columns[ 'email' ];
174+
$column = ( is_numeric( $value ) ) ? $columns[ 'unique_key' ] : $columns[ 'username' ];
175175
$obj = call_user_func_array(
176176
array( $connection , 'where' ) , array( $column , '=' , $value ) );
177177
return static::_guard( $obj->row( ) );
@@ -365,16 +365,16 @@ public static function encrypt( $length = 50 )
365365
/**
366366
* 0 some error occured , 2 email already exists , 1 created
367367
*/
368-
public static function create( $email , $password , $extraData = null , $isAdmin = 0 )
368+
public static function create( $username , $password , $extraData = null , $isAdmin = 0 )
369369
{
370370
if ( !static::_isConfigured( ) ){ return false; }
371371
$code = 0;
372372
$data = null;
373-
static::_fireEvent( 'creating' , array( &$email , &$extraData , &$isAdmin ) );
373+
static::_fireEvent( 'creating' , array( &$username , &$extraData , &$isAdmin ) );
374374
$columns = static::$_tableColumns;
375375
$connection = static::_connection( );
376376
$connection->table( static::$_options[ 'users_table' ] )
377-
->where( $columns[ 'email' ] , '=' , $email )
377+
->where( $columns[ 'username' ] , '=' , $username )
378378
->run( );
379379
if ( $connection->CountRows( ) > 0 ){ $code = 2; } // email already exists
380380
if ( 0 === $code )
@@ -386,7 +386,7 @@ public static function create( $email , $password , $extraData = null , $isAdmin
386386
(
387387
$columns[ 'salt' ] => $user_salt ,
388388
$columns[ 'password' ] => $password ,
389-
$columns[ 'email' ] => $email ,
389+
$columns[ 'username' ] => $username
390390
);
391391
if ( static::$_options[ 'verify' ] ) // create verification code
392392
{
@@ -398,7 +398,7 @@ public static function create( $email , $password , $extraData = null , $isAdmin
398398
if ( $extraData ) // add extra data if any to the insert
399399
{
400400
$invalid_keys = array( $columns[ 'password' ] ,
401-
$columns[ 'email' ] , $columns[ 'unique_key' ] , $columns[ 'salt' ] );
401+
$columns[ 'username' ] , $columns[ 'unique_key' ] , $columns[ 'salt' ] );
402402
foreach ( $extraData as $k => $v )
403403
{
404404
if ( in_array( $k , $invalid_keys ) ){ continue; }
@@ -410,7 +410,7 @@ public static function create( $email , $password , $extraData = null , $isAdmin
410410
->run( );
411411
$code = ( $insert ) ? 1 : 0;
412412
}
413-
static::_fireEvent( 'created' , array( $email , $code , $data ) );
413+
static::_fireEvent( 'created' , array( $username , $code , $data ) );
414414
return $code;
415415
}
416416
/**
@@ -464,17 +464,17 @@ public static function logout( $destroySession = false )
464464
$query->where( 'expires' , '<' , $query->raw( 'NOW()' ) )
465465
->rawSelect( ' OR `expires` IS NULL' );
466466
} )->delete( )->run( );*/
467-
if ( @$_options[ 'remember_options' ][ 'param' ] )
467+
if ( @$options[ 'remember_options' ][ 'param' ] )
468468
{
469469
$update = array( static::$_tableColumns[ 'remember' ] => '' );
470-
static::_connection( $_options[ 'users_table' ] )
470+
static::_connection( $options[ 'users_table' ] )
471471
->update( static::_track( $update ) , $_SESSION[ 'user_id' ] )
472472
->run( );
473-
/*if ( static::getCookie( $_options[ 'remember_options' ][ 'param' ] ) )
473+
if ( static::getCookie( $options[ 'remember_options' ][ 'param' ] ) )
474474
{
475-
//static::setCookie( $options[ 'param' ] , '' , strtotime( '-1 day' ) , $options[ 'path' ] ,
476-
// $options[ 'domain' ] , $options[ 'secure' ] , $options[ 'http_only' ] );
477-
}*/
475+
static::setCookie( $options[ 'param' ] , '' , strtotime( '-1 day' ) , $options[ 'path' ] ,
476+
$options[ 'domain' ] , $options[ 'secure' ] , $options[ 'http_only' ] );
477+
}
478478
}
479479
}
480480
unset( $_SESSION[ 'token' ] );
@@ -486,25 +486,25 @@ public static function logout( $destroySession = false )
486486
/**
487487
* 0 some error occured , 4 no match , 3 not verified , 2 not active , 1 logged in
488488
*/
489-
public static function login( $email , $password )
489+
public static function login( $username , $password )
490490
{
491491
if ( !static::_isConfigured( ) ){ return false; }
492492
$code = 0;
493-
static::_fireEvent( 'before_login' , array( $email ) );
493+
static::_fireEvent( 'before_login' , array( $username ) );
494494
$columns = static::$_tableColumns;
495495
static::$_guard = false;
496-
if ( !$user = static::user( $email ) ){ $code = 4; } // mo match
496+
if ( !$user = static::user( $username ) ){ $code = 4; } // mo match
497497
else if ( static::$_options[ 'verify' ] &&
498498
true !== ( boolean ) $user->{ $columns[ 'verified' ] } ){ $code = 3; } // user is not verified
499499
else if ( static::$_options[ 'check_active' ] &&
500-
true !== (boolean) $user->{ $columns[ 'active' ] } ){ $code = 2; } // user is not active
500+
true !== ( boolean ) $user->{ $columns[ 'active' ] } ){ $code = 2; } // user is not active
501501
else
502502
{
503503
$password = static::_hashPassword( $user->{ $columns[ 'salt' ] } . $password );
504504
if ( $password !== $user->{ $columns[ 'password' ] } ){ $code = 4; } // mo match
505505
}
506506
if ( 0 === $code ){ $code = static::_processLogin( $user->{ $columns[ 'unique_key' ] } ); }
507-
static::_fireEvent( 'after_login' , array( $email , $code , static::_guard( $user ) ) );
507+
static::_fireEvent( 'after_login' , array( $username , $code , static::_guard( $user ) ) );
508508
return $code;
509509
}
510510
/**
@@ -621,11 +621,12 @@ public static function observe( $class = null )
621621
protected static $_tableColumns = array
622622
(
623623
'salt' => 'user_salt' , // required ***
624-
'email' => 'email' , // required ***
624+
'username' => 'username' , // required ***
625625
'password' => 'password' , // required ***
626626
'unique_key' => 'id' , // required ***
627627
'firstname' => 'firstname' , // optional
628628
'lastname' => 'lastname' , // optional
629+
'email' => 'email' , // optional
629630
'group' => 'group' , // optional
630631
'active' => 'is_active' , // optional controlled
631632
'admin' => 'is_admin' , // optional controlled
@@ -711,7 +712,11 @@ protected static function _guard( $user )
711712
foreach ( static::$_options[ 'guard' ] as $column )
712713
{
713714
$col = static::$_tableColumns[ $column ];
714-
if ( static::$_options[ 'model' ] ){ @$user->remove( $col ); }
715+
if ( static::$_options[ 'model' ] &&
716+
method_exists( $user , 'remove' ) )
717+
{
718+
$user->remove( $col );
719+
}
715720
else{ unset( $user->{ $col } ); }
716721
}
717722
}
@@ -874,6 +879,7 @@ protected static function _createUsersTable( )
874879
$query = ' CREATE TABLE ' . static::$_options[ 'users_table' ] . ' ( ';
875880
$columns = static::$_tableColumns;
876881
$query .= '`' . $columns[ 'unique_key' ] . '` int(11) NOT NULL auto_increment,';
882+
$query .= '`' . $columns[ 'username' ] . '` varchar(255) NOT NULL,';
877883
if ( @$columns[ 'firstname' ] )
878884
{
879885
$query .= '`' . $columns[ 'firstname' ] . '` varchar(255) NULL,';
@@ -882,7 +888,10 @@ protected static function _createUsersTable( )
882888
{
883889
$query .= '`' . $columns[ 'lastname' ] . '` varchar(255) NULL,';
884890
}
885-
$query .= '`' . $columns[ 'email' ] . '` varchar(255) NOT NULL,';
891+
if ( @$columns[ 'email' ] )
892+
{
893+
$query .= '`' . $columns[ 'email' ] . '` varchar(255) NULL,';
894+
}
886895
if ( @$columns[ 'group' ] )
887896
{
888897
$query .= '`' . $columns[ 'group' ] . '` varchar(255) NULL,';

0 commit comments

Comments
 (0)