Exemplo n.º 1
0
function Activate()
{
    global $context, $txt, $modSettings, $scripturl, $sourcedir, $language;
    loadLanguage('Login');
    //loadTemplate('Login');
    if (empty($_REQUEST['u']) && empty($_POST['user'])) {
        if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) {
            fatal_lang_error('no_access', false);
        }
        $context['member_id'] = 0;
        EoS_Smarty::loadTemplate('generic_skeleton');
        EoS_Smarty::getConfigInstance()->registerHookTemplate('generic_content_area', 'loginout/resend');
        $context['page_title'] = $txt['invalid_activation_resend'];
        $context['can_activate'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] == 1;
        $context['default_username'] = isset($_GET['user']) ? $_GET['user'] : '';
        return;
    }
    // Get the code from the database...
    $request = smf_db_query('
		SELECT id_member, validation_code, member_name, real_name, email_address, is_activated, passwd, lngfile
		FROM {db_prefix}members' . (empty($_REQUEST['u']) ? '
		WHERE member_name = {string:email_address} OR email_address = {string:email_address}' : '
		WHERE id_member = {int:id_member}') . '
		LIMIT 1', array('id_member' => isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0, 'email_address' => isset($_POST['user']) ? $_POST['user'] : ''));
    // Does this user exist at all?
    if (mysql_num_rows($request) == 0) {
        EoS_Smarty::loadTemplate('generic_skeleton');
        EoS_Smarty::getConfigInstance()->registerHookTemplate('generic_content_area', 'loginout/retry_activate');
        $context['page_title'] = $txt['invalid_userid'];
        $context['member_id'] = 0;
        return;
    }
    $row = mysql_fetch_assoc($request);
    mysql_free_result($request);
    // Change their email address? (they probably tried a fake one first :P.)
    if (isset($_POST['new_email'], $_REQUEST['passwd']) && sha1(strtolower($row['member_name']) . $_REQUEST['passwd']) == $row['passwd']) {
        if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) {
            fatal_lang_error('no_access', false);
        }
        // !!! Separate the sprintf?
        if (preg_match('~^[0-9A-Za-z=_+\\-/][0-9A-Za-z=_\'+\\-/\\.]*@[\\w\\-]+(\\.[\\w\\-]+)*(\\.[\\w]{2,6})$~', $_POST['new_email']) == 0) {
            fatal_error(sprintf($txt['valid_email_needed'], htmlspecialchars($_POST['new_email'])), false);
        }
        // Make sure their email isn't banned.
        isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']);
        // Ummm... don't even dare try to take someone else's email!!
        $request = smf_db_query('
			SELECT id_member
			FROM {db_prefix}members
			WHERE email_address = {string:email_address}
			LIMIT 1', array('email_address' => $_POST['new_email']));
        // !!! Separate the sprintf?
        if (mysql_num_rows($request) != 0) {
            fatal_lang_error('email_in_use', false, array(htmlspecialchars($_POST['new_email'])));
        }
        mysql_free_result($request);
        updateMemberData($row['id_member'], array('email_address' => $_POST['new_email']));
        $row['email_address'] = $_POST['new_email'];
        $email_change = true;
    }
    // Resend the password, but only if the account wasn't activated yet.
    if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'resend' && ($row['is_activated'] == 0 || $row['is_activated'] == 2) && (!isset($_REQUEST['code']) || $_REQUEST['code'] == '')) {
        require_once $sourcedir . '/lib/Subs-Post.php';
        $replacements = array('REALNAME' => $row['real_name'], 'USERNAME' => $row['member_name'], 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $row['id_member'] . ';code=' . $row['validation_code'], 'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $row['id_member'], 'ACTIVATIONCODE' => $row['validation_code'], 'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder');
        $emaildata = loadEmailTemplate('resend_activate_message', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
        sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
        $context['page_title'] = $txt['invalid_activation_resend'];
        // This will ensure we don't actually get an error message if it works!
        $context['error_title'] = '';
        fatal_lang_error(!empty($email_change) ? 'change_email_success' : 'resend_email_success', false);
    }
    // Quit if this code is not right.
    if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code']) {
        if (!empty($row['is_activated'])) {
            fatal_lang_error('already_activated', false);
        } elseif ($row['validation_code'] == '') {
            loadLanguage('Profile');
            fatal_error($txt['registration_not_approved'] . ' <a href="' . $scripturl . '?action=activate;user='******'member_name'] . '">' . $txt['here'] . '</a>.', false);
        }
        EoS_Smarty::loadTemplate('generic_skeleton');
        EoS_Smarty::getConfigInstance()->registerHookTemplate('generic_content_area', 'loginout/retry_activate');
        $context['page_title'] = $txt['invalid_activation_code'];
        $context['member_id'] = $row['id_member'];
        return;
    }
    // Let the integration know that they've been activated!
    HookAPI::callHook('integrate_activate', array($row['member_name']));
    // Validation complete - update the database!
    updateMemberData($row['id_member'], array('is_activated' => 1, 'validation_code' => ''));
    // Also do a proper member stat re-evaluation.
    updateStats('member', false);
    if (!isset($_POST['new_email'])) {
        $actid = 0;
        require_once $sourcedir . '/lib/Subs-Post.php';
        // add to the activity stream
        if ($modSettings['astream_active']) {
            require_once $sourcedir . '/lib/Subs-Activities.php';
            $actid = aStreamAdd($row['id_member'], ACT_NEWMEMBER, array('member_name' => $row['member_name']), 0, 0, 0, $row['id_member']);
        }
        adminNotify('activation', $row['id_member'], $row['member_name'], $actid, ACT_NEWMEMBER);
    }
    EoS_Smarty::loadTemplate('generic_skeleton');
    EoS_Smarty::getConfigInstance()->registerHookTemplate('generic_content_area', 'loginout/login');
    $context += array('page_title' => $txt['registration_successful'], 'sub_template' => 'login', 'default_username' => $row['member_name'], 'default_password' => '', 'never_expire' => false, 'description' => $txt['activate_success']);
}
Exemplo n.º 2
0
/**
 * @param type $members			int: a single member id or an array of UNIQUE member ids
 * @param type $postOptions		array: must contain id_topic and id_message of the message
 *								that triggered the @mention.
 * 
 * creates an activity stream entry and sends out notifications to one or more 
 * members about a user tagging event in the message specified in $postOptions[].
 */
