<commit_before>
import uuid
from datetime import datetime
import bleach
from bl.string import String
import bweb.models.user

class User(bweb.models.user.User):
    
    def before_insert(self):
        """create the id for the user from their email address when their account is created.
        This id stays constant in the system, even if their email changes.
        """
        assert self.email is not None
        self.id = str(uuid.uuid5(uuid.NAMESPACE_URL, self.email)).replace('-', '')
        if self.name is None or self.name.strip()=='':
            self.name = self.email.split('@')[0].strip()
        self.name = bleach.clean(self.name)
        self.bio = bleach.clean(self.bio, tags=bleach.ALLOWED_TAGS+['p','br'])
        self.registered = datetime.now()
        self.verified = self.registered

    def items(self, update=True, orderby='created desc', **kwargs):
        from .item import Item
        return self.to_many(Item, update=update, orderby=orderby, **kwargs)

    def recent_activity(self, orderby='created desc'):
        from .item import Item
        return self.db.select("""
            select i.* from items i
            where i.title != '' 
            and (i.user_email = %s
                or user_email in (
                    select rel.other_email from users_relationships rel
                    where rel.user_email=%s
                    and rel.kind='following'))
            order by created desc;
            """, vals=[self.email, self.email], Record=Item)

    @property
    def id_slash_name(self):
        return "%s/%s" % (self.id, String(self.name).hyphenify())

    @property
    def following(self):
        return self.db.select("""
            select other.*, rel.created as rel_created 
            from users other
            inner join users_relationships rel
                on rel.other_email = other.email
            inner join users
                on rel.user_email = users.email
            where users.email=%s
            and kind='following'
            order by created desc
            """, vals=[self.email], Record=User)

    def follow(self, other_email, cursor=None):
        from .user_relationship import UserRelationship
        rel = UserRelationship(self.db, user_email=self.email, other_email=other_email, kind='following')
        rel.insert(cursor=cursor)

    def unfollow(self, other_email, cursor=None):
        from .user_relationship import UserRelationship
        rel = UserRelationship(self.db).select_one(user_email=self.email, other_email=other_email, kind='following')
        rel.delete(cursor=cursor)

    @property
    def blocking(self):
        return self.db.select("""
            select other.*, rel.created as rel_created
            from users other
            inner join users_relationships rel
                on rel.other_email = other.email
            inner join users
                on rel.user_email = users.email
            where users.email=%s
            and kind='blocking'
            order by created
            """, vals=[self.email], Record=User)

    def block(self, other_email, cursor=None):
        from .user_relationship import UserRelationship
        rel = UserRelationship(self.db, user_email=self.email, other_email=other_email, kind='blocking')
        rel.insert(cursor=cursor)

    def unblock(self, other_email, cursor=None):
        from .user_relationship import UserRelationship
        rel = UserRelationship(self.db).select_one(user_email=self.email, other_email=other_email, kind='blocking')
        rel.delete(cursor=cursor)
<commit_msg>User.authenticate() doesn't require user verification.<commit_after>
import uuid
from datetime import datetime
import bleach
from bl.string import String
import bweb.models.user

class User(bweb.models.user.User):

    def authenticate(self, email, password):
        return bweb.models.user.User.authenticate(self, email, password, unverified=True, upgrade=True)
    
    def before_insert(self):
        """create the id for the user from their email address when their account is created.
        This id stays constant in the system, even if their email changes.
        """
        assert self.email is not None
        self.id = str(uuid.uuid5(uuid.NAMESPACE_URL, self.email)).replace('-', '')
        if self.name is None or self.name.strip()=='':
            self.name = self.email.split('@')[0].strip()
        self.name = bleach.clean(self.name)
        self.bio = bleach.clean(self.bio, tags=bleach.ALLOWED_TAGS+['p','br'])
        self.registered = datetime.now()
        self.verified = self.registered

    def items(self, update=True, orderby='created desc', **kwargs):
        from .item import Item
        return self.to_many(Item, update=update, orderby=orderby, **kwargs)

    def recent_activity(self, orderby='created desc'):
        from .item import Item
        return self.db.select("""
            select i.* from items i
            where i.title != '' 
            and (i.user_email = %s
                or user_email in (
                    select rel.other_email from users_relationships rel
                    where rel.user_email=%s
                    and rel.kind='following'))
            order by created desc;
            """, vals=[self.email, self.email], Record=Item)

    @property
    def id_slash_name(self):
        return "%s/%s" % (self.id, String(self.name).hyphenify())

    @property
    def following(self):
        return self.db.select("""
            select other.*, rel.created as rel_created 
            from users other
            inner join users_relationships rel
                on rel.other_email = other.email
            inner join users
                on rel.user_email = users.email
            where users.email=%s
            and kind='following'
            order by created desc
            """, vals=[self.email], Record=User)

    def follow(self, other_email, cursor=None):
        from .user_relationship import UserRelationship
        rel = UserRelationship(self.db, user_email=self.email, other_email=other_email, kind='following')
        rel.insert(cursor=cursor)

    def unfollow(self, other_email, cursor=None):
        from .user_relationship import UserRelationship
        rel = UserRelationship(self.db).select_one(user_email=self.email, other_email=other_email, kind='following')
        rel.delete(cursor=cursor)

    @property
    def blocking(self):
        return self.db.select("""
            select other.*, rel.created as rel_created
            from users other
            inner join users_relationships rel
                on rel.other_email = other.email
            inner join users
                on rel.user_email = users.email
            where users.email=%s
            and kind='blocking'
            order by created
            """, vals=[self.email], Record=User)

    def block(self, other_email, cursor=None):
        from .user_relationship import UserRelationship
        rel = UserRelationship(self.db, user_email=self.email, other_email=other_email, kind='blocking')
        rel.insert(cursor=cursor)

    def unblock(self, other_email, cursor=None):
        from .user_relationship import UserRelationship
        rel = UserRelationship(self.db).select_one(user_email=self.email, other_email=other_email, kind='blocking')
        rel.delete(cursor=cursor)

{'fraction_non_alphanumeric': 0.10240391144913757, 'fraction_numerical': 0.0005432568246638599, 'mean_word_length': 2.3748854262144823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4711034', 'n_tokens_mistral': 2060, 'n_tokens_neox': 1980, 'n_words': 528}