Esempio n. 1
0
def register(request):
    form = ChallengesRegisterForm(
        initial=request.GET,
        enable_register_club=feature_is_enabled('challenge_register_club'))
    if request.method == "POST":
        form = ChallengesRegisterForm(request.POST, enable_register_club=feature_is_enabled('challenge_register_club'))
        if form.is_valid():
            username = form.cleaned_data.get('email_address')
            password = form.cleaned_data.get('password')
            user = User.objects.create_user(username, username, password)
            user.save()
            user.spudder_user.mark_password_as_done()
            fan_entity = create_and_activate_fan_role(request, user)
            fan_page = fan_entity.entity
            fan_page.username = form.cleaned_data.get('username')
            fan_page.state = str(request.META.get('HTTP_X_APPENGINE_REGION')).upper()
            fan_page.save()
            login(request, authenticate(username=username, password=password))
            if feature_is_enabled('tracking_pixels'):
                EventController.RegisterEvent(request, EventController.CHALLENGER_USER_REGISTERER)
            if form.cleaned_data.get('account_type') == EntityController.ENTITY_CLUB:
                return redirect('/challenges/register/team?next=%s' % form.cleaned_data.get('next', '/'))
            return redirect(form.cleaned_data.get('next', '/'))
    return render(
        request,
        'spudderspuds/challenges/pages/register.html',
        {'form': form})
Esempio n. 2
0
def _state_engine_process_register(request, challenge, engine, state, template_data):
    response = None
    next_state = _StateEngineStates.NOTICE
    if engine == "pledge-only":
        next_state = _StateEngineStates.PLEDGE
    if request.current_role:
        state = next_state
    else:
        form = FanRegisterForm()
        if request.method == "POST":
            form = FanRegisterForm(request.POST)
            if form.is_valid():
                username = form.cleaned_data.get('email_address')
                password = form.cleaned_data.get('password')
                user = User.objects.create_user(username, username, password)
                user.save()
                user.spudder_user.mark_password_as_done()
                fan_entity = create_and_activate_fan_role(request, user)
                request.current_role = fan_entity
                fan_page = fan_entity.entity
                fan_page.username = create_at_name_from_email_address(username)
                fan_page.state = form.cleaned_data.get('state')
                fan_page.save()
                user = authenticate(username=username, password=password)
                login(request, user)
                if feature_is_enabled('tracking_pixels'):
                    EventController.RegisterEvent(request, EventController.CHALLENGER_USER_REGISTERER)
                state = next_state
                response = redirect('/challenges/%s/%s/%s' % (challenge.id, engine, state))
        if state == _StateEngineStates.REGISTER:
            template_data['form'] = form
            response = render(request, 'spudderspuds/challenges/pages_ajax/register.html', template_data)
    return response, state
Esempio n. 3
0
def register(request):
    form = ChallengesRegisterForm(
        initial=request.GET,
        enable_register_club=feature_is_enabled('challenge_register_club'))
    if request.method == "POST":
        form = ChallengesRegisterForm(
            request.POST,
            enable_register_club=feature_is_enabled('challenge_register_club'))
        if form.is_valid():
            username = form.cleaned_data.get('email_address')
            password = form.cleaned_data.get('password')
            user = User.objects.create_user(username, username, password)
            user.save()
            user.spudder_user.mark_password_as_done()
            fan_entity = create_and_activate_fan_role(request, user)
            fan_page = fan_entity.entity
            fan_page.username = form.cleaned_data.get('username')
            fan_page.state = str(
                request.META.get('HTTP_X_APPENGINE_REGION')).upper()
            fan_page.save()
            login(request, authenticate(username=username, password=password))
            if feature_is_enabled('tracking_pixels'):
                EventController.RegisterEvent(
                    request, EventController.CHALLENGER_USER_REGISTERER)
            if form.cleaned_data.get(
                    'account_type') == EntityController.ENTITY_CLUB:
                return redirect('/challenges/register/team?next=%s' %
                                form.cleaned_data.get('next', '/'))
            return redirect(form.cleaned_data.get('next', '/'))
    return render(request, 'spudderspuds/challenges/pages/register.html',
                  {'form': form})
Esempio n. 4
0
def _state_engine_process_register(request, challenge, engine, state,
                                   template_data):
    response = None
    next_state = _StateEngineStates.NOTICE
    if engine == "pledge-only":
        next_state = _StateEngineStates.PLEDGE
    if request.current_role:
        state = next_state
    else:
        form = FanRegisterForm()
        if request.method == "POST":
            form = FanRegisterForm(request.POST)
            if form.is_valid():
                username = form.cleaned_data.get('email_address')
                password = form.cleaned_data.get('password')
                user = User.objects.create_user(username, username, password)
                user.save()
                user.spudder_user.mark_password_as_done()
                fan_entity = create_and_activate_fan_role(request, user)
                request.current_role = fan_entity
                fan_page = fan_entity.entity
                fan_page.username = create_at_name_from_email_address(username)
                fan_page.state = form.cleaned_data.get('state')
                fan_page.save()
                user = authenticate(username=username, password=password)
                login(request, user)
                if feature_is_enabled('tracking_pixels'):
                    EventController.RegisterEvent(
                        request, EventController.CHALLENGER_USER_REGISTERER)
                state = next_state
                response = redirect('/challenges/%s/%s/%s' %
                                    (challenge.id, engine, state))
        if state == _StateEngineStates.REGISTER:
            template_data['form'] = form
            response = render(
                request, 'spudderspuds/challenges/pages_ajax/register.html',
                template_data)
    return response, state
Esempio n. 5
0
def user_add_fan_role(request):
    if not request.current_role:
        return redirect('/spuds/register')
    fan_role = create_and_activate_fan_role(request, request.user)
    return redirect('/fan/%s/edit?new_registration=true' % fan_role.entity.id)
Esempio n. 6
0
def fan_register(request):
    # Should the current_role be here?
    should_be_here, response = should_current_role_be_here(request)
    if not should_be_here:
        return response

    # Extract an invitation if there is one
    invitation = extract_invitation_from_request(request)

    template_data = {'tab': request.GET.get('tab', 'fan')}
    form = FanRegisterForm(initial=request.GET)
    club_form = RegisterClubWithFanForm()


    if request.method == "POST":
        is_valid = True
        tab = request.POST.get('tab')
        template_data['tab'] = tab

        if tab == 'org':
            club_form = RegisterClubWithFanForm(request.POST)
            is_valid = club_form.is_valid()

        form = FanRegisterForm(request.POST)
        if is_valid and form.is_valid():
            # Get the form data
            username = form.cleaned_data.get('email_address')
            password = form.cleaned_data.get('password')
            state = form.cleaned_data.get('state')
            # Create the auth.User
            user = User.objects.create_user(username, username, password)
            user.save()
            user.spudder_user.mark_password_as_done()
            # Create the Fan
            fan_role = create_and_activate_fan_role(request, user)
            request.current_role = fan_role
            fan_page = fan_role.entity
            fan_page.state = state
            at_name = create_at_name_from_email_address(username)
            fan_page.username = at_name
            fan_page.save()
            # Login the user
            login(request, authenticate(username=username, password=password))
            is_signin_claiming_spud(
                request,
                fan_role.entity,
                form.cleaned_data.get('twitter', None),
                form.cleaned_data.get('spud_id', None))
            if invitation:
                if invitation.invitation_type == Invitation.REGISTER_AND_ADMINISTRATE_TEAM_INVITATION:
                    team_admin = TeamAdministrator(entity_type=fan_role.entity_type, entity_id=fan_role.entity.id)
                    team_admin.team_page_id = invitation.target_entity_id
                    team_admin.save()
                    invitation.status = Invitation.ACCEPTED_STATUS
                    invitation.save()
                elif invitation.invitation_type == Invitation.AFFILIATE_INVITE_CLUB_ADMINISTRATOR:
                    fan_role.entity.affiliate = Affiliate.objects.get(name=invitation.extras['affiliate_name'])
                    return HttpResponseRedirect('/spudderaffiliates/invitation/%s/create_club' % invitation.id)
                return redirect('/fan/follow?origin=invitation')
            if tab == 'org':
                # Get the form data
                club_name = club_form.cleaned_data.get('name')
                # Create the club
                club = Club(name=club_name, state=state)
                club.save()
                # Create the club admin
                club_admin = ClubAdministrator(club=club, admin=user)
                club_admin.save()
                club_admin_role = change_current_role(request, RoleController.ENTITY_CLUB_ADMIN, club_admin.id)
                request.current_role = club_admin_role
                EventController.RegisterEvent(request, EventController.CLUB_REGISTERED)
            return redirect(request.current_role.home_page_path)

    template_data["form"] = form
    template_data['club_form'] = club_form
    return render(request, 'spudderspuds/pages/user_register.html', template_data)
Esempio n. 7
0
def user_add_fan_role(request):
    if not request.current_role:
        return redirect('/spuds/register')
    fan_role = create_and_activate_fan_role(request, request.user)
    return redirect('/fan/%s/edit?new_registration=true' % fan_role.entity.id)
Esempio n. 8
0
def fan_register(request):
    # Should the current_role be here?
    should_be_here, response = should_current_role_be_here(request)
    if not should_be_here:
        return response

    # Extract an invitation if there is one
    invitation = extract_invitation_from_request(request)

    template_data = {'tab': request.GET.get('tab', 'fan')}
    form = FanRegisterForm(initial=request.GET)
    club_form = RegisterClubWithFanForm()

    if request.method == "POST":
        is_valid = True
        tab = request.POST.get('tab')
        template_data['tab'] = tab

        if tab == 'org':
            club_form = RegisterClubWithFanForm(request.POST)
            is_valid = club_form.is_valid()

        form = FanRegisterForm(request.POST)
        if is_valid and form.is_valid():
            # Get the form data
            username = form.cleaned_data.get('email_address')
            password = form.cleaned_data.get('password')
            state = form.cleaned_data.get('state')
            # Create the auth.User
            user = User.objects.create_user(username, username, password)
            user.save()
            user.spudder_user.mark_password_as_done()
            # Create the Fan
            fan_role = create_and_activate_fan_role(request, user)
            request.current_role = fan_role
            fan_page = fan_role.entity
            fan_page.state = state
            at_name = create_at_name_from_email_address(username)
            fan_page.username = at_name
            fan_page.save()
            # Login the user
            login(request, authenticate(username=username, password=password))
            is_signin_claiming_spud(request, fan_role.entity,
                                    form.cleaned_data.get('twitter', None),
                                    form.cleaned_data.get('spud_id', None))
            if invitation:
                if invitation.invitation_type == Invitation.REGISTER_AND_ADMINISTRATE_TEAM_INVITATION:
                    team_admin = TeamAdministrator(
                        entity_type=fan_role.entity_type,
                        entity_id=fan_role.entity.id)
                    team_admin.team_page_id = invitation.target_entity_id
                    team_admin.save()
                    invitation.status = Invitation.ACCEPTED_STATUS
                    invitation.save()
                elif invitation.invitation_type == Invitation.AFFILIATE_INVITE_CLUB_ADMINISTRATOR:
                    fan_role.entity.affiliate = Affiliate.objects.get(
                        name=invitation.extras['affiliate_name'])
                    return HttpResponseRedirect(
                        '/spudderaffiliates/invitation/%s/create_club' %
                        invitation.id)
                return redirect('/fan/follow?origin=invitation')
            if tab == 'org':
                # Get the form data
                club_name = club_form.cleaned_data.get('name')
                # Create the club
                club = Club(name=club_name, state=state)
                club.save()
                # Create the club admin
                club_admin = ClubAdministrator(club=club, admin=user)
                club_admin.save()
                club_admin_role = change_current_role(
                    request, RoleController.ENTITY_CLUB_ADMIN, club_admin.id)
                request.current_role = club_admin_role
                EventController.RegisterEvent(request,
                                              EventController.CLUB_REGISTERED)
            return redirect(request.current_role.home_page_path)

    template_data["form"] = form
    template_data['club_form'] = club_form
    return render(request, 'spudderspuds/pages/user_register.html',
                  template_data)