126 $Settings->load_package_settings(
'page::page_composer' ,
'last' ,
'cf_site' );
127 $this->EnableRegistration = intval( $Settings->get_setting(
'enable_registration' , 1 ) );
128 $this->RegistrationConfirm = intval( $Settings->get_setting(
'registration_confirm' , 1 ) );
129 $this->EmailSender = $Settings->get_setting(
'email_sender' , $this->EmailSender );
130 $this->SystemEmail = $Settings->get_setting(
'system_email' , $this->SystemEmail );
132 catch( Exception $e )
152 $this->ContextSet =
get_package(
'gui::context_set' ,
'last' , __FILE__ );
153 $this->EventManager =
get_package(
'event_manager' ,
'last' , __FILE__ );
154 $this->Messages =
get_package(
'page::messages' ,
'last' , __FILE__ );
155 $this->PageComposerUtilities =
get_package(
'page::page_composer_utilities' ,
'last' , __FILE__ );
156 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
158 catch( Exception $e )
180 $this->UserAccess =
get_package(
'user::user_access' ,
'last' , __FILE__ );
181 $this->UserAlgorithms =
get_package(
'user::user_algorithms' ,
'last' , __FILE__ );
183 'user::user_controller::user_controller_utilities' ,
'last' , __FILE__
186 catch( Exception $e )
218 $User = $this->UserAccess->get_user( $Login );
220 if( $this->UserAlgorithms->user_banned( $Login ) )
222 $this->Messages->add_error_message(
'user_is_banned_to '.$User->banned_to );
227 $this->EventManager->trigger_event(
'on_before_login' , array(
'id' => $id ) );
228 $this->UserAlgorithms->login( $Login , $id );
229 $this->EventManager->trigger_event(
'on_after_login' , array(
'id' => $id ) );
231 $this->PageComposerUtilities->redirect_using_map( $Options );
233 catch( Exception $e )
261 $Login = $this->Security->get_gp(
'login' ,
'string' );
262 $UserPassword = $this->Security->get_gp(
'password' ,
'string' );
264 $UserExists = $this->UserAlgorithms->user_exists( $Login );
265 $UserActive = $AuthValid =
true;
269 if( $UserActive = $this->UserAlgorithms->user_active( $Login ) )
271 if( $AuthValid = $this->UserAlgorithms->validate_auth( $Login , $UserPassword ) )
273 $this->
do_login( $Login , $Options );
278 $this->UserControllerUtilities->handle_login_errors( $UserExists , $UserActive , $AuthValid );
280 catch( Exception $e )
308 $this->UserAlgorithms->logout();
310 catch( Exception $e )
338 if( $this->EnableRegistration === 1 )
340 $Hash = $this->Security->get_gp(
'hash' ,
'command' ,
false );
341 if( $Hash !==
false )
343 $this->UserAccess->activate_user( $Hash );
344 $this->Messages->add_success_message(
'user_was_activated' );
348 catch( Exception $e )
376 $Ids = $this->Security->get_gp(
'ids' ,
'integer' );
378 if( is_array( $Ids ) ===
false )
380 $Ids = array( $Ids );
383 $this->UserAccess->activate_users( $Ids );
385 catch( Exception $e )
413 $Ids = $this->Security->get_gp(
'ids' ,
'integer' );
415 if( is_array( $Ids ) ===
false )
417 $Ids = array( $Ids );
420 $this->UserAccess->deactivate_users( $Ids );
422 catch( Exception $e )
450 $Login = $this->Security->get_gp(
'rlogin' ,
'string' );
451 $NewPassword = $this->UserAlgorithms->generate_password();
453 $CachedMultyFS =
get_package(
'cached_multy_fs' ,
'last' , __FILE__ );
454 $Message = str_replace(
455 '{new_password}' , $NewPassword ,
456 $CachedMultyFS->get_template( __FILE__ ,
'password_restoration_email.tpl' )
459 $this->UserControllerUtilities->send_email(
460 $this->SystemEmail , $this->EmailSender , $Message ,
461 '{lang:password_restoration}' ,
get_field( $this->UserAccess->get_user( $Login ) ,
'email' )
464 $this->UserAccess->reset_password( $Login , $NewPassword );
466 catch( Exception $e )
490 $User = $this->UserAlgorithms->get_user();
492 $Password = $this->Security->get_gp(
'password' ,
'string' );
493 $PasswordConfirmation = $this->Security->get_gp(
'password_confirmation' ,
'string' );
495 if( $Password == $PasswordConfirmation )
497 $this->UserAccess->reset_password( $Login , $Password );
500 catch( Exception $e )
524 private function get_update_data()
528 $UserEmail = $this->Security->get_gp(
'email' ,
'email' );
530 $Site = $this->Security->get_gp(
'site' ,
'string' ,
'' );
532 $About = $this->Security->get_gp(
'about' ,
'string' ,
'' );
534 return( array( $UserEmail , $Site , $About ) );
536 catch( Exception $e )
564 private function need_reset_password( $Login )
568 $PermitAlgorithms =
get_package(
'permit::permit_algorithms' ,
'last' , __FILE__ );
569 $HasPermit = $PermitAlgorithms->object_has_permit(
false ,
'user' ,
'user_manager' );
570 $ChangePassword = $HasPermit || ( $this->Security->get_gp(
'current_password' ,
'set' ) &&
571 strlen( $CurrentPassword = $this->Security->get_gp(
'current_password' ,
'string' ) ) &&
572 $this->UserAlgorithms->validate_auth( $Login , $CurrentPassword ) );
574 return( $ChangePassword );
576 catch( Exception $e )
604 $User = $this->UserAlgorithms->get_user();
606 list( $UserEmail , $Site , $About ) = $this->get_update_data();
608 $Record = array(
'email' => $UserEmail ,
'site' => $Site ,
'about' => $About );
609 $this->update(
get_field( $User ,
'id' ) , $Record );
611 $ChangePassword = $this->need_reset_password( $Login );
613 if( $ChangePassword )
618 $this->Messages->add_success_message(
'user_update_was_completed' );
620 catch( Exception $e )
644 private function send_confirmation( $ActivationHash )
648 $CachedMultyFS =
get_package(
'cached_multy_fs' ,
'last' , __FILE__ );
649 $Message = $CachedMultyFS->get_template( __FILE__ ,
'confirm_registration_email.tpl' );
650 $Message = str_replace(
'{hash}' , $ActivationHash , $Message );
652 $this->send_email( $Message ,
'{lang:registration_confirm}' );
654 catch( Exception $e )
678 private function create_user_object_and_permits()
682 $SecurityParser =
get_package(
'security::security_parser' ,
'last' , __FILE__ );
684 $Record = $SecurityParser->parse_http_parameters(
685 'login:string;password:string;email:email;name:string;'.
686 'sex:integer;site:string,allow_not_set;about:string,allow_not_set'
689 list( $id , $Hash ) = $this->UserAccess->create( $Record );
691 $this->UserControllerUtilities->add_default_permits( $id );
695 catch( Exception $e )
719 private function send_confirmation_if_necessary( $ActivationHash )
723 if( $this->RegistrationConfirm &&
724 $this->Security->get_p(
'active_permanently' ,
'command' ,
false ) !==
'on' )
726 $this->send_confirmation( $ActivationHash );
730 $this->UserAccess->activate_user( $ActivationHash );
731 $this->RegistrationConfirm =
false;
734 catch( Exception $e )
755 private function register_do()
759 $Hash = $this->create_user_object_and_permits();
761 $this->send_confirmation_if_necessary( $Hash );
763 $this->RegistrationWasPassed =
true;
765 $Login = $this->Security->get_gp(
'login' ,
'string' );
767 $this->EventManager->trigger_event(
'on_after_registration' , array(
'login' => $Login ) );
769 catch( Exception $e )
797 $PermitAlgorithms =
get_package(
'permit::permit_algorithms' ,
'last' , __FILE__ );
798 $HasPermit = $PermitAlgorithms->object_has_permit(
false ,
'user' ,
'user_manager' );
800 if( $this->EnableRegistration === 1 || $HasPermit )
802 if( $this->UserControllerUtilities->handle_register_errors() )
807 $this->register_do();
810 catch( Exception $e )
838 $FileInputController =
get_package(
'file_input::file_input_controller' ,
'last' , __FILE__ );
840 if( $FileInputController->UploadedFile )
842 $User = $this->UserAlgorithms->get_user();
847 $FileInputAccess =
get_package(
'file_input::file_input_access' ,
'last' , __FILE__ );
848 $FileInputAccess->delete( $Avatar );
852 $FileId =
get_field( $FileInputController->UploadedFile ,
'id' );
853 $this->UserAccess->set_avatar( $Login , $FileId );
856 catch( Exception $e )
884 $this->ContextSet->add_contexts(
885 $Options , dirname( __FILE__ ) , $this->UserControllerUtilities->get_configs()
888 if( $this->ContextSet->execute( $Options , $this , __FILE__ ) )
893 catch( Exception $e )