Пример #1
0
 public static function add_user($opt = array())
 {
     global $db, $LANG;
     if (!ab_to(array('users' => 'add'))) {
         return false;
     }
     $opt = \site\utils::array_map_recursive('trim', $opt);
     if (empty($opt['name']) || empty($opt['email']) || empty($opt['password'])) {
         return false;
     }
     $stmt = $db->stmt_init();
     $stmt->prepare("INSERT INTO " . DB_TABLE_PREFIX . "users (name, email, password, avatar, points, credits, privileges, erole, subscriber, valid, date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())");
     $avatar = \site\images::upload(@$_FILES['logo'], 'avatar_', array('path' => DIR . '/', 'max_size' => 1024, 'max_width' => 500, 'max_height' => 600, 'current' => ''));
     $password = md5($opt['password']);
     $stmt->bind_param("ssssiiisii", $opt['name'], $opt['email'], $password, $avatar, $opt['points'], $opt['credits'], $opt['privileges'], @serialize($opt['erole']), $opt['subscriber'], $opt['confirm']);
     if ($stmt->execute()) {
         if (!$opt['confirm']) {
             $stmt->prepare("SELECT id FROM " . DB_TABLE_PREFIX . "users WHERE email = ?");
             $stmt->bind_param("s", $opt['email']);
             $stmt->execute();
             $stmt->bind_result($id);
             $stmt->fetch();
             $stmt->close();
             $cofirm_session = md5(\site\utils::str_random(15));
             if (\user\mail_sessions::insert('confirmation', array('user' => $id, 'session' => $cofirm_session))) {
                 \site\mail::send($opt['email'], $LANG['email_acc_title'] . ' - ' . \query\main::get_option('sitename'), array('template' => 'account_confirmation', 'path' => '../'), array('hello_name' => sprintf($LANG['email_text_hello'], $opt['name']), 'confirmation_main_text' => $LANG['email_acc_maintext'], 'confirmation_button' => $LANG['email_acc_button'], 'link' => \site\utils::update_uri($GLOBALS['siteURL'] . 'verify.php', array('user' => $id, 'token' => $cofirm_session))));
             }
         }
         return true;
     }
     $stmt->close();
     return false;
 }
Пример #2
0
 public static function unsubscribe($post)
 {
     global $db, $LANG;
     $post = array_map('trim', $post);
     if (!isset($post['email']) || !filter_var($post['email'], FILTER_VALIDATE_EMAIL)) {
         throw new \Exception($LANG['newsletter_usevalide']);
     } else {
         $stmt = $db->stmt_init();
         $stmt->prepare("SELECT COUNT(*) FROM " . DB_TABLE_PREFIX . "newsletter WHERE email = ?");
         $stmt->bind_param("s", $post['email']);
         $stmt->bind_result($count);
         $stmt->execute();
         $stmt->fetch();
         $stmt->close();
         if ($count == 0) {
             throw new \Exception($LANG['uunsubscr_notsubscr']);
         }
         if (\query\main::get_option('unsubscr_confirm_req')) {
             $session = md5(\site\utils::str_random(15));
             if (\user\mail_sessions::insert('unsubscription', array('email' => $post['email'], 'session' => $session)) && \site\mail::send($post['email'], $LANG['email_unsub_title'] . ' - ' . \query\main::get_option('sitename'), array('template' => 'confirm_unsubscription'), array('confirmation_main_text' => $LANG['email_unsub_maintext'], 'confirmation_button' => $LANG['email_unsub_button'], 'link' => \site\utils::update_uri($GLOBALS['siteURL'] . 'verify.php', array('action' => 'unsubscribe2', 'email' => $post['email'], 'token' => $session))))) {
                 return 1;
             } else {
                 throw new \Exception($LANG['msg_error']);
             }
         } else {
             // auto-unsubscribe
             $stmt = $db->stmt_init();
             $stmt->prepare("DELETE FROM " . DB_TABLE_PREFIX . "newsletter WHERE email = ?");
             $stmt->bind_param("s", $post['email']);
             $execute = $stmt->execute();
             $stmt->close();
             if ($execute) {
                 return 2;
             } else {
                 throw new \Exception($LANG['msg_error']);
             }
         }
     }
 }