Esempio n. 1
0
 /**
  * Register user procedure
  * Send email with confirmation link
  *
  * @param	array	$data
  * @return	boolean	true on success or false on fail
  */
 public function register($data, $captcha = '')
 {
     if (!$this->check_token()) {
         return false;
     }
     /**
      * @see  'lib/vivvo/core/Users.class.php'
      */
     require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Users.class.php';
     if (!vivvo_hooks_manager::call('login_register', array(&$data))) {
         return vivvo_hooks_manager::get_status();
     }
     $sm = vivvo_lite_site::get_instance();
     $lang = vivvo_lang::get_instance();
     if (!$sm->user) {
         if (!preg_match("/^[-_a-z0-9]+(\\.[-_a-z0-9]+)*@[-a-z0-9]+(\\.[-a-z0-9]+)*\\.[a-z]{2,6}\$/", $data['email_address'])) {
             $this->set_error_code(2702);
             return false;
         }
         $user_list = new Users_list();
         if ($user_list->get_email_exists($data['email_address'])) {
             $this->set_error_code(2703);
             return false;
         }
         if (preg_match("/[^a-zA-Z0-9\\_\\-]/", $data['username'])) {
             $this->set_error_code(2704);
             return false;
         }
         if ($user_list->get_user_exists($data['username'])) {
             $this->set_error_code(2705);
             return false;
         }
         if (strlen($data['password']) < 6) {
             $this->set_error_code(2706);
             return false;
         }
         if ($data['password'] != $data['retype_password']) {
             $this->set_error_code(2707);
             return false;
         }
         if (VIVVO_REGISTRATION_CAPTCHA == 1 && (empty($_SESSION['vivvo']['login_captcha']) || $_SESSION['vivvo']['login_captcha'] != $captcha)) {
             $this->set_error_code(2714);
             return false;
         }
         $data['password'] = md5($data['password']);
         $data['created'] = date('Y-m-d H:i:s');
         $data['activated'] = '0';
         array_walk($data, 'array_htmlspecialchars');
         $user = new Users();
         if ($user->populate($data, true) === false) {
             $this->set_error_info($user->get_error_info());
             return false;
         }
         $this->_post_master->set_data_object($user);
         if ($this->_post_master->sql_insert()) {
             $id = $this->_post_master->get_work_id();
             $user->set_userid($id);
             $user_manager = $sm->get_user_manager();
             $user_manager->set_user_groups($id, VIVVO_GROUP_DEFAULT_MEMBER);
             $crypt = md5($data['email_address'] . $data['username'] . $data['created']);
             $confirm_url = make_absolute_url('login.html?action=login&cmd=confirm&ack=' . $crypt);
             $recipients = $data['email_address'];
             $search = array('(', ')', '<', '>', '@', ';', ':', '\\', '"', '.', '[', ']');
             $replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
             $vivvo_website_title = str_replace($search, $replace, VIVVO_WEBSITE_TITLE);
             $vivvo_website_title = "=?UTF-8?B?" . base64_encode($vivvo_website_title) . "?=";
             $headers['From'] = $vivvo_website_title . '<' . VIVVO_EMAIL_SEND_FROM . '>';
             $recipients = array();
             $recipients[] = $data['email_address'];
             $headers['Subject'] = "=?UTF-8?B?" . base64_encode(VIVVO_EMAIL_REGISTER_SUBJECT) . "?=";
             $headers['Content-Type'] = "text/plain; charset=UTF-8;";
             if ($data['first_name'] != '' or $data['last_name'] != '') {
                 $fullname = $data['first_name'] . ' ' . $data['last_name'];
             } else {
                 $fullname = $data['email_address'];
             }
             $br = "\n";
             $sm->set_template();
             $body_template = new template();
             $template_sting = xml_template_node::xmlentities_decode(VIVVO_EMAIL_REGISTER_TEMPLATE);
             $body_template->set_string_template($template_sting);
             $body_template->assign('new_user', $fullname);
             $body_template->assign('activation_url', $confirm_url);
             $body = $body_template->get_output() . "\n\n";
             if (VIVVO_EMAIL_SMTP_PHP == 1) {
                 $mail_object = new Mail();
                 $mail_object->send($recipients, $headers, $body);
             } else {
                 $mail_options['driver'] = 'smtp';
                 $mail_options['host'] = VIVVO_EMAIL_SMTP_HOST;
                 $mail_options['port'] = VIVVO_EMAIL_SMTP_PORT;
                 $mail_options['localhost'] = 'localhost';
                 if (VIVVO_EMAIL_SMTP_PASSWORD != '' && VIVVO_EMAIL_SMTP_USERNAME != '') {
                     $mail_options['auth'] = true;
                     $mail_options['username'] = VIVVO_EMAIL_SMTP_USERNAME;
                     $mail_options['password'] = VIVVO_EMAIL_SMTP_PASSWORD;
                 } else {
                     $mail_options['auth'] = false;
                     $mail_options['username'] = '';
                     $mail_options['password'] = '';
                 }
                 $mail_object = Mail::factory('smtp', $mail_options);
                 $mail_object->send($recipients, $headers, $body);
             }
             return true;
         } else {
             $this->set_error_code(2708);
             return false;
         }
         return true;
     } else {
         $this->set_error_code(2709);
         return false;
     }
 }
Esempio n. 2
0
 function check_email($email)
 {
     if (!vivvo_hooks_manager::call('user_checkEmail', array(&$email))) {
         return vivvo_hooks_manager::get_status();
     }
     $user_list = new Users_list();
     echo json_encode(!!$user_list->get_email_exists($email));
     exit;
 }