Beispiel #1
0
 private function signup_full()
 {
     $error = '';
     // Check email
     $_POST['email'] = trim($_POST['email']);
     $email_check = $this->check_email($_POST['email']);
     if ($email_check !== TRUE) {
         $error .= $email_check;
     }
     // Check username
     $username_check = $this->check_username($_POST['username']);
     if ($username_check !== TRUE) {
         $error .= $username_check;
     }
     // Check password
     $password_check = $this->check_password($_POST['password1'], $_POST['password2']);
     if ($password_check !== TRUE) {
         $error .= $password_check;
     }
     // Error processing
     if ($error == '') {
         // No error so proceed...
         // First check if user added
         $user = User::get_by_email($_POST['email']);
         // If not then add
         if ($user == NULL) {
             $user_id = User::add($_POST['email']);
             $user = User::get_by_id($user_id);
         }
         // Do signup
         User::signup($user->id, $_POST['username'], $_POST['password1'], $this->config->encryption_salt);
         if ($this->config->send_emails == TRUE) {
             // Send 'thank you for signing up' email
             $admin = User::get_by_id($this->config->admin_users[0]);
             $to = array('name' => $_POST['username'], 'email' => $_POST['email']);
             $subject = '[' . $this->config->name . '] Welcome to ' . $this->config->name . '!';
             $body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/signup.html"), array('username' => $_POST['username'], 'app' => $this));
             // Email user
             $this->email->send_email($to, $subject, $body);
         }
         // Log signup
         if (isset($this->plugins->log)) {
             $this->plugins->log->add($user->id, 'user', NULL, 'signup');
         }
         // Admin alert email
         if ($this->config->send_emails && $this->config->signup_email_notifications == TRUE) {
             $admin = User::get_by_id($this->config->admin_users[0]);
             $to = array('name' => $admin->username, 'email' => $admin->email);
             $subject = '[' . $this->config->name . '] New signup on ' . $this->config->name . '!';
             $link = substr($this->config->url, 0, -1) . $this->url_for('users', 'show', $user->id);
             $body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/admin_signup_notification.html"), array('link' => $link, 'app' => $this));
             // Email user
             $this->email->send_email($to, $subject, $body);
         }
         // Start session
         $_SESSION['user_id'] = $user->id;
         // Check invites are enabled and the code is valid
         if ($this->config->invites->enabled == TRUE && Invite::check_code_valid($_POST['code'], $_POST['email']) == TRUE) {
             // Get invites
             $invites = Invite::list_by_code($_POST['code']);
             if (is_array($invites)) {
                 foreach ($invites as $invite) {
                     // Update invites
                     $invite->update();
                     // Log invite update
                     if (isset($this->plugins->log)) {
                         $this->plugins->log->add($_SESSION['user_id'], 'invite', $invite->id, 'accept');
                     }
                     // Update points (but only if inviting user is not an admin)
                     if (isset($this->plugins->points) && in_array($invite->user_id, $this->config->admin_users) != TRUE) {
                         // Update points
                         $this->plugins->points->update($invite->user_id, $this->plugins->points['per_invite_accepted']);
                         // Log points update
                         if (isset($this->plugins->log)) {
                             $this->plugins->log->add($invite->user_id, 'points', NULL, $this->plugins->points['per_invite_accepted'], 'invite_accepted = ' . $invite->id);
                         }
                     }
                 }
                 // end foreach
             }
             // end if is_array
         }
         // Log login
         if (isset($this->plugins->log)) {
             $this->plugins->log->add($_SESSION['user_id'], 'user', NULL, 'login');
         }
         // If redirect_to is set then redirect
         if ($this->uri['params']['redirect_to']) {
             header('Location: ' . $this->uri['params']['redirect_to']);
             exit;
         }
         // Set welcome message
         Application::flash('success', 'Welcome to ' . $this->config->name . '!');
         // Go forth!
         header('Location: ' . $this->config->url);
         exit;
     } else {
         // There was an error
         // Propagate get vars to be picked up by the form
         $this->uri['params']['email'] = $_POST['email'];
         $this->uri['params']['username'] = $_POST['username'];
         if (isset($_POST['code'])) {
             $this->code = $_POST['code'];
         }
         // Show error message
         Application::flash('error', $error);
         // Show signup form
         $this->loadView('users/add', array('title' => 'Signup'));
     }
 }