# Path: screenchop/models.py
# class Invite_code(Document):
#     code = StringField(required=True)
#     date_used = StringField()
#     used_by = StringField()
#     valid = BooleanField(default=True)
#     created_by = StringField()
# 
#     meta = {
#         'indexes': ['code', 'used_by']
#         }


from screenchop.models import Invite_code
from time import strftime

class InviteCode(object):
    """ Class to check if a code is valid and/or to use the code """    

    def is_valid(self, code):
        try:
            # Query code to check if valid
            checkCode = Invite_code.objects.get(code=code)
            
            # If valid, return True, if not, False
            if checkCode.valid == False:
                return False
            
            return True
        
        # Exception = False. Usually because query is not found
        except:
            return False
    
    def use_code(self, code, user):
        """ Code to use the code, timestamp with user """

# Path: screenchop/models.py
# class Invite_code(Document):
#     code = StringField(required=True)
#     date_used = StringField()
#     used_by = StringField()
#     valid = BooleanField(default=True)
#     created_by = StringField()
# 
#     meta = {
#         'indexes': ['code', 'used_by']
#         }


# Path: screenchop/util/invite_codes.py
from screenchop.models import Invite_code
from time import strftime


class InviteCode(object):
    """ Class to check if a code is valid and/or to use the code """    

    def is_valid(self, code):
        try:
            # Query code to check if valid
            checkCode = Invite_code.objects.get(code=code)
            
            # If valid, return True, if not, False
            if checkCode.valid == False:
                return False
            
            return True
        
        # Exception = False. Usually because query is not found
        except:
            return False
    
    def use_code(self, code, user):
        """ Code to use the code, timestamp with user """

        code = Invite_code.objects.get(code=code)