def create(): """ Create a post. """ random_token = None if app.config['USE_RANDOM_TOKEN']: # Check if client defined a random token, if not generate one if 'post[random_token]' in request.form: random_token = request.form['post[random_token]'] else: random_token = helpers.generate_token( app.config['RANDOM_TOKEN_LENGTH']) # Create burn after date based off client paramters or generate one today = datetime.today() if 'post[seconds_until_burn]' in request.form: burn_after = timedelta(seconds=int(request.form['post[seconds_until_burn]'])) + \ today else: burn_after = timedelta(seconds=app.config['POST_LIFETIME_MAX']) + \ today # Set the privly application, use "PlainPost" as default privly_application = "PlainPost" if 'post[privly_application]' in request.form: privly_application = request.form['post[privly_application]'] # Set the content of the post content, structured = (None, None) if 'post[content]' in request.form: content = request.form['post[content]'] if 'post[structured_content]' in request.form: structured = request.form['post[structured_content]'] # Create the Post post = Post( random_id=helpers.generate_token(app.config['RANDOM_ID_LENGTH']), random_token=random_token, content=content, structured_content=structured, burn_after=burn_after, privly_application=privly_application, public=True, user=user ) post.save() # Create JSON response response = helpers.jsonify(status='created', location=post, _status=201) response.headers['X-Privly-Url'] = helpers.privly_URL(post) return response
def create(): """ Create a post. """ random_token = None if app.config['USE_RANDOM_TOKEN']: # Check if client defined a random token, if not generate one if 'post[random_token]' in request.form: random_token = request.form['post[random_token]'] else: random_token = helpers.generate_token( app.config['RANDOM_TOKEN_LENGTH']) # Create burn after date based off client paramters or generate one today = datetime.today() if 'post[seconds_until_burn]' in request.form: burn_after = timedelta(seconds=int(request.form['post[seconds_until_burn]'])) + \ today else: burn_after = timedelta(seconds=app.config['POST_LIFETIME_MAX']) + \ today # Set the privly application, use "PlainPost" as default privly_application = "PlainPost" if 'post[privly_application]' in request.form: privly_application = request.form['post[privly_application]'] # Set the content of the post content, structured = (None, None) if 'post[content]' in request.form: content = request.form['post[content]'] if 'post[structured_content]' in request.form: structured = request.form['post[structured_content]'] # Create the Post post = Post(random_id=helpers.generate_token( app.config['RANDOM_ID_LENGTH']), random_token=random_token, content=content, structured_content=structured, burn_after=burn_after, privly_application=privly_application, public=True, user=user) post.save() # Create JSON response response = helpers.jsonify(status='created', location=post, _status=201) response.headers['X-Privly-Url'] = helpers.privly_URL(post) return response
def __init__(self, email, password): self.email = email self.password = generate_password_hash(password=password, method='pbkdf2:sha512', salt_length=128) self.created = datetime.now() self.updated = self.created self.confirmation_token = generate_token()
def __init__(self, user_id): self.user_id = user_id self.regular_token = generate_token(32) self.crypto_token = generate_crypto_token(self.regular_token)