Beispiel #1
0
def control_username_post_(request):
    if request.POST['do'] == 'change':
        login.change_username(
            acting_user=request.userid,
            target_user=request.userid,
            bypass_limit=False,
            new_username=request.POST['new_username'],
        )

        return Response(
            define.errorpage(
                request.userid,
                "Your username has been changed.",
                [["Go Back", "/control/username"], ["Return Home", "/"]],
            ))
    elif request.POST['do'] == 'release':
        login.release_username(
            define.engine,
            acting_user=request.userid,
            target_user=request.userid,
        )

        return Response(
            define.errorpage(
                request.userid,
                "Your old username has been released.",
                [["Go Back", "/control/username"], ["Return Home", "/"]],
            ))
    else:
        raise WeasylError("Unexpected")
Beispiel #2
0
def do_manage(my_userid,
              userid,
              username=None,
              full_name=None,
              catchphrase=None,
              birthday=None,
              gender=None,
              country=None,
              remove_social=None,
              permission_tag=None):
    """Updates a user's information from the admin user management page.
    After updating the user it records all the changes into the mod notes.

    If an argument is None it will not be updated.

    Args:
        my_userid (int): ID of user making changes to other user.
        userid (int): ID of user to modify.
        username (str): New username for user. Defaults to None.
        full_name (str): New full name for user. Defaults to None.
        catchphrase (str): New catchphrase for user. Defaults to None.
        birthday (str): New birthday for user, in HTML5 date format (ISO 8601 yyyy-mm-dd). Defaults to None.
        gender (str): New gender for user. Defaults to None.
        country (str): New country for user. Defaults to None.
        remove_social (list): Items to remove from the user's social/contact links. Defaults to None.
        permission_tag (bool): New tagging permission for user. Defaults to None.

    Returns:
        Does not return.
    """
    updates = []

    # Username
    if username is not None:
        login.change_username(
            acting_user=my_userid,
            target_user=userid,
            bypass_limit=True,
            new_username=username,
        )

        updates.append('- Username: %s' % (username, ))

    # Full name
    if full_name is not None:
        d.engine.execute(
            "UPDATE profile SET full_name = %(full_name)s WHERE userid = %(user)s",
            full_name=full_name,
            user=userid)
        updates.append('- Full name: %s' % (full_name, ))

    # Catchphrase
    if catchphrase is not None:
        d.engine.execute(
            "UPDATE profile SET catchphrase = %(catchphrase)s WHERE userid = %(user)s",
            catchphrase=catchphrase,
            user=userid)
        updates.append('- Catchphrase: %s' % (catchphrase, ))

    # Birthday
    if birthday is not None:
        # HTML5 date format is yyyy-mm-dd
        split = birthday.split("-")
        if len(split) != 3 or d.convert_unixdate(
                day=split[2], month=split[1], year=split[0]) is None:
            raise WeasylError("birthdayInvalid")
        unixtime = d.convert_unixdate(day=split[2],
                                      month=split[1],
                                      year=split[0])
        age = d.convert_age(unixtime)

        d.execute("UPDATE userinfo SET birthday = %i WHERE userid = %i",
                  [unixtime, userid])

        if age < ratings.EXPLICIT.minimum_age:
            max_rating = ratings.GENERAL.code
            rating_flag = ""
        else:
            max_rating = ratings.EXPLICIT.code

        if d.get_rating(userid) > max_rating:
            d.engine.execute(
                """
                UPDATE profile
                SET config = REGEXP_REPLACE(config, '[ap]', '', 'g') || %(rating_flag)s
                WHERE userid = %(user)s
                """,
                rating_flag=rating_flag,
                user=userid,
            )
            d._get_all_config.invalidate(userid)
        updates.append('- Birthday: %s' % (birthday, ))

    # Gender
    if gender is not None:
        d.engine.execute(
            "UPDATE userinfo SET gender = %(gender)s WHERE userid = %(user)s",
            gender=gender,
            user=userid)
        updates.append('- Gender: %s' % (gender, ))

    # Location
    if country is not None:
        d.engine.execute(
            "UPDATE userinfo SET country = %(country)s WHERE userid = %(user)s",
            country=country,
            user=userid)
        updates.append('- Country: %s' % (country, ))

    # Social and contact links
    if remove_social:
        for social_link in remove_social:
            d.engine.execute(
                "DELETE FROM user_links WHERE userid = %(userid)s AND link_type = %(link)s",
                userid=userid,
                link=social_link)
            updates.append('- Removed social link for %s' % (social_link, ))

    # Permissions
    if permission_tag is not None:
        if permission_tag:
            query = (
                "UPDATE profile SET config = replace(config, 'g', '') "
                "WHERE userid = %(user)s AND position('g' in config) != 0")
        else:
            query = ("UPDATE profile SET config = config || 'g' "
                     "WHERE userid = %(user)s AND position('g' in config) = 0")

        if d.engine.execute(query, user=userid).rowcount != 0:
            updates.append('- Permission to tag: ' +
                           ('yes' if permission_tag else 'no'))
            d._get_all_config.invalidate(userid)

    if updates:
        from weasyl import moderation
        moderation.note_about(my_userid, userid,
                              'The following fields were changed:',
                              '\n'.join(updates))