def create_project(api_response = True): project_form = sanitize.form_keys(json.loads(request.form['payload'])) project = Project.map_from_form(project_form) token_form = sanitize.form_keys(json.loads(request.form['token'])) token = Token.map_from_form(token_form) project = project_insert.create_project(project, token.user_id) parent_url = "api/DAL/images/projects/" project.image.save_to_file_system(parent_url) return response.success(project.id)
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
def update_card_details(card_id): card_form = json.loads(request.form['payload']) card_form = sanitize.form_keys(card_form) print(card_form) card = Card.map_from_form(card_form) card_update.details(card) return get_card_details(card.id, api_response = False)
def update_card_description(card_id): '''Updates the provided card's description, then returns the value from the database''' card_form = json.loads(request.form['payload']) card_form = sanitize.form_keys(card_form) card = Card.map_from_form(card_form) card_update.description(card) return get_card_description(card.id, api_response = False)
def process_token(token_form): token_form = json.loads(request.form['token']) token_form = sanitize.form_keys(token_form) provided_token = Token.map_from_form(token_form) stored_token = user_select.token(provided_token) validate.token(stored_token, provided_token) provided_token.update() user_update.token(provided_token) return provided_token
def create_objects_from_form_array(Class, form): '''Takes a form and converts it into objects of the provided class''' array = [] try: for item in form: item = sanitize.form_keys(item) array.append(Class.map_from_form(item)) except TypeError: pass return array
def get_projects_for_user(): token_form = json.loads(request.form['token']) token_form = sanitize.form_keys(token_form) token = Token.map_from_form(token_form) projects = project_select.projects_for_user(token.user_id) serialized_projects = [] for project in projects: serialized_projects.append(project.serialize()) return response.success(serialized_projects)
def get_card_with_user_task(project_id, api_response = True): '''Using the user id on the authentication token, send back all cards that have steps or are in anyway assigned to the user''' token_form = json.loads(request.form['token']) token_form = sanitize.form_keys(token_form) token = Token.map_from_form(token_form) cards = card_select.card_with_user_task(token.user_id, project_id) serialized_cards = serialize_array(cards) if api_response: return response.success(serialized_cards) else: return serialized_cards
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)
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()