Example #1
0
def get_video_thumbnail(request):
    url = request.GET.get('url')
    if not url:
        return api_response.invalid_param("Missing url parameter")
    thumbnail_url = get_thumbnail(url)
    if thumbnail_url:
        return {'thumbnail': thumbnail_url}
Example #2
0
def invite_friends_to_competition_by_email(request):
    """	Invite friend to compete """
    sender_user_id = request.user.id

    competition_id = request.POST.get('competition_id')
    if competition_id is None:
        return api_response.invalid_param(
            {'message': 'missing competition_id'})

    errors = []
    emailsStr = request.POST.get('emails')
    if emailsStr is not None:
        emails = emailsStr.split(',')
        for email in emails:
            email = email.strip()
            if not email_re.search(email):
                errors.append(email)
            else:
                Invite.objects.get_or_create(sender_user_id=sender_user_id,
                                             competition_id=competition_id,
                                             kind=InviteType.FRIEND,
                                             invite_email=email)
                context = {
                    'url': settings.SERVER_URL,
                    'compete_url': reverse('competition:view',
                                           args=[competition_id]),
                }
                html = render_to_string('emails/invite_friend_email.html',
                                        context)
                mail.send_mail(
                    sender='Starboxx TV Invitations <%s>' % settings.EMAIL_NOREPLY,
                    to=email,
                    subject="Invite to Compete on Starboxx.TV",
                    body='',
                    html=html)

    if len(errors) > 0:
        return api_response.error(errors)
    else:
        return api_response.ok({'stat': 'ok'})
Example #3
0
def signup_complete(request):  # todo rewrite in classed-based-style
    """	Complete signup and send verification email """
    # todo: check if ajax
    # todo: check if POST
    # todo: check for CSRF - ok
    # logging.error(request.POST)
    username = request.POST.get('username')
    email = request.POST.get('email')
    gender = request.POST.get('gender')
    birthdate = request.POST.get('birthdate')
    try:
        if birthdate:
            birthdate = datetime.strptime(birthdate, '%b %d %Y')
    except ValueError:
        birthdate = None
        logging.error('Wrong birthday')

    username_exists = User.objects.filter(username=username)
    email_exists = User.objects.filter(email=email)

    if username_exists:
        # todo: show this error on front-end
        return api_response.invalid_param('username already exists')

    if not email_exists:
        user = request.user
        profile = user.profile
        user.username = username
        user.save()
        profile.birthdate = birthdate
        profile.gender = gender
        profile.save()
        EmailValidation.objects.add(user, username, email)

    return api_response.ok({'email': not email_exists,
                            'username': not username_exists})