def love(): recipients = sanitize_recipients(request.form.get('recipients')) message = request.form.get('message').strip() secret = (request.form.get('secret') == 'true') link_id = request.form.get('link_id') if not recipients: flash('Enter a name, lover.', 'error') return redirect(url_for('home')) recipients_display_str = ', '.join(recipients) if not message: flash('Enter a message, lover.', 'error') return redirect(url_for('home', recipients=recipients_display_str)) try: real_recipients = logic.love.send_loves(recipients, message, secret=secret) # actual recipients may have the sender stripped from the list real_display_str = ', '.join(real_recipients) if secret: flash('Secret love sent to {}!'.format(real_display_str)) return redirect(url_for('home')) else: hash_key = link_id if link_id else create_love_link(real_display_str, message).hash_key return redirect(url_for('sent', message=message, recipients=real_display_str, link_id=hash_key)) except TaintedLove as exc: if exc.is_error: flash(exc.user_message, 'error') else: flash(exc.user_message) return redirect(url_for('home', recipients=recipients_display_str, message=message))
def love_link(link_id): try: loveLink = logic.love_link.get_love_link(link_id) recipients_str = loveLink.recipient_list message = loveLink.message recipients = sanitize_recipients(recipients_str) loved = [ Employee.get_key_for_username(recipient).get() for recipient in recipients ] return render_template( 'love_link.html', current_time=datetime.utcnow(), current_user=Employee.get_current_employee(), recipients=recipients_str, message=message, loved=loved, link_id=link_id, ) except NoSuchLoveLink: flash('Sorry, that link ({}) is no longer valid.'.format(link_id), 'error') return redirect(url_for('home'))
def love(): recipients = sanitize_recipients(request.form.get('recipients')) message = request.form.get('message').strip() secret = (request.form.get('secret') == 'true') if not recipients: flash('Enter a name, lover.', 'error') return redirect(url_for('home')) recipients_display_str = ', '.join(recipients) if not message: flash('Enter a message, lover.', 'error') return redirect(url_for('home', recipients=recipients_display_str)) try: logic.love.send_loves(recipients, message, secret=secret) flash('{}ove sent to {}!'.format('Secret l' if secret else 'L', recipients_display_str)) return redirect(url_for('home')) except TaintedLove as exc: if exc.is_error: flash(exc.user_message, 'error') else: flash(exc.user_message) return redirect( url_for('home', recipients=recipients_display_str, message=message))
def api_send_loves(): sender = request.form.get('sender') recipients = sanitize_recipients(request.form.get('recipient')) message = request.form.get('message') try: send_loves(recipients, message, sender_username=sender) recipients_display_str = ', '.join(recipients) return make_response( u'Love sent to {}!'.format(recipients_display_str), LOVE_CREATED_STATUS_CODE, {}) except TaintedLove as exc: return make_response( exc.user_message, LOVE_FAILED_STATUS_CODE if exc.is_error else LOVE_CREATED_STATUS_CODE, {})
def sent(): link_id = request.args.get('link_id', None) recipients_str = request.args.get('recipients', None) message = request.args.get('message', None) if not link_id or not recipients_str or not message: return redirect(url_for('home')) recipients = sanitize_recipients(recipients_str) loved = [ Employee.get_key_for_username(recipient).get() for recipient in recipients ] return render_template( 'sent.html', current_time=datetime.utcnow(), current_user=Employee.get_current_employee(), message=message, loved=loved, url='{0}l/{1}'.format(config.APP_BASE_URL, link_id), )
def _test_sanitization(self, input_recipients, expected_recipients): sanitized_recipients = sanitize_recipients(input_recipients) self.assertEqual( sanitized_recipients, expected_recipients, )