Exemplo n.º 1
0
def new_register(request):
    """ This is for a new user who wishes to register independent of twitter and facebook; 
        we use gravatar for these users.
    """
    if request.method == 'POST':
            form = NewPlayerForm(request.POST)
            if form.is_valid():
                first_name = form.cleaned_data['first_name']
                last_name = form.cleaned_data['last_name']
                username = form.cleaned_data['username']
                email = form.cleaned_data['email']  
                phone_number = form.cleaned_data['phone_number']
                sports = form.cleaned_data['sports']
                gender = form.cleaned_data['gender']
                password1 = form.cleaned_data['password1']
                password2 = form.cleaned_data['password2']

                user = User.objects.create_user(username=username, email=email, password=password1)
                user.first_name = first_name
                user.last_name = last_name
                user.save()
                player = Player()
                player.gender = gender
                player.user = user
                player.phone_number = phone_number
                player.image_url = get_gravatar(player.user.email)
                player.save()
                player.sports = sports
                user = authenticate(username=player.user, password=password1)
                login(request, user)
                SignUpTask.delay(user)
                return HttpResponseRedirect('/')
    else:
        if 'email' in request.GET:
            form = NewPlayerForm(initial={'email': request.GET['email']})
        else:
            form = NewPlayerForm()
    return render(request, 'new_register.html', {'form': form})
Exemplo n.º 2
0
def complete_sign_up(request):
    """ This will use form object will be referenced here 
        and used to fill in user data that is missing for twitter and facebook
        data. 

        Keyword arguments:
        request - 
    """
    if 'twitter' in request.session:
        if request.method == 'POST':
            form = PlayerForm(request.POST)
            if form.is_valid():
                player =  request.session['twitter']
                user =  player.user
                first_name = form.cleaned_data['first_name']
                last_name = form.cleaned_data['last_name']
                username = form.cleaned_data['username']
                email = form.cleaned_data['email']  
                phone_number = form.cleaned_data['phone_number']
                sports = form.cleaned_data['sports']
                gender = form.cleaned_data['gender']
                player.gender = gender
                user.first_name = first_name
                user.last_name = last_name
                user.username = username
                user.email = email
                user.save()
                player.user = user
                player.image_url = get_gravatar(player.user.email)
                player.save()
                player.sports = sports
                user1 = authenticate(username=player.user.username, password=player.twitter_oauth_secret)
                login(request, user1)
                SignUpTask.delay(user)
                return HttpResponseRedirect('/')
        else:
            form = PlayerForm()
        return render(request, 'register.html', {'form': form})
        
    if 'facebook' in request.session:
        if request.method == 'POST':
            form = PlayerForm(request.POST)
            if form.is_valid():
                player =  request.session['facebook']
                user =  player.user
                first_name = form.cleaned_data['first_name']
                last_name = form.cleaned_data['last_name']
                username = form.cleaned_data['username']
                email = form.cleaned_data['email']  
                phone_number = form.cleaned_data['phone_number']
                sports = form.cleaned_data['sports']
                gender = form.cleaned_data['gender']
                player.gender = gender
                user.first_name = first_name
                user.last_name = last_name
                user.username = username
                user.email = email
                user.save()
                player.user = user
                player.image_url = get_gravatar(player.user.email)
                player.save()
                player.sports = sports
                user = authenticate(username=player.user.username, password=player.facebook_oauth_token)
                login(request, user)
                print "SEND EMAIL"
                SignUpTask.delay(user)
                return HttpResponseRedirect('/')
    else:
        form = PlayerForm()
    return render(request, 'register.html', {'form': form})