Example #1
0
    public function submit()
    {
        if ((int) $this->config->get('cmsbridge_reg_redirect') == 1 && (int) $this->config->get('cmsbridge_active') == 1) {
            if (strlen($this->config->get('cmsbridge_reg_url')) > 1) {
                redirect($this->config->get('cmsbridge_reg_url'), false, true);
            } else {
                redirect('index.php');
            }
        }
        //Check CAPTCHA
        if ($this->config->get('pk_enable_captcha') == 1) {
            require $this->root_path . 'libraries/recaptcha/recaptcha.class.php';
            $captcha = new recaptcha();
            $response = $captcha->recaptcha_check_answer($this->config->get('lib_recaptcha_pkey'), $this->env->ip, $this->in->get('recaptcha_challenge_field'), $this->in->get('recaptcha_response_field'));
            if (!$response->is_valid) {
                $this->core->message($this->user->lang('lib_captcha_wrong'), $this->user->lang('error'), 'red');
                $this->display_form();
                return;
            }
        }
        //Check Email
        if ($this->pdh->get('user', 'check_email', array($this->in->get('user_email'))) == 'false') {
            $this->core->message($this->user->lang('fv_email_alreadyuse'), $this->user->lang('error'), 'red');
            $this->display_form();
            return;
        } elseif (!preg_match("/^([a-zA-Z0-9])+([\\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\\.[a-zA-Z0-9_-]+)+/", $this->in->get('user_email'))) {
            $this->core->message($this->user->lang('fv_invalid_email'), $this->user->lang('error'), 'red');
            $this->display_form();
            return;
        }
        //Check Username
        if ($this->pdh->get('user', 'check_username', array($this->in->get('username'))) == 'false') {
            $this->core->message($this->user->lang('fv_username_alreadyuse'), $this->user->lang('error'), 'red');
            $this->display_form();
            return;
        }
        // If the config requires account activation, generate a random key for validation
        if ((int) $this->config->get('account_activation') == 1 || (int) $this->config->get('account_activation') == 2) {
            $user_key = random_string(true);
            $key_len = 54 - strlen($this->server_url);
            $key_len = $key_len > 6 ? $key_len : 6;
            $user_key = substr($user_key, 0, $key_len);
            $user_active = '0';
            if ($this->user->is_signedin()) {
                $this->user->destroy();
            }
        } else {
            $user_key = '';
            $user_active = '1';
        }
        //Insert the user into the DB
        $user_id = $this->pdh->put('user', 'register_user', array($this->data, $user_active, $user_key, true, $this->in->get('lmethod')));
        //Add auth-account
        if ($this->in->exists('auth_account')) {
            $auth_account = $this->crypt->decrypt($this->in->get('auth_account'));
            if ($this->pdh->get('user', 'check_auth_account', array($auth_account))) {
                $this->pdh->put('user', 'add_authaccount', array($user_id, $auth_account, $this->in->get('lmethod')));
            }
        }
        //Give permissions if there is no default group
        $default_group = $this->pdh->get('user_groups', 'standard_group', array());
        if (!$default_group) {
            $sql = 'SELECT auth_id, auth_default
					FROM __auth_options
					ORDER BY auth_id';
            $result = $this->db->query($sql);
            while ($row = $this->db->fetch_record($result)) {
                $arrSet = array('user_id' => $user_id, 'auth_id' => $row['auth_id'], 'auth_setting' => $row['auth_default']);
                $this->db->query("INSERT INTO __auth_users :params", $arrSet);
            }
        }
        if ($this->config->get('account_activation') == 1) {
            $success_message = sprintf($this->user->lang('register_activation_self'), $this->in->get('user_email'));
            $email_template = 'register_activation_self';
            $email_subject = $this->user->lang('email_subject_activation_self');
        } elseif ($this->config->get('account_activation') == 2) {
            $success_message = sprintf($this->user->lang('register_activation_admin'), $this->in->get('user_email'));
            $email_template = 'register_activation_admin';
            $email_subject = $this->user->lang('email_subject_activation_admin');
        } else {
            $success_message = sprintf($this->user->lang('register_activation_none'), '<a href="login.php' . $this->SID . '">', '</a>', $this->in->get('user_email'));
            $email_template = 'register_activation_none';
            $email_subject = $this->user->lang('email_subject_activation_none');
        }
        // Email a notice
        $this->email->Set_Language($this->in->get('user_lang'));
        $bodyvars = array('USERNAME' => stripslashes($this->in->get('username')), 'PASSWORD' => stripslashes($this->in->get('user_password1')), 'U_ACTIVATE' => $this->server_url . '?mode=activate&key=' . $user_key, 'GUILDTAG' => $this->config->get('guildtag'));
        if (!$this->email->SendMailFromAdmin($this->in->get('user_email'), $email_subject, $email_template . '.html', $bodyvars)) {
            $success_message = $this->user->lang('email_subject_send_error');
        }
        // Now email the admin if we need to
        if ($this->config->get('account_activation') == 2) {
            $this->email->Set_Language($this->config->get('default_lang'));
            $bodyvars = array('USERNAME' => $this->in->get('username'), 'U_ACTIVATE' => $this->server_url . '?mode=activate&key=' . $user_key);
            if (!$this->email->SendMailFromAdmin(register('encrypt')->decrypt($this->config->get('admin_email')), $this->user->lang('email_subject_activation_admin_act'), 'register_activation_admin_activate.html', $bodyvars)) {
                $success_message = $this->user->lang('email_subject_send_error');
            }
        }
        message_die($success_message);
    }
