private function change_password($user_id, $change_password_pass, $password) { PHPBoostAuthenticationMethod::update_auth_infos($user_id, null, null, KeyGenerator::string_hash($password), null, ''); $session = AppContext::get_session(); if ($session != null) { Session::delete($session); } AppContext::set_session(Session::create($user_id, true)); AppContext::get_response()->redirect(Environment::get_home_page()); }
private function send_email() { $change_password_pass = KeyGenerator::generate_key(15); $user = $this->get_user(); PHPBoostAuthenticationMethod::update_auth_infos($user->get_id(), null, null, null, null, $change_password_pass); $general_config = GeneralConfig::load(); $parameters = array('pseudo' => $user->get_display_name(), 'host' => $general_config->get_site_url(), 'change_password_link' => UserUrlBuilder::change_password($change_password_pass)->absolute(), 'signature' => MailServiceConfig::load()->get_mail_signature()); $subject = $general_config->get_site_name() . ' : ' . $this->lang['forget-password']; $content = StringVars::replace_vars($this->lang['forget-password.mail.content'], $parameters); AppContext::get_mail_service()->send_from_properties($user->get_email(), $subject, $content); $this->tpl->put('MSG', MessageHelper::display($this->lang['forget-password.success'], MessageHelper::SUCCESS)); }
private function check_activation($registration_pass) { $user_id = PHPBoostAuthenticationMethod::registration_pass_exists($registration_pass); if ($user_id) { PHPBoostAuthenticationMethod::update_auth_infos($user_id, null, true, null, ''); $session = AppContext::get_session(); if ($session != null) { Session::delete($session); } AppContext::set_session(Session::create($user_id, true)); AppContext::get_response()->redirect(Environment::get_home_page()); } else { $controller = new UserErrorController($this->lang['profile'], LangLoader::get_message('process.error', 'status-messages-common'), UserErrorController::WARNING); DispatchManager::redirect($controller); } }
private function add_user() { if (PersistenceContext::get_querier()->row_exists(DB_TABLE_INTERNAL_AUTHENTICATION, 'WHERE login=:login', array('login' => $this->login))) { throw new Exception($this->login . ' login already use'); } else { if (UserService::user_exists('WHERE email=:email', array('email' => $this->email))) { throw new Exception($this->email . ' email already use'); } else { $user = new User(); $user->set_display_name($this->login); $user->set_level($this->get_real_value($this->level, $this->level_possible_values)); $user->set_email($this->email); $auth_method = new PHPBoostAuthenticationMethod($this->login, $this->password); $auth_method->set_association_parameters($this->get_real_value($this->approbation, $this->approbation_possible_values)); UserService::create($user, $auth_method); CLIOutput::writeln('User added successfull'); } } }
private function save() { $has_error = false; $registration_pass = $this->user_accounts_config->get_member_accounts_validation_method() == UserAccountsConfig::MAIL_USER_ACCOUNTS_VALIDATION ? KeyGenerator::generate_key(15) : ''; $user_aprobation = $this->user_accounts_config->get_member_accounts_validation_method() == UserAccountsConfig::AUTOMATIC_USER_ACCOUNTS_VALIDATION; $user = new User(); $user->set_display_name($this->form->get_value('display_name')); $user->set_level(User::MEMBER_LEVEL); $user->set_email($this->form->get_value('email')); $user->set_show_email(!$this->form->get_value('user_hide_mail')); $user->set_locale($this->form->get_value('lang')->get_raw_value()); $user->set_editor($this->form->get_value('text-editor')->get_raw_value()); $user->set_timezone($this->form->get_value('timezone')->get_raw_value()); if ($this->form->has_field('theme')) { $user->set_theme($this->form->get_value('theme')->get_raw_value()); } $login = $this->form->get_value('email'); if ($this->form->get_value('custom_login')) { $login = $this->form->get_value('login'); } $auth_method = new PHPBoostAuthenticationMethod($login, $this->form->get_value('password')); $auth_method->set_association_parameters($user_aprobation, $registration_pass); try { $user_id = UserService::create($user, $auth_method, $this->member_extended_fields_service); } catch (MemberExtendedFieldErrorsMessageException $e) { $has_error = true; $this->tpl->put('MSG', MessageHelper::display($e->getMessage(), MessageHelper::NOTICE)); } if (!$has_error) { UserRegistrationService::send_email_confirmation($user_id, $user->get_email(), $this->form->get_value('display_name'), $login, $this->form->get_value('password'), $registration_pass); $this->confirm_registration($user_id); } }
private function save(HTTPRequestCustom $request) { $has_error = false; $user_id = $this->user->get_id(); if ($this->form->get_value('delete_account')) { UserService::delete_by_id($user_id); } else { $approbation = $this->internal_auth_infos['approved']; if (AppContext::get_current_user()->is_admin()) { $old_approbation = $approbation; $approbation = $this->form->get_value('approbation'); $groups = array(); foreach ($this->form->get_value('groups') as $field => $option) { $groups[] = $option->get_raw_value(); } GroupsService::edit_member($user_id, $groups); $this->user->set_groups($groups); $this->user->set_level($this->form->get_value('rank')->get_raw_value()); } if ($this->form->has_field('theme')) { $this->user->set_theme($this->form->get_value('theme')->get_raw_value()); } $this->user->set_locale($this->form->get_value('lang')->get_raw_value()); $this->user->set_display_name($this->form->get_value('display_name')); $this->user->set_email($this->form->get_value('email')); $this->user->set_locale($this->form->get_value('lang')->get_raw_value()); $this->user->set_editor($this->form->get_value('text-editor')->get_raw_value()); $this->user->set_show_email(!$this->form->get_value('user_hide_mail')); $this->user->set_timezone($this->form->get_value('timezone')->get_raw_value()); try { UserService::update($this->user, $this->member_extended_fields_service); } catch (MemberExtendedFieldErrorsMessageException $e) { $has_error = true; $this->tpl->put('MSG', MessageHelper::display($e->getMessage(), MessageHelper::NOTICE)); } $login = $this->form->get_value('email'); if ($this->form->get_value('custom_login', false)) { $login = $this->form->get_value('login'); } $password = $this->form->get_value('password'); if ($this->internal_auth_infos === null && !empty($password)) { $authentication_method = new PHPBoostAuthenticationMethod($login, $password); AuthenticationService::associate($authentication_method, $user_id); } elseif (!empty($password)) { $old_password = $this->form->get_value('old_password'); if (!empty($old_password)) { $old_password_hashed = KeyGenerator::string_hash($old_password); if ($old_password_hashed == $this->internal_auth_infos['password']) { PHPBoostAuthenticationMethod::update_auth_infos($user_id, $login, $approbation, KeyGenerator::string_hash($password)); $has_error = false; } else { $has_error = true; $this->tpl->put('MSG', MessageHelper::display($this->lang['profile.edit.password.error'], MessageHelper::NOTICE)); } } } else { PHPBoostAuthenticationMethod::update_auth_infos($user_id, $login, $approbation); } if (AppContext::get_current_user()->is_admin()) { if ($old_approbation != $approbation && $old_approbation == 0) { //Recherche de l'alerte correspondante $matching_alerts = AdministratorAlertService::find_by_criteria($user_id, 'member_account_to_approbate'); //L'alerte a été trouvée if (count($matching_alerts) == 1) { $alert = $matching_alerts[0]; $alert->set_status(AdministratorAlert::ADMIN_ALERT_STATUS_PROCESSED); AdministratorAlertService::save_alert($alert); $site_name = GeneralConfig::load()->get_site_name(); $subject = StringVars::replace_vars($this->user_lang['registration.subject-mail'], array('site_name' => $site_name)); $content = StringVars::replace_vars($this->user_lang['registration.email.mail-administrator-validation'], array('pseudo' => $this->user->get_display_name(), 'site_name' => $site_name, 'signature' => MailServiceConfig::load()->get_mail_signature())); AppContext::get_mail_service()->send_from_properties($this->user->get_email(), $subject, $content); } } $user_warning = $this->form->get_value('user_warning')->get_raw_value(); if (!empty($user_warning) && $user_warning != $this->user->get_warning_percentage()) { MemberSanctionManager::caution($user_id, $user_warning, MemberSanctionManager::SEND_MP, str_replace('%level%', $user_warning, LangLoader::get_message('user_warning_level_changed', 'main'))); } elseif (empty($user_warning)) { MemberSanctionManager::cancel_caution($user_id); } $user_readonly = $this->form->get_value('user_readonly')->get_raw_value(); if (!empty($user_readonly) && $user_readonly != $this->user->get_delay_readonly()) { MemberSanctionManager::remove_write_permissions($user_id, time() + $user_readonly, MemberSanctionManager::SEND_MP, str_replace('%date%', $this->form->get_value('user_readonly')->get_label(), LangLoader::get_message('user_readonly_changed', 'main'))); } elseif (empty($user_readonly)) { MemberSanctionManager::restore_write_permissions($user_id); } $user_ban = $this->form->get_value('user_ban')->get_raw_value(); if (!empty($user_ban) && $user_ban != $this->user->get_delay_banned()) { MemberSanctionManager::banish($user_id, time() + $user_ban, MemberSanctionManager::SEND_MAIL); } elseif ($user_ban != $this->user->get_delay_banned()) { MemberSanctionManager::cancel_banishment($user_id); } } SessionData::recheck_cached_data_from_user_id($user_id); } if (!$has_error) { AppContext::get_response()->redirect($request->get_url_referrer() ? $request->get_url_referrer() : UserUrlBuilder::edit_profile($user_id), $this->lang['user.message.success.edit']); } }