def force_resetbirthday_(request): if define.common_status_check(request.userid) != "resetbirthday": return define.errorpage(request.userid, errorcode.permission) form = request.web_input(birthday="") birthday = define.convert_inputdate(form.birthday) profile.force_resetbirthday(request.userid, birthday) raise HTTPSeeOther(location="/", headers=request.response.headers)
def POST(self): if define.common_status_check(self.user_id) != "resetbirthday": return define.errorpage(self.user_id, errorcode.permission) form = web.input(birthday="") birthday = define.convert_inputdate(form.birthday) profile.force_resetbirthday(self.user_id, birthday) raise web.seeother("/index")
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 format for convert_inputdate. 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: if not d.get_sysname(username): raise WeasylError("usernameInvalid") elif d.execute( "SELECT EXISTS (SELECT 0 FROM login WHERE login_name = '%s')", [d.get_sysname(username)], ["bool"]): raise WeasylError("usernameExists") elif d.execute( "SELECT EXISTS (SELECT 0 FROM useralias WHERE alias_name = '%s')", [d.get_sysname(username)], ["bool"]): raise WeasylError("usernameExists") elif d.execute( "SELECT EXISTS (SELECT 0 FROM logincreate WHERE login_name = '%s')", [d.get_sysname(username)], ["bool"]): raise WeasylError("usernameExists") d.execute("UPDATE login SET login_name = '%s' WHERE userid = %i", [d.get_sysname(username), userid]) d._get_display_name.invalidate(userid) d.execute("UPDATE profile SET username = '******' WHERE userid = %i", [username, userid]) updates.append('- Username: %s' % (username, )) # Full name if full_name is not None: d.execute("UPDATE profile SET full_name = '%s' WHERE userid = %i", [full_name, userid]) updates.append('- Full name: %s' % (full_name, )) # Catchphrase if catchphrase is not None: d.execute("UPDATE profile SET catchphrase = '%s' WHERE userid = %i", [catchphrase, userid]) updates.append('- Catchphrase: %s' % (catchphrase, )) # Birthday if birthday is not None and d.convert_inputdate(birthday): unixtime = d.convert_inputdate(birthday) 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.execute( """ UPDATE profile SET config = REGEXP_REPLACE(config, '[ap]', '', 'g') || '%s' WHERE userid = %i """, [rating_flag, userid]) d._get_config.invalidate(userid) updates.append('- Birthday: %s' % (birthday, )) # Gender if gender is not None: d.execute("UPDATE userinfo SET gender = '%s' WHERE userid = %i", [gender, userid]) updates.append('- Gender: %s' % (gender, )) # Location if country is not None: d.execute("UPDATE userinfo SET country = '%s' WHERE userid = %i", [country, 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_config.invalidate(userid) if updates: from weasyl import moderation moderation.note_about(my_userid, userid, 'The following fields were changed:', '\n'.join(updates))
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 format for convert_inputdate. 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: if not d.get_sysname(username): raise WeasylError("usernameInvalid") elif d.execute("SELECT EXISTS (SELECT 0 FROM login WHERE login_name = '%s')", [d.get_sysname(username)], ["bool"]): raise WeasylError("usernameExists") elif d.execute("SELECT EXISTS (SELECT 0 FROM useralias WHERE alias_name = '%s')", [d.get_sysname(username)], ["bool"]): raise WeasylError("usernameExists") elif d.execute("SELECT EXISTS (SELECT 0 FROM logincreate WHERE login_name = '%s')", [d.get_sysname(username)], ["bool"]): raise WeasylError("usernameExists") d.execute("UPDATE login SET login_name = '%s' WHERE userid = %i", [d.get_sysname(username), userid]) d._get_display_name.invalidate(userid) d.execute("UPDATE profile SET username = '******' WHERE userid = %i", [username, userid]) updates.append('- Username: %s' % (username,)) # Full name if full_name is not None: d.execute("UPDATE profile SET full_name = '%s' WHERE userid = %i", [full_name, userid]) updates.append('- Full name: %s' % (full_name,)) # Catchphrase if catchphrase is not None: d.execute("UPDATE profile SET catchphrase = '%s' WHERE userid = %i", [catchphrase, userid]) updates.append('- Catchphrase: %s' % (catchphrase,)) # Birthday if birthday is not None and d.convert_inputdate(birthday): unixtime = d.convert_inputdate(birthday) age = d.convert_age(unixtime) d.execute("UPDATE userinfo SET birthday = %i WHERE userid = %i", [unixtime, userid]) if age < ratings.MODERATE.minimum_age: max_rating = ratings.GENERAL.code rating_flag = "" elif age < ratings.EXPLICIT.minimum_age: max_rating = ratings.MODERATE.code rating_flag = "m" else: max_rating = ratings.EXPLICIT.code if d.get_rating(userid) > max_rating: d.execute( """ UPDATE profile SET config = REGEXP_REPLACE(config, '[map]', '', 'g') || '%s' WHERE userid = %i """, [rating_flag, userid] ) d._get_config.invalidate(userid) updates.append('- Birthday: %s' % (birthday,)) # Gender if gender is not None: d.execute("UPDATE userinfo SET gender = '%s' WHERE userid = %i", [gender, userid]) updates.append('- Gender: %s' % (gender,)) # Location if country is not None: d.execute("UPDATE userinfo SET country = '%s' WHERE userid = %i", [country, 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_config.invalidate(userid) if updates: from weasyl import moderation moderation.note_about(my_userid, userid, 'The following fields were changed:', '\n'.join(updates))