public function __construct()
 {
     $this->querier = PersistenceContext::get_querier();
     $auth_config = AuthenticationConfig::load();
     $this->google_client = new Google_Client();
     $this->google_client->setClientId($auth_config->get_google_client_id());
     $this->google_client->setClientSecret($auth_config->get_google_client_secret());
     $this->google_client->setRedirectUri(AppContext::get_request()->get_site_url() . $_SERVER['REQUEST_URI']);
     $this->google_client->setScopes(array('https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email'));
     $this->google_auth = new Google_Oauth2Service($this->google_client);
 }
 public static function get_activated_types_authentication()
 {
     $authentication_config = AuthenticationConfig::load();
     $types = array(PHPBoostAuthenticationMethod::AUTHENTICATION_METHOD);
     if ($authentication_config->is_fb_auth_available()) {
         $types[] = FacebookAuthenticationMethod::AUTHENTICATION_METHOD;
     }
     if ($authentication_config->is_google_auth_available()) {
         $types[] = GoogleAuthenticationMethod::AUTHENTICATION_METHOD;
     }
     return $types;
 }
 public function display($tpl = false)
 {
     global $LANG;
     if (!Url::is_current_url('/user/login')) {
         $tpl = new FileTemplate('connect/connect_mini.tpl');
         $user = AppContext::get_current_user();
         MenuService::assign_positions_conditions($tpl, $this->get_block());
         if ($user->check_level(User::MEMBER_LEVEL)) {
             $unread_contributions = UnreadContributionsCache::load();
             //Vaut 0 si l'utilisateur n'a aucune contribution. Est > 0 si on connait le nombre de contributions
             //Vaut -1 si l'utilisateur a au moins une contribution (mais on ne sait pas combien à cause des recoupements entre les groupes)
             $contribution_number = 0;
             if ($user->check_level(User::ADMIN_LEVEL)) {
                 $contribution_number = $unread_contributions->get_admin_unread_contributions_number();
             } elseif ($user->check_level(User::MODERATOR_LEVEL)) {
                 if ($unread_contributions->have_moderators_unread_contributions()) {
                     $contribution_number = -1;
                 }
             } else {
                 if ($unread_contributions->have_members_unread_contributions()) {
                     $contribution_number = -1;
                 } else {
                     if ($unread_contributions->has_user_unread_contributions($user->get_id())) {
                         $contribution_number = -1;
                     } else {
                         foreach ($user->get_groups() as $group_id) {
                             if ($unread_contributions->has_group_unread_contributions($group_id)) {
                                 $contribution_number = -1;
                                 break;
                             }
                         }
                     }
                 }
             }
             $user_accounts_config = UserAccountsConfig::load();
             $user_avatar = AppContext::get_session()->get_cached_data('user_avatar');
             if (empty($user_avatar)) {
                 $user_avatar = '/templates/' . AppContext::get_current_user()->get_theme() . '/images/' . $user_accounts_config->get_default_avatar_name();
             }
             $total_alert = $user->get_unread_pm() + $contribution_number + ($user->check_level(User::ADMIN_LEVEL) ? AdministratorAlertService::get_number_unread_alerts() : 0);
             $user_group_color = User::get_group_color($user->get_groups(), $user->get_level(), true);
             $tpl->put_all(array('C_ADMIN_AUTH' => $user->check_level(User::ADMIN_LEVEL), 'C_MODERATOR_AUTH' => $user->check_level(User::MODERATOR_LEVEL), 'C_UNREAD_CONTRIBUTION' => $contribution_number != 0, 'C_KNOWN_NUMBER_OF_UNREAD_CONTRIBUTION' => $contribution_number > 0, 'C_UNREAD_ALERT' => (bool) AdministratorAlertService::get_number_unread_alerts(), 'C_HAS_PM' => $user->get_unread_pm() > 0, 'C_USER_GROUP_COLOR' => !empty($user_group_color), 'NUMBER_UNREAD_CONTRIBUTIONS' => $contribution_number, 'NUMBER_UNREAD_ALERTS' => AdministratorAlertService::get_number_unread_alerts(), 'NUMBER_PM' => $user->get_unread_pm(), 'NUMBER_TOTAL_ALERT' => $total_alert, 'PSEUDO' => $user->get_display_name(), 'USER_LEVEL_CLASS' => UserService::get_level_class($user->get_level()), 'USER_GROUP_COLOR' => $user_group_color, 'U_USER_PROFILE' => UserUrlBuilder::profile($user->get_id())->rel(), 'U_USER_PM' => UserUrlBuilder::personnal_message($user->get_id())->rel(), 'U_AVATAR_IMG' => Url::to_rel($user_avatar), 'L_NBR_PM' => $user->get_unread_pm() > 0 ? $user->get_unread_pm() . ' ' . ($user->get_unread_pm() > 1 ? $LANG['message_s'] : $LANG['message']) : $LANG['private_messaging'], 'L_PROFIL' => LangLoader::get_message('profile', 'user-common'), 'L_ADMIN_PANEL' => $LANG['admin_panel'], 'L_MODO_PANEL' => $LANG['modo_panel'], 'L_PRIVATE_PROFIL' => $LANG['my_private_profile'], 'L_DISCONNECT' => LangLoader::get_message('disconnect', 'user-common'), 'L_CONTRIBUTION_PANEL' => $LANG['contribution_panel']));
         } else {
             $authentication_config = AuthenticationConfig::load();
             $tpl->put_all(array('C_USER_NOTCONNECTED' => true, 'C_USER_REGISTER' => UserAccountsConfig::load()->is_registration_enabled(), 'C_FB_AUTH_ENABLED' => $authentication_config->is_fb_auth_available(), 'C_GOOGLE_AUTH_ENABLED' => $authentication_config->is_google_auth_available(), 'L_REQUIRE_PSEUDO' => $LANG['require_pseudo'], 'L_REQUIRE_PASSWORD' => $LANG['require_password'], 'L_CONNECT' => LangLoader::get_message('connection', 'user-common'), 'L_PSEUDO' => LangLoader::get_message('login', 'user-common'), 'L_PASSWORD' => LangLoader::get_message('password', 'user-common'), 'L_AUTOCONNECT' => LangLoader::get_message('autoconnect', 'user-common'), 'L_FORGOT_PASS' => LangLoader::get_message('forget-password', 'user-common'), 'L_REGISTER' => LangLoader::get_message('register', 'user-common'), 'U_CONNECT' => UserUrlBuilder::connect()->rel(), 'SITE_REWRITED_SCRIPT' => substr(REWRITED_SCRIPT, strlen(GeneralConfig::load()->get_site_path()))));
         }
         return $tpl->render();
     }
     return '';
 }
 private function handle_form()
 {
     $installation_services = new InstallationServices();
     $installation_services->configure_website($this->form->get_value('host'), $this->form->get_value('path'), $this->form->get_value('name'), $this->form->get_value('slogan'), $this->form->get_value('description'), $this->form->get_value('timezone')->get_raw_value());
     $this->security_config->set_internal_password_min_length($this->form->get_value('internal_password_min_length'));
     $this->security_config->set_internal_password_strength($this->form->get_value('internal_password_strength')->get_raw_value());
     if ($this->form->get_value('login_and_email_forbidden_in_password')) {
         $this->security_config->forbid_login_and_email_in_password();
     } else {
         $this->security_config->allow_login_and_email_in_password();
     }
     SecurityConfig::save();
     if ($this->server_configuration->has_curl_library()) {
         if ($this->form->get_value('fb_auth_enabled')) {
             $this->authentication_config->enable_fb_auth();
             $this->authentication_config->set_fb_app_id($this->form->get_value('fb_app_id'));
             $this->authentication_config->set_fb_app_key($this->form->get_value('fb_app_key'));
         } else {
             $this->authentication_config->disable_fb_auth();
         }
         if ($this->form->get_value('google_auth_enabled')) {
             $this->authentication_config->enable_google_auth();
             $this->authentication_config->set_google_client_id($this->form->get_value('google_client_id'));
             $this->authentication_config->set_google_client_secret($this->form->get_value('google_client_secret'));
         } else {
             $this->authentication_config->disable_google_auth();
         }
         AuthenticationConfig::save();
     }
     AppContext::get_response()->redirect(InstallUrlBuilder::admin());
 }
 private function save()
 {
     $this->user_account_config->set_registration_enabled($this->form->get_value('members_activation'));
     if (!$this->form->field_is_disabled('type_activation_members')) {
         $this->user_account_config->set_member_accounts_validation_method($this->form->get_value('type_activation_members')->get_raw_value());
     }
     if (!$this->form->field_is_disabled('unactivated_accounts_timeout')) {
         $this->user_account_config->set_unactivated_accounts_timeout($this->form->get_value('unactivated_accounts_timeout'));
     }
     $this->security_config->set_internal_password_min_length($this->form->get_value('internal_password_min_length'));
     $this->security_config->set_internal_password_strength($this->form->get_value('internal_password_strength')->get_raw_value());
     if ($this->form->get_value('login_and_email_forbidden_in_password')) {
         $this->security_config->forbid_login_and_email_in_password();
     } else {
         $this->security_config->allow_login_and_email_in_password();
     }
     SecurityConfig::save();
     if ($this->server_configuration->has_curl_library()) {
         if ($this->form->get_value('fb_auth_enabled')) {
             $this->authentication_config->enable_fb_auth();
             $this->authentication_config->set_fb_app_id($this->form->get_value('fb_app_id'));
             $this->authentication_config->set_fb_app_key($this->form->get_value('fb_app_key'));
         } else {
             $this->authentication_config->disable_fb_auth();
         }
         if ($this->form->get_value('google_auth_enabled')) {
             $this->authentication_config->enable_google_auth();
             $this->authentication_config->set_google_client_id($this->form->get_value('google_client_id'));
             $this->authentication_config->set_google_client_secret($this->form->get_value('google_client_secret'));
         } else {
             $this->authentication_config->disable_google_auth();
         }
         AuthenticationConfig::save();
     }
     $this->user_account_config->set_avatar_upload_enabled($this->form->get_value('upload_avatar_server'));
     $this->user_account_config->set_default_avatar_name_enabled($this->form->get_value('default_avatar_activation'));
     $this->user_account_config->set_avatar_auto_resizing_enabled($this->form->get_value('activation_resize_avatar'));
     $this->user_account_config->set_default_avatar_name($this->form->get_value('default_avatar_link'));
     $this->user_account_config->set_max_avatar_width($this->form->get_value('maximal_width_avatar'));
     $this->user_account_config->set_max_avatar_height($this->form->get_value('maximal_height_avatar'));
     $this->user_account_config->set_max_avatar_weight($this->form->get_value('maximal_weight_avatar'));
     $this->user_account_config->set_auth_read_members($this->form->get_value('authorizations')->build_auth_array());
     $this->user_account_config->set_welcome_message($this->form->get_value('welcome_message_contents'));
     $this->user_account_config->set_registration_agreement($this->form->get_value('registration_agreement'));
     UserAccountsConfig::save();
 }
 public function __construct()
 {
     $this->querier = PersistenceContext::get_querier();
     $config = AuthenticationConfig::load();
     $this->facebook = new Facebook(array('appId' => $config->get_fb_app_id(), 'secret' => $config->get_fb_app_key(), 'cookie' => true));
 }