Exemplo n.º 1
0
def create_card():

    '''Creates Card (Epic and Standard) from the card creation menu'''
    #TODO Make seperate functions for diffrent card types

    card_form = json.loads(request.form['payload'])
    card_form = sanitize.form_keys(card_form)

    card = Card.map_from_form(card_form)
    
    if card.type == CardType(0).name: #Standard
        
        #add the provided "steps" to the card to be netered into the database
        steps_form = card_form.get('steps')
        steps = create_objects_from_form_array(Step, steps_form)
        card.add_steps(steps)
        
        return_value = card_insert.new_card(card)

    elif card.type == CardType(1).name: #Epic
        #No special action needs to be taken, enter into database
        return_value = card_insert.new_epic(card)

    else:
        
        return_value = response.error("Card Type is Invalid")
    
    return return_value
Exemplo n.º 2
0
        def check_authorization(*args, **kwargs):

            # If the function is not a direct api_repsonse, it means it credentials have already been checked
            #So we return the function itself
            if(kwargs.get('api_response', True)):
                updated_token = None
                try:
                    updated_token = process_token(json.loads(request.form['token']))
                    project_access(kwargs.get('project_id'),updated_token) #project_id past in contructor
                    
                except InvalidCredential as invalid:
                    return response.error(invalid.args[0])

                except AccessDenied as denied:
                    error = response.error(denied.args[0])
                    mesg = response.add_token(updated_token, error)
                    return mesg


                return response.add_token(updated_token, function(*args, **kwargs))
            
            else:
                return function(*args, **kwargs)
Exemplo n.º 3
0
    def __call__(self, *args, **kwargs):


        db = self._connect()
        connection_cursor = db.cursor(MySQLdb.cursors.DictCursor)
        try:
            query_result = self.function(cursor = connection_cursor, *args, **kwargs)
            db.commit();

        except MySQLdb.Error as exception:
            db.rollback()

            message = exception.args[1]
            print(message)
            return response.error(message)
           
        finally: 
            db.close()

        return query_result
Exemplo n.º 4
0
def login():

    '''Called when a user is loging in (shocker)
    Checks the provided email and password with the values stored in the database'''

    credentials_form = json.loads(request.form['payload'])
    credentials_form = sanitize.form_keys(credentials_form)

    provided_credentials = Credentials.map_from_form(credentials_form)
    stored_credentials = user_select.login_credentials(provided_credentials)

    try:
        validate.login(stored_credentials, provided_credentials)
    
    except InvalidCredential as invalid:
        return response.error(invalid.args[0])

    token = Token()
    token.user_id = stored_credentials.id
    token.update()

    user_update.token(token)
    
    return response.add_token(token = token)
Exemplo n.º 5
0
def register_user():

    '''Called when adding a new user to the database. Makes sure that all information 
    provided is valid(see individual validations for details) and hashes the password for storage'''

    credentials_form = json.loads(request.form['payload'])
    credentials_form = sanitize.form_keys(credentials_form)

    credentials = Credentials.map_from_form(credentials_form)

    try:
        validate.email(credentials.email)
        validate.name(credentials.first_name)
        validate.name(credentials.last_name)
        validate.password(credentials.password)
    
    except InvalidCredential as invalid:
        return response.error(invalid.args[0])

    credentials.hash_password()

    user_insert.new_user(credentials)
    
    return login()