ultimix
user_algorithms_1_0_0 Class Reference

Public Member Functions

 __construct ()
 get_by_id ($id)
 session_start ()
 logged_in ()
 get_login ()
 get_id ()
 get_user ()
 login ($Login, $id)
 logout ()
 user_active ($Login)
 user_banned ($Login)
 get_password_hash ($Login=false)
 user_exists ($Login)
 delete ($ids)
 email_exists ($Email)
 validate_auth ($Login, $Password, $HashPassed=false)
 generate_password ($Length=10)

Data Fields

 $User = false
 $Security = false
 $UserAccess = false

Detailed Description

Working with user's accounts.

Author
Dodonov A.A.

Definition at line 26 of file user_algorithms.php.

Constructor & Destructor Documentation

__construct ( )

Constructor.

Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 67 of file user_algorithms.php.

{
try
{
$this->Security = get_package( 'security' , 'last' , __FILE__ );
$this->UserAccess = get_package( 'user::user_access' , 'last' , __FILE__ );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

Member Function Documentation

delete (   $ids)

Function deletes user.

Parameters
$ids- id of the deleting user.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 547 of file user_algorithms.php.

{
try
{
$ids = $this->Security->get( $ids , 'integer_list' );
$Users = $this->UserAccess->unsafe_select( $this->UserAccess->NativeTable.
".id IN( $ids ) and `system` = 0" );
$this->UserAccess->delete( implode( ',' , get_field_ex( $Users , 'id' ) ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
email_exists (   $Email)

Function validates email's existance.

Parameters
$Email- Email of the validated user.
Returns
true if user exists, false otherwise.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 586 of file user_algorithms.php.

{
try
{
$Email = $this->Security->get( $Email , 'email' );
$Records = $this->UserAccess->unsafe_select( "email LIKE '$Email'" );
return( count( $Records ) == 1 );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
generate_password (   $Length = 10)

Function generates password.

Parameters
$Length- Password length.
Returns
Password.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 678 of file user_algorithms.php.

{
try
{
$Letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$c = strlen( $Letters );
$Password = '';
for( $i = 0 ; $i < $Length ; $i++ )
{
$Password .= $Letters[ rand( 0 , $c - 1 ) ];
}
return( $Password );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_by_id (   $id)

Function returns user by it's id.

Parameters
$id- Id of the searching user.
Returns
User object.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 102 of file user_algorithms.php.

{
try
{
$id = $this->Security->get( $id , 'integer' );
$Users = $this->UserAccess->unsafe_select( $this->UserAccess->NativeTable.".id = $id" );
if( count( $Users ) === 0 || count( $Users ) > 1 )
{
throw( new Exception( 'User with id '.$id.' was not found' ) );
}
else
{
return( $Users[ 0 ] );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_id ( )

Function returns id of the logged in user.

Returns
Id of the logged in user.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 242 of file user_algorithms.php.

{
try
{
$this->session_start();
if( $this->logged_in() )
{
return( $_SESSION[ 'user_id' ] );
}
else
{
/* guest id will be returned */
return( $this->UserAccess->GuestUserId );
}
return( false );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_login ( )

Function returns login of the logged in user.

Returns
Login of the logged in user, if no user is logged in, then "guest" is returned.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 199 of file user_algorithms.php.

{
try
{
$this->session_start();
if( $this->logged_in() )
{
/* залогинен, значит опознаем его */
return( $_SESSION[ 'login' ] );
}
else
{
/* не залогинен значит гость */
return( 'guest' );
}
return( false );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_password_hash (   $Login = false)

Function returns md5 hash of the password.

Parameters
$Login- login of the deleting user.
Returns
md5 hash of the password.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 472 of file user_algorithms.php.

{
try
{
if( $Login === false )
{
$Login = $this->get_login();
}
$User = $this->UserAccess->get_user( $Login );
return( $User->password );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_user ( )

Function returns object of the logged in user.

Returns
Id of the logged in user.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 284 of file user_algorithms.php.

{
try
{
if( $this->User === false )
{
$this->User = $this->get_by_id( $this->get_id() );
}
return( $this->User );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
logged_in ( )

Function validates if user with the login $Login is logged in.

Returns
true if logged in, false otherwise.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 161 of file user_algorithms.php.

{
try
{
$this->session_start();
if( isset( $_SESSION[ 'login' ] ) )
{
return( true );
}
return( false );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
login (   $Login,
  $id 
)

Function logins user.

Parameters
$Login- Login of the user to be logged in.
$id- id of the user to be logged in.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 323 of file user_algorithms.php.

{
try
{
if( $this->user_active( $Login ) )
{
$this->session_start();
$_SESSION[ 'login' ] = $Login;
$_SESSION[ 'user_id' ] = $id;
$this->User = false;
}
else
{
return( false );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
logout ( )

Function logouts user.

Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 361 of file user_algorithms.php.

{
try
{
$this->session_start();
unset( $_SESSION[ 'login' ] );
unset( $_SESSION[ 'id' ] );
$this->User = false;
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
session_start ( )

Function starts sessions.

Author
Dodonov A.A.

Definition at line 135 of file user_algorithms.php.

{
if( session_id() == '' )
{
}
}
user_active (   $Login)

Function validates if user is active.

Parameters
$Login- login of the deleting user.
Returns
true if the user is active, false otherwise.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 400 of file user_algorithms.php.

{
try
{
$User = $this->UserAccess->get_user( $Login );
return( $User->active == 'active' );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
user_banned (   $Login)

Function validates if user is banned.

Parameters
$Login- login of the deleting user.
Returns
true if the user is active, false otherwise.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 436 of file user_algorithms.php.

{
try
{
$User = $this->UserAccess->get_user( $Login );
return( $User->banned );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
user_exists (   $Login)

Function validates user's existance.

Parameters
$Login- login of the validated user.
Returns
true if user exists, false otherwise.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 513 of file user_algorithms.php.

{
try
{
$Login = $this->Security->get( $Login , 'string' );
$this->UserAccess->get_user( $Login );
return( true );
}
catch( Exception $e )
{
return( false );
}
}
validate_auth (   $Login,
  $Password,
  $HashPassed = false 
)

Function validates login and password.

Parameters
$Login- Inputed login.
$Password- Inputed password.
$HashPassed- true if md5 hash of the password was put in $Password.
Returns
false if login and password validation was passed.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 632 of file user_algorithms.php.

{
try
{
$Login = $this->Security->get( $Login , 'string' );
$Password = $this->Security->get( $Password , 'string' );
$User = $this->UserAccess->get_user( $Login );
if( $HashPassed )
{
return( $Password == get_field( $User , 'password' ) );
}
else
{
return( md5( $Password ) == get_field( $User , 'password' ) );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

Field Documentation

$Security = false

Cached objects.

Author
Dodonov A.A.

Definition at line 50 of file user_algorithms.php.

$User = false

Object od the authorized user.

Author
Dodonov A.A.

Definition at line 38 of file user_algorithms.php.

$UserAccess = false

Definition at line 51 of file user_algorithms.php.


The documentation for this class was generated from the following file: