Example #1
0
def account_password_reset(request):
    err_msg = ''
    if request.method == 'POST':
        form = PasswordResetForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email')

            try:
                user = User.objects.get(email=email)
            except User.DoesNotExist:
                err_msg = design.no_such_email_in_database

            if err_msg == '':
                # change password to new random hash
                new_password = create_hash(12)

                # save it
                user.set_password(new_password)
                user.save()

                # send it in email
                subject = design.password_reset_on_website
                context = Context({
                    'new_password': new_password,
                    'host': request.get_host(),
                })
                message_txt = get_template('email/password_reset.txt').render(context)
                message_html = get_template('email/password_reset.html').render(context)
                send_html_mail(subject, message_txt, message_html, [email])

                return render_to_response('account/password_reset_ok.html', locals(), context_instance=RequestContext(request))
    else:
        form = PasswordResetForm()

    return render_to_response('account/password_reset.html', locals(), context_instance=RequestContext(request))
Example #2
0
def account_password_reset(request):
    err_msg = ''
    if request.method == 'POST':
        form = PasswordResetForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email')

            try:
                user = User.objects.get(email=email)
            except User.DoesNotExist:
                err_msg = design.no_such_email_in_database

            if err_msg == '':
                # change password to new random hash
                new_password = create_hash(12)

                # save it
                user.set_password(new_password)
                user.save()

                # send it in email
                subject = design.password_reset_on_website
                context = Context({
                    'new_password': new_password,
                    'host': request.get_host(),
                })
                message_txt = get_template('email/password_reset.txt').render(
                    context)
                message_html = get_template(
                    'email/password_reset.html').render(context)
                send_html_mail(subject, message_txt, message_html, [email])

                return render_to_response(
                    'account/password_reset_ok.html',
                    locals(),
                    context_instance=RequestContext(request))
    else:
        form = PasswordResetForm()

    return render_to_response('account/password_reset.html',
                              locals(),
                              context_instance=RequestContext(request))
Example #3
0
def ajax_create_invite(request):
    band = get_obj_from_request(request.POST, 'band', Band)
    invitee = get_obj_from_request(request.POST, 'invitee', User)

    if band is None:
        return json_failure(design.bad_band_id)

    if not band.openness == Band.FULL_OPEN:
        try:
            member = BandMember.objects.get(user=request.user, band=band)
        except BandMember.DoesNotExist:
            return json_failure(design.can_only_invite_to_your_own_band)

        if member.role != BandMember.MANAGER:
            return json_failure(design.only_managers_can_create_invitations)

    # make sure user isn't already in band
    if BandMember.objects.filter(band=band, user=invitee).count() > 0:
        return json_failure(design.x_already_in_band.format(invitee.username))

    invite = BandInvitation()
    invite.inviter = request.user
    invite.band = band
    invite.expire_date = datetime.now() + timedelta(days=30)

    if invitee == None:
        invite.code = create_hash(32)
        invite.save()
        data = {'url': invite.redeemHyperlink()}
        return json_success(data)
    else:
        # make sure invitation doesn't exist already
        if BandInvitation.objects.filter(band=band,
                                         invitee=invitee).count() > 0:
            return json_failure(
                design.already_invited_x_to_your_band.format(invitee.username))

        invite.invitee = invitee
        invite.save()
        send_invitation_email(invite, request.get_host())

        return json_success()
Example #4
0
def ajax_create_invite(request):
    band = get_obj_from_request(request.POST, 'band', Band)
    invitee = get_obj_from_request(request.POST, 'invitee', User)

    if band is None:
        return json_failure(design.bad_band_id)

    if not band.openness == Band.FULL_OPEN:
        try:
            member = BandMember.objects.get(user=request.user, band=band)
        except BandMember.DoesNotExist:
            return json_failure(design.can_only_invite_to_your_own_band)

        if member.role != BandMember.MANAGER:
            return json_failure(design.only_managers_can_create_invitations)

    # make sure user isn't already in band
    if BandMember.objects.filter(band=band, user=invitee).count() > 0:
        return json_failure(design.x_already_in_band.format(invitee.username))

    invite = BandInvitation()
    invite.inviter = request.user
    invite.band = band
    invite.expire_date = datetime.now() + timedelta(days=30)

    if invitee == None:
        invite.code = create_hash(32)
        invite.save()
        data = {'url': invite.redeemHyperlink()}
        return json_success(data)
    else:
        # make sure invitation doesn't exist already
        if BandInvitation.objects.filter(band=band, invitee=invitee).count() > 0:
            return json_failure(design.already_invited_x_to_your_band.format(invitee.username))

        invite.invitee = invitee
        invite.save()
        send_invitation_email(invite, request.get_host())

        return json_success()
Example #5
0
def user_register_plan(request, plan_url):
    "plan_url of 'free' means free plan"
    if request.user.is_authenticated():
        return change_plan(request, plan_url)

    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            plan_id = 0
            plan = None

            # create the user
            user = User.objects.create_user(form.cleaned_data.get('username'),
                form.cleaned_data.get('email'),
                form.cleaned_data.get('password'))
            user.save()

            # create a band
            band = Band()
            band.title = form.cleaned_data.get('artist_name')
            band.total_space = settings.BAND_INIT_SPACE
            band.save()

            # create a profile
            profile = Profile()
            profile.user = user
            profile.solo_band = band
            profile.activated = False
            profile.activate_code = create_hash(32)
            profile.logon_count = 0
            profile.band_count_limit = settings.FREE_BAND_LIMIT
            profile.save()

            # make them a manager
            manager = BandMember()
            manager.user = user
            manager.band = band
            manager.role = BandMember.MANAGER
            manager.save()

            # send an activation email
            subject = design.account_confirmation
            context = Context({
                'user': user,
                'activate_url': request.build_absolute_uri(reverse('confirm', args=[user.username, profile.activate_code])),
                'host': request.get_host(),
            })
            message_txt = get_template('email/activation.txt').render(context)
            message_html = get_template('email/activation.html').render(context)
            send_html_mail(subject, message_txt, message_html, [user.email])

            return HttpResponseRedirect(reverse("register_pending"))
    else:
        try:
            plan = AccountPlan.objects.get(url=plan_url)
            plan_id = plan.id
        except AccountPlan.DoesNotExist:
            plan = None
            plan_id = 0

        form = RegisterForm(initial={'plan': plan_id})
    return render_to_response('register.html', {'form': form}, context_instance=RequestContext(request))
Example #6
0
def obfuscated_url(band):
    return os.path.join('band', band.url, create_hash(16))   
Example #7
0
def ajax_email_invite(request):
    "send a band invitation by email."
    to_email = get_val(request.POST, 'email', '')
    band = get_obj_from_request(request.POST, 'band', Band)
    
    if band is None:
        return json_failure(design.bad_band_id)

    if not band.permission_to_invite(request.user):
        return json_failure(design.lack_permission_to_invite)

    if to_email == '':
        return json_failure(design.you_must_supply_an_email_address)

    if not is_valid_email(to_email):
        return json_failure(design.invalid_email_address)

    # if the email is a registered solid composer user, simply translate into direct invitation.
    try:
        local_user = User.objects.get(email=to_email)
    except User.DoesNotExist:
        local_user = None

    invite = BandInvitation()       
    invite.inviter = request.user
    invite.band = band
    invite.role = BandMember.BAND_MEMBER

    subject = design.x_is_inviting_you_to_join_y.format(request.user.username, band.title)
    if local_user is not None:
        # make sure the user isn't already in the band
        if BandMember.objects.filter(user=local_user, band=band).count() > 0:
            return json_failure(design.x_already_in_band.format(local_user.username))

        # make sure there isn't already an invitation for them
        if BandInvitation.objects.filter(invitee=local_user, band=band).count() > 0:
            return json_failure(design.already_invited_x_to_your_band.format(local_user.username))

        invite.invitee = local_user
        invite.save()
        
        # send a heads up email
        if local_user.get_profile().email_notifications:
            context = Context({
                'user': request.user,
                'band': band,
                'invite': invite,
                'host': request.get_host(),
            })
            message_txt = get_template('workbench/email/invitation_direct.txt').render(context)
            message_html = get_template('workbench/email/invitation_direct.html').render(context)
            send_html_mail(subject, message_txt, message_html, [to_email])

        return json_success()
    else:
        # create invitation link
        invite.expire_date = datetime.now() + timedelta(days=30)
        invite.code = create_hash(32)
        invite.save()

        # send the invitation email
        context = Context({
            'user': request.user,
            'band': band,
            'invite': invite,
            'host': request.get_host(),
        })
        message_txt = get_template('workbench/email/invitation_link.txt').render(context)
        message_html = get_template('workbench/email/invitation_link.html').render(context)
        send_html_mail(subject, message_txt, message_html, [to_email])

        return json_success()
Example #8
0
def user_register_plan(request, plan_url):
    "plan_url of 'free' means free plan"
    if request.user.is_authenticated():
        return change_plan(request, plan_url)

    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            plan_id = 0
            plan = None

            # create the user
            user = User.objects.create_user(form.cleaned_data.get('username'),
                                            form.cleaned_data.get('email'),
                                            form.cleaned_data.get('password'))
            user.save()

            # create a band
            band = Band()
            band.title = form.cleaned_data.get('artist_name')
            band.total_space = settings.BAND_INIT_SPACE
            band.save()

            # create a profile
            profile = Profile()
            profile.user = user
            profile.solo_band = band
            profile.activated = False
            profile.activate_code = create_hash(32)
            profile.logon_count = 0
            profile.band_count_limit = settings.FREE_BAND_LIMIT
            profile.save()

            # make them a manager
            manager = BandMember()
            manager.user = user
            manager.band = band
            manager.role = BandMember.MANAGER
            manager.save()

            # send an activation email
            subject = design.account_confirmation
            context = Context({
                'user':
                user,
                'activate_url':
                request.build_absolute_uri(
                    reverse('confirm',
                            args=[user.username, profile.activate_code])),
                'host':
                request.get_host(),
            })
            message_txt = get_template('email/activation.txt').render(context)
            message_html = get_template('email/activation.html').render(
                context)
            send_html_mail(subject, message_txt, message_html, [user.email])

            return HttpResponseRedirect(reverse("register_pending"))
    else:
        try:
            plan = AccountPlan.objects.get(url=plan_url)
            plan_id = plan.id
        except AccountPlan.DoesNotExist:
            plan = None
            plan_id = 0

        form = RegisterForm(initial={'plan': plan_id})
    return render_to_response('register.html', {'form': form},
                              context_instance=RequestContext(request))
Example #9
0
def ajax_email_invite(request):
    "send a band invitation by email."
    to_email = get_val(request.POST, 'email', '')
    band = get_obj_from_request(request.POST, 'band', Band)

    if band is None:
        return json_failure(design.bad_band_id)

    if not band.permission_to_invite(request.user):
        return json_failure(design.lack_permission_to_invite)

    if to_email == '':
        return json_failure(design.you_must_supply_an_email_address)

    if not is_valid_email(to_email):
        return json_failure(design.invalid_email_address)

    # if the email is a registered solid composer user, simply translate into direct invitation.
    try:
        local_user = User.objects.get(email=to_email)
    except User.DoesNotExist:
        local_user = None

    invite = BandInvitation()
    invite.inviter = request.user
    invite.band = band
    invite.role = BandMember.BAND_MEMBER

    subject = design.x_is_inviting_you_to_join_y.format(
        request.user.username, band.title)
    if local_user is not None:
        # make sure the user isn't already in the band
        if BandMember.objects.filter(user=local_user, band=band).count() > 0:
            return json_failure(
                design.x_already_in_band.format(local_user.username))

        # make sure there isn't already an invitation for them
        if BandInvitation.objects.filter(invitee=local_user,
                                         band=band).count() > 0:
            return json_failure(
                design.already_invited_x_to_your_band.format(
                    local_user.username))

        invite.invitee = local_user
        invite.save()

        # send a heads up email
        if local_user.get_profile().email_notifications:
            context = Context({
                'user': request.user,
                'band': band,
                'invite': invite,
                'host': request.get_host(),
            })
            message_txt = get_template(
                'workbench/email/invitation_direct.txt').render(context)
            message_html = get_template(
                'workbench/email/invitation_direct.html').render(context)
            send_html_mail(subject, message_txt, message_html, [to_email])

        return json_success()
    else:
        # create invitation link
        invite.expire_date = datetime.now() + timedelta(days=30)
        invite.code = create_hash(32)
        invite.save()

        # send the invitation email
        context = Context({
            'user': request.user,
            'band': band,
            'invite': invite,
            'host': request.get_host(),
        })
        message_txt = get_template(
            'workbench/email/invitation_link.txt').render(context)
        message_html = get_template(
            'workbench/email/invitation_link.html').render(context)
        send_html_mail(subject, message_txt, message_html, [to_email])

        return json_success()
Example #10
0
def obfuscated_url(band):
    return os.path.join('band', band.url, create_hash(16))