function notifyTaggedUsers(&$members, $postOptions)
{
    global $user_info, $modSettings, $sourcedir;
    $to_notify = !is_array($members) ? array($members) : $members;
    if ($modSettings['astream_active'] && count($to_notify) > 0 && isset($postOptions['id_topic']) && isset($postOptions['id_message']) && $postOptions['id_topic'] && $postOptions['id_message']) {
        require_once $sourcedir . '/lib/Subs-Activities.php';
        $id_act = aStreamAdd($user_info['id'], ACT_USERTAGGED, array('member_name' => $user_info['name']), 0, $postOptions['id_topic'], $postOptions['id_message'], $user_info['id'], ACT_PLEVEL_PRIVATE);
        if ((int) $id_act > 0) {
            aStreamAddNotification($to_notify, $id_act, ACT_USERTAGGED);
        }
    }
}
Exemplo n.º 3
0
    /**
     * @param $mid = int message (or content) id
     *
     * handle the ajax request for rating a post. Also handles deletion of 
     * 
     * TODO: remove likes from the database when a user is deleted
     * TODO: make it work without AJAX and JavaScript
     */
    public static function rateIt($mid)
    {
        global $context, $user_info, $sourcedir, $txt, $modSettings;
        $total = array();
        $content_type = 1;
        // > post content type, we should define them elsewhere later when we have more than just this one
        if ((int) $mid > 0) {
            $uid = $user_info['id'];
            $remove_it = isset($_REQUEST['remove']) ? true : false;
            $repair = isset($_REQUEST['repair']) && $user_info['is_admin'] ? true : false;
            $is_xmlreq = $_REQUEST['action'] == 'xmlhttp' ? true : false;
            $update_mode = false;
            $like_type = isset($_REQUEST['r']) && (int) $_REQUEST['r'] > 0 ? $_REQUEST['r'] : '1';
            $comment = isset($_REQUEST['comment']) ? strip_tags($_REQUEST['comment']) : '';
            $rtypes = explode(',', $like_type);
            foreach ($rtypes as $rtype) {
                if (!isset($modSettings['ratings'][$rtype])) {
                    AjaxErrorMsg($txt['unknown_rating_type']);
                }
            }
            if ($user_info['is_guest']) {
                AjaxErrorMsg($txt['no_like_for_guests']);
            }
            $request = smf_db_query('SELECT m.id_msg, m.id_member, m.id_board, m.id_topic, m.subject, l.id_msg AS like_message, l.rtype, l.id_user
					FROM {db_prefix}messages AS m 
					LEFT JOIN {db_prefix}likes AS l ON (l.id_msg = m.id_msg AND l.ctype = {int:content_type} AND l.id_user = {int:id_user})
					WHERE m.id_msg = {int:id_msg} LIMIT 1', array('content_type' => $content_type, 'id_msg' => $mid, 'id_user' => $uid));
            $row = mysql_fetch_assoc($request);
            mysql_free_result($request);
            $like_owner = $row['id_user'];
            if ($row['id_user'] > 0 && !$remove_it && !$repair) {
                // duplicate like (but not when removing it)
                AjaxErrorMsg($txt['like_verify_error']);
            }
            $like_receiver = $row['id_member'];
            EoS_Smarty::loadTemplate('xml_blocks');
            $context['template_functions'] = 'rating_response';
            $context['ratings_output']['mid'] = $mid;
            /*
             * this is a debugging feature and allows the admin to repair
             * the likes for a post.
             * it may go away at a later time.
             */
            if ($repair) {
                if (!$user_info['is_admin']) {
                    obExit(false);
                }
                $total = self::updateForContent($mid);
                $output = '';
                self::generateOutput($total['status'], $output, $mid, $row['id_user'] > 0 ? $row['rtype'] : 0);
                // fix like stats for the like_giver and like_receiver. This might be a very slow query, but
                // since this feature will most likely go away, right now I do not care.
                /*
                				smf_db_query('UPDATE {db_prefix}members AS m
                SET m.likes_given = (SELECT COUNT(l.id_user) FROM {db_prefix}likes AS l WHERE l.id_user = m.id_member),
                	m.likes_received = (SELECT COUNT(l1.id_receiver) FROM {db_prefix}likes AS l1 WHERE l1.id_receiver = m.id_member)
                WHERE m.id_member = {int:owner} OR m.id_member = {int:receiver}', array('owner' => $like_owner, 'receiver' => $like_receiver));
                */
                invalidateMemberData(array($like_owner, $like_receiver));
                if ($is_xmlreq) {
                    $context['ratings_output']['output'] = $output;
                    $context['ratings_output']['likebar'] = '';
                    $context['postratings'] = json_encode($context['ratings_output']);
                    return;
                } else {
                    redirectexit();
                }
            }
            if ($like_receiver == $uid) {
                AjaxErrorMsg($txt['cannot_like_own']);
            }
            if (!allowedTo('like_give', $row['id_board'])) {
                // no permission to give likes in this board
                AjaxErrorMsg($txt['like_no_permission']);
            }
            if ($remove_it && $row['id_user'] > 0) {
                // remove a rating
                if ($like_owner == $uid) {
                    smf_db_query('DELETE FROM {db_prefix}likes WHERE id_msg = {int:id_msg} AND id_user = {int:id_user} AND ctype = {int:ctype}', array('id_msg' => $mid, 'id_user' => $uid, 'ctype' => $content_type));
                    if ($like_receiver) {
                        smf_db_query('UPDATE {db_prefix}members SET likes_received = likes_received - 1 WHERE id_member = {int:id_member}', array('id_member' => $like_receiver));
                    }
                    smf_db_query('UPDATE {db_prefix}members SET likes_given = likes_given - 1 WHERE id_member = {int:id_member}', array('id_member' => $uid));
                    // if we remove a like (unlike) a post, also delete the corresponding activity
                    smf_db_query('DELETE a.*, n.* FROM {db_prefix}log_activities AS a LEFT JOIN {db_prefix}log_notifications AS n ON(n.id_act = a.id_act)
						WHERE a.id_member = {int:id_member} AND a.id_type = 1 AND a.id_content = {int:id_content}', array('id_member' => $uid, 'id_content' => $mid));
                    $context['ratings_output']['likebar'] = self::$rate_bar;
                }
            } else {
                /* store the rating */
                global $memberContext;
                if ($like_receiver) {
                    // we do have a member, but still allow to like posts made by guests
                    loadMemberData($like_receiver);
                    // but banned users shall not receive likes
                    loadMemberContext($like_receiver);
                }
                if ($like_receiver && !$memberContext[$like_receiver]['is_banned'] || $like_receiver == 0) {
                    // posts by guests can be liked
                    smf_db_query('INSERT INTO {db_prefix}likes(id_msg, id_user, id_receiver, updated, ctype, rtype, comment) 
							VALUES({int:id_message}, {int:id_user}, {int:id_receiver}, {int:updated}, {int:ctype}, {string:rtype}, {string:comment})', array('id_message' => $mid, 'id_user' => $uid, 'id_receiver' => $like_receiver, 'updated' => time(), 'ctype' => $content_type, 'rtype' => $like_type, 'comment' => $comment));
                    if ($like_receiver) {
                        smf_db_query('UPDATE {db_prefix}members SET likes_received = likes_received + 1 WHERE id_member = {int:id_member}', array('id_member' => $like_receiver));
                    }
                    smf_db_query('UPDATE {db_prefix}members SET likes_given = likes_given + 1 WHERE id_member = {int:uid}', array('uid' => $uid));
                    $update_mode = $like_type;
                    if ($modSettings['astream_active']) {
                        @(require_once $sourcedir . '/lib/Subs-Activities.php');
                        aStreamAdd($uid, ACT_LIKE, array('member_name' => $context['user']['name'], 'topic_title' => $row['subject'], 'rtype' => $like_type), $row['id_board'], $row['id_topic'], $mid, $like_receiver);
                    }
                } else {
                    AjaxErrorMsg($txt['like_cannot_like']);
                }
                $context['ratings_output']['likebar'] = '<a rel="nofollow" class="givelike" data-fn="remove" href="#" data-id="' . $mid . '">' . $txt['unlike_label'] . '</a>';
            }
            if ($user_info['is_admin'] && self::$show_repair_link) {
                $context['ratings_output']['likebar'] .= ' <a rel="nofollow" class="givelike" data-fn="repair" href="#" data-id="' . $mid . '">Repair ratings</a>';
            }
            $total = self::updateForContent($mid);
            $output = '';
            self::generateOutput($total['status'], $output, $mid, $update_mode);
            $context['ratings_output']['output'] = $output;
            $context['postratings'] = json_encode($context['ratings_output']);
        }
    }