contributions/usermanagement/controller/base/renderdecorators/confirmuserdatarenderdecorator.cls.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * A render decorator that forces users to confirm or update their account data 00004 * 00005 * This render decorator 00006 * 00007 * - checks if a user is logged in 00008 * 00009 * - for logged in users checks if the email address is CONFIRMED and the TOS the user 00010 * acknowledged are the same then the current valid TOS 00011 * 00012 * - If this fails redirects to action "users_confirmdata" 00013 * 00014 * - Except if the current route is one of the allowed ones, that can be set through 00015 * ConfirmUserDataRenderDecorator::append_allowed_route_id() 00016 * 00017 * @author Gerd Riesselmann 00018 * @ingroup Controller 00019 */ 00020 class ConfirmUserDataRenderDecorator extends RenderDecoratorBase { 00021 private static $allowed_route_ids = array(); 00022 00023 /** 00024 * Initialize this decorator and the data passed 00025 * 00026 * @param PageData $page_data 00027 * @return void 00028 */ 00029 public function initialize($page_data) { 00030 $user = Users::get_current_user(); 00031 if ($user) { 00032 $this->confirm_data_if_required($user, $page_data); 00033 } 00034 00035 parent::initialize($page_data); 00036 } 00037 00038 /** 00039 * Check if data must be confirmed, if so do it 00040 * 00041 * @param DAOUsers $user 00042 */ 00043 protected function confirm_data_if_required($user, PageData $page_data) { 00044 if ($user->confirmed_email() == false || $user->confirmed_tos() == false) { 00045 if (!$this->is_allowed_route($page_data->router->get_route_id())) { 00046 if ($page_data->status) { 00047 $page_data->status->persist(); 00048 } 00049 if (Session::pull('user_confirm_mail_send')) { 00050 Url::create(ActionMapper::get_url('users_confirm_mail'))->redirect(Url::TEMPORARY); 00051 } 00052 else { 00053 Url::create(ActionMapper::get_url('users_confirm'))->redirect(Url::TEMPORARY); 00054 } 00055 exit; 00056 } 00057 } 00058 } 00059 00060 /** 00061 * Returns true, if the current route is allowed 00062 * 00063 * @param string $route_id 00064 * @return bool 00065 */ 00066 protected function is_allowed_route($route_id) { 00067 $allowed = self::get_allowed_route_ids(); 00068 $allowed[] = 'UsersController::users_confirm'; 00069 $allowed[] = 'UsersController::users_confirm_mail'; 00070 $allowed[] = 'UsersController::logout'; 00071 $allowed[] = 'ConfirmationsController::confirm'; 00072 return in_array($route_id, $allowed); 00073 } 00074 00075 /** 00076 * Return the allowed route ids 00077 * 00078 * @return array 00079 */ 00080 public static function get_allowed_route_ids() { 00081 return self::$allowed_route_ids; 00082 } 00083 00084 /** 00085 * Add allowed route ids 00086 * 00087 * @param array|string $route_ids 00088 */ 00089 public static function add_allowed_route_ids($route_ids) { 00090 self::$allowed_route_ids = array_merge(self::$allowed_route_ids, Arr::force($route_ids, false)); 00091 } 00092 }