Example #2
0
 public function save()
 {
     //Build Field-Array
     $arrFields = $this->pdh->get('guildrequest_fields', 'id_list', array());
     $arrInput = array();
     foreach ($arrFields as $id) {
         $row = $this->pdh->get('guildrequest_fields', 'id', array($id));
         if ($row['type'] == 3 || $row['type'] == 4) {
             continue;
         }
         $arrInput[$row['name']] = array('id' => $row['id'], 'input' => $this->in->get('gr_field_' . $row['id']), 'required' => $row['required']);
         if ($row['type'] == 5) {
             $arrInput[$row['name']] = array('id' => $row['id'], 'input' => serialize($this->in->getArray('gr_field_' . $row['id'], 'int')), 'required' => $row['required']);
         }
     }
     $arrInput[$this->user->lang('email')] = array('input' => $this->in->get('gr_email'), 'required' => true);
     $arrInput[$this->user->lang('name')] = array('input' => $this->in->get('gr_name'), 'required' => true);
     $this->data = $arrInput;
     //Check Captcha
     require $this->root_path . 'libraries/recaptcha/recaptcha.class.php';
     $captcha = new recaptcha();
     $response = $captcha->recaptcha_check_answer($this->config->get('lib_recaptcha_pkey'), $this->env->ip, $this->in->get('recaptcha_challenge_field'), $this->in->get('recaptcha_response_field'));
     if (!$response->is_valid) {
         $this->core->message($this->user->lang('lib_captcha_wrong'), $this->user->lang('error'), 'red');
         $this->display;
         return;
     }
     //Check email
     if (!preg_match("/^([a-zA-Z0-9])+([\\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\\.[a-zA-Z0-9_-]+)+/", $this->in->get('gr_email'))) {
         $this->core->message($this->user->lang('fv_invalid_email'), $this->user->lang('error'), 'red');
         $this->display();
         return;
     }
     //Check Required
     $arrRequired = array();
     foreach ($arrInput as $key => $val) {
         if (!$val['required']) {
             continue;
         }
         if ($val['input'] == '' || $val['input'] == 'a:0:{}') {
             $arrRequired[] = $key;
         }
     }
     if (count($arrRequired) > 0) {
         $this->core->message(implode(', ', $arrRequired), $this->user->lang('missing_values'), 'red');
         $this->display();
         return;
     }
     //Insert into DB
     $strName = $arrInput[$this->user->lang('name')]['input'];
     $strEmail = $arrInput[$this->user->lang('email')]['input'];
     $strAuthKey = random_string(false, 40);
     $strActivationKey = random_string(false, 32);
     $arrInput[$this->user->lang('email')]['input'] = register('encrypt')->encrypt($arrInput[$this->user->lang('email')]['input']);
     $arrToSave = array();
     foreach ($arrInput as $val) {
         $arrToSave[$val['id']] = $val['input'];
     }
     $strContent = serialize($arrToSave);
     $blnResult = $this->pdh->put('guildrequest_requests', 'add', array($strName, $strEmail, $strAuthKey, $strActivationKey, $strContent));
     $this->pdh->process_hook_queue();
     if (!$blnResult) {
         $this->core->message($this->user->lang('error'), $this->user->lang('error'), 'red');
         $this->display();
         return;
     }
     //Send Email to User with activation Key
     /*
     	$server_url = $this->env->link.'plugins/guildrequest/activate.php';
     	$bodyvars = array(
     		'USERNAME'		=> $strName,
     		'U_ACTIVATE' 	=> $server_url . '?key=' . $strActivationKey,
     		'GUILDTAG'		=> $this->config->get('guildtag'),
     	);
     	
     	if(!$this->email->SendMailFromAdmin($strEmail, $this->user->lang('gr_activationmail_subject'), $this->root_path.'plugins/guildrequest/language/'.$this->user->data['user_lang'].'/email/request_activation.html', $bodyvars)){
     		$this->core->message($this->user->lang('email_subject_send_error'), $this->user->lang('error'), 'red');
     		$this->display();
     		return;
     	}*/
     //Send Email to User with auth key
     $server_url = $this->env->link . 'plugins/guildrequest/viewrequest.php';
     $bodyvars = array('USERNAME' => sanitize($strName), 'U_ACTIVATE' => $server_url . '?id=' . $blnResult . '&key=' . $strAuthKey, 'GUILDTAG' => $this->config->get('guildtag'));
     if (!$this->email->SendMailFromAdmin($strEmail, $this->user->lang('gr_viewlink_subject'), $this->root_path . 'plugins/guildrequest/language/' . $this->user->data['user_lang'] . '/email/request_viewlink.html', $bodyvars)) {
         $this->core->message($this->user->lang('email_subject_send_error'), $this->user->lang('error'), 'red');
         $this->display();
         return;
     } else {
         //Send Notification Mail to everyone who wants it
         $bodyvars = array('U_VIEW' => $server_url . '?id=' . $blnResult, 'REQUEST_USER' => sanitize($strName), 'GUILDTAG' => $this->config->get('guildtag'));
         $arrUserIDs = $this->pdh->get('user', 'id_list', array());
         foreach ($arrUserIDs as $userid) {
             $arrGuildrequestSettings = $this->pdh->get('user', 'plugin_settings', array($userid, 'guildrequest'));
             if (isset($arrGuildrequestSettings['gr_send_notification_mails']) && $arrGuildrequestSettings['gr_send_notification_mails']) {
                 $strEmail = $this->pdh->get('user', 'email', array($userid, true));
                 if ($strEmail != '') {
                     $bodyvars['USERNAME'] = $this->pdh->get('user', 'name', array($userid));
                     $this->email->SendMailFromAdmin($strEmail, $this->user->lang('gr_notification_subject'), $this->root_path . 'plugins/guildrequest/language/' . $this->user->data['user_lang'] . '/email/request_notification.html', $bodyvars);
                 }
             }
         }
         //Redirect to viewrequest page
         redirect('plugins/guildrequest/viewrequest.php?id=' . $blnResult . '&key=' . $strAuthKey . '&msg=success');
     }
 }