<commit_before>from sqlalchemy.orm import exc

import os, base64, datetime

import cbpos
logger = cbpos.get_logger(__name__)

from cbpos.mod.auth.models import User, Clock

class UserState(object):
    __logged_in_user = None
    
    @property
    def current(self):
        return self.__logged_in_user
    
    @current.setter
    def current(self, value):
        self.__logged_in_user = value
    
    @current.deleter
    def current(self):
        self.__logged_in_user = None
    
    def check(self, username, password):
        session = cbpos.database.session()
        try:
            u = session.query(User).filter(User.username == username).one()
        except exc.NoResultFound, exc.MultipleResultsFound:
            return None
        else:
            return u if u.login(password) else None
    
    def login(self, username, password):
        session = cbpos.database.session()
        u = self.check(username, password)
        if u is None:
            del self.current
        else:
            self.current = u
        
        if self.current is not None and not self.current.super:
            # Filter menu items to display according to permissions
            restrictions = [(mr.root, mr.item) for mr in self.current.menu_restrictions] 
            for root in cbpos.menu.items:
                for item in root.children:
                    item.enabled = ((root.name, item.name) in restrictions)
        
        return self.current
    
    def is_logged_in(self):
        return self.current is not None
    
    def clockin(self, u=None):
        from cbpos.mod.auth.controllers import user

        session = cbpos.database.session()

        date_time = datetime.datetime.now()
        if u is None:
            u = self.current
        
        #create the new row.
        clockcard = Clock(user=u, date_time_in=date_time, date_time_out=date_time)
        session.add(clockcard)<commit_msg>Fix tabs keeping disabled when logging out then as super user<commit_after>from sqlalchemy.orm import exc

import os, base64, datetime

import cbpos
logger = cbpos.get_logger(__name__)

from cbpos.mod.auth.models import User, Clock

class UserState(object):
    __logged_in_user = None
    
    @property
    def current(self):
        return self.__logged_in_user
    
    @current.setter
    def current(self, value):
        self.__logged_in_user = value
    
    @current.deleter
    def current(self):
        self.__logged_in_user = None
    
    def check(self, username, password):
        session = cbpos.database.session()
        try:
            u = session.query(User).filter(User.username == username).one()
        except exc.NoResultFound, exc.MultipleResultsFound:
            return None
        else:
            return u if u.login(password) else None
    
    def login(self, username, password):
        session = cbpos.database.session()
        u = self.check(username, password)
        if u is None:
            del self.current
        else:
            self.current = u
        
        if self.current is None:
            pass
        elif self.current.super:
            # Filter menu items to display all items 
            for root in cbpos.menu.items:
                for item in root.children:
                    item.enabled = True
        else:
            # Filter menu items to display according to permissions
            restrictions = [(mr.root, mr.item) for mr in self.current.menu_restrictions] 
            for root in cbpos.menu.items:
                for item in root.children:
                    item.enabled = ((root.name, item.name) in restrictions)
        
        return self.current
    
    def is_logged_in(self):
        return self.current is not None
    
    def clockin(self, u=None):
        from cbpos.mod.auth.controllers import user

        session = cbpos.database.session()

        date_time = datetime.datetime.now()
        if u is None:
            u = self.current
        
        #create the new row.
        clockcard = Clock(user=u, date_time_in=date_time, date_time_out=date_time)
        session.add(clockcard)
{'fraction_non_alphanumeric': 0.07908782144590004, 'fraction_numerical': 0.0009704027171276079, 'mean_word_length': 1.9471050750536096, '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': '6066181', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1151, 'n_words': 322}