Esempio n. 1
0
def register_action(request):
    context = {}
    # Just display the registration form if this is a GET request.
    if request.method == 'GET':
        context['form'] = RegistrationForm()
        return render(request, 'register.html', context)
    # Creates a bound form from the request POST parameters and makes the
    # form available in the request context dictionary.
    form = RegistrationForm(request.POST)
    context['form'] = form
    # Validates the form.
    if not form.is_valid():
        return render(request, 'register.html', context)
    # At this point, the form data is valid.  Register and login the user.
    new_user = User.objects.create_user(
        username=form.cleaned_data['username'],
        password=form.cleaned_data['password'],
        email=form.cleaned_data['email'],
        first_name=form.cleaned_data['first_name'],
        last_name=form.cleaned_data['last_name'])
    new_user.save()

    new_user = authenticate(username=form.cleaned_data['username'],
                            password=form.cleaned_data['password'])
    login(request, new_user)
    profile = Profile(user=request.user)
    profile.save()
    return redirect(reverse('home'))
Esempio n. 2
0
def register(request):
    context = {}

    # Just display the registration form if this is a GET request.
    if request.method == 'GET':
        context['form'] = RegistrationForm()
        return render(request, 'socialnetwork/register.html', context)

    # Creates a bound form from the request POST parameters and makes the
    # form available in the request context dictionary.
    form = RegistrationForm(request.POST)
    context['form'] = form

    # Validates the form.
    if not form.is_valid():
        return render(request, 'socialnetwork/register.html', context)

    # At this point, the form data is valid.  Register and login the user.
    new_user = User.objects.create_user(username=form.cleaned_data['username'],
                                        password=form.cleaned_data['password1'],
                                        email=form.cleaned_data['email'],
                                        first_name=form.cleaned_data['first_name'],
                                        last_name=form.cleaned_data['last_name'])

    # Mark the user as inactive to prevent login before email confirmation.
    new_user.is_active = False
    new_user.save()



    # Give every new user a default profile
    default_profile = Profile(
        owner=new_user
    )
    default_profile.save()

    # Generate a one-time use token and an email message body
    token = default_token_generator.make_token(new_user)

    email_body = """
    Please click the link below to verify your email address and
    complete the registration of your account:
      http://{host}{path}
    """.format(host=request.get_host(),
               path=reverse('confirm', args=(new_user.username, token)))

    send_mail(subject="Verify your email address",
              message=email_body,
              from_email="*****@*****.**",
              recipient_list=[new_user.email])

    context['email'] = form.cleaned_data['email']
    return render(request, 'socialnetwork/needs-confirmation.html', context)
Esempio n. 3
0
def register(request):
    context = {}

    # Just display the registration form if this is a GET request.
    if request.method == 'GET':
        context['form'] = RegistrationForm()
        return render(request, 'socialnetwork/register.html', context)

    # Creates a bound form from the request POST parameters and makes the
    # form available in the request context dictionary.
    form = RegistrationForm(request.POST)
    context['form'] = form

    # Validates the form.
    if not form.is_valid():
        return render(request, 'socialnetwork/register.html', context)

    # At this point, the form data is valid.  Register and login the user.
    new_user = User.objects.create_user(
        username=form.cleaned_data['username'],
        password=form.cleaned_data['password1'],
        first_name=form.cleaned_data['first_name'],
        last_name=form.cleaned_data['last_name'],
        email=form.cleaned_data['email'])
    new_user.is_active = False
    new_user.save()

    #    entry = Entry(age=0 ,created_by=new_user,update_time=datetime.now(),creation_time= datetime.now())
    #    entry.save()

    # Generate a one-time use token and an email message body
    token = default_token_generator.make_token(new_user)

    email_body = """
Welcome to Voice @ CMU  Please click the link below to
verify your email address and complete the registration of your account:

  http://%s%s
""" % (request.get_host(), reverse('confirm', args=(new_user.username, token)))

    send_mail(subject="Verify your email address",
              message=email_body,
              from_email="*****@*****.**",
              recipient_list=[new_user.email])

    context['email'] = form.cleaned_data['email']
    return render(request, 'socialnetwork/needs-confirmation.html', context)
Esempio n. 4
0
def register(request):
    context = {}

    # Just display the registration form if this is a GET request.
    if request.method == 'GET':
        context['registerform'] = RegistrationForm()
        return render(request, 'register.html', context)

    # Creates a bound form from the request POST parameters and makes the
    # form available in the request context dictionary.
    registerform = RegistrationForm(request.POST)
    context['registerform'] = registerform

    # Validates the form.
    if not registerform.is_valid():
        return render(request, 'register.html', context)

    # At this point, the form data is valid.  Register and login the user.
    new_user = User.objects.create_user(
        username=registerform.cleaned_data['username'],
        password=registerform.cleaned_data['password1'],
        email=registerform.cleaned_data['email'])
    # Mark the user as inactive to prevent login before email confirmation.
    new_user.is_active = False
    new_user.save()

    # Generate a one-time use token and an email message body
    token = default_token_generator.make_token(new_user)

    email_body = """
Welcome to the Simple Address Book.  Please click the link below to
verify your email address and complete the registration of your account:

  http://%s%s
""" % (request.get_host(),
       reverse('confirm',
               args=(new_user.username, registerform.cleaned_data['password1'],
                     token)))

    send_mail(subject="Verify your email address",
              message=email_body,
              from_email="*****@*****.**",
              recipient_list=[new_user.email])

    context['email'] = registerform.cleaned_data['email']
    return render(request, 'needs-confirmation.html', context)
Esempio n. 5
0
def register(request):
    context = {}

    # Just display the registration form if it is a GET request
    if request.method == 'GET':
        context['form'] = RegistrationForm()
        return render(request, 'socialnetwork/register.html', context)

    
    form = RegistrationForm(request.POST)
    context['form'] = form

    if not form.is_valid():
        return render(request, 'socialnetwork/register.html', context)

    # Creates the new user from the valid form data
    new_user = User.objects.create_user(username = form.cleaned_data['username'],
                                        password = form.cleaned_data['password1'],
                                        first_name = form.cleaned_data['first_name'],
                                        last_name = form.cleaned_data['last_name'],
                                        email = form.cleaned_data['email'])
    new_user.is_active = False
    new_user.save()

    token = default_token_generator.make_token(new_user)
    email_body = """
        Welcome to the WebApp Class Address Book.  Please click the link below to
        verify your email address and complete the registration of your account:
        http://%s%s
    """ % (request.get_host(),
            reverse('confirm', args = (new_user.username, token)))

    send_mail(subject = "Verify your email address",
              message = email_body, 
              from_email = "*****@*****.**",
              recipient_list = [new_user.email])



    new_user_profile = Profile(user = new_user,
                               age = form.cleaned_data['age'],
                               bio = form.cleaned_data['bio'])
    new_user_profile.save()

    context['email'] = form.cleaned_data['email']
    return render(request, 'socialnetwork/need-confirmation.html', context)
def temp_account(request):
    # Use the RegistrationForm to validate the generated user for safety
    charspace = u'abcdefghijklmnopqrstuvwxyz0123456789'
    username = "******"+get_random_string(length=4, allowed_chars=charspace)

    while User.objects.filter(username__exact=username):
        if attempts >= 100:
            # this should be extremely unlikely, probably indicates a bug
            return Http404()
        username="******"+get_random_string(length=4, allowed_chars=charspace)

    form = RegistrationForm({"username": username,
                             "password1": username,
                             "password2": username,
                             "first_name": "Temporary",
                             "last_name": "User",
                             "email": username+"@mailinator.com"
                            })

    # Validates the form.
    if not form.is_valid():
         # this should never happen, and means that something is broken
        return Http404()

    new_user = User.objects.create_user(username=form.cleaned_data['username'], 
                                        password=form.cleaned_data['password1'],
                                        first_name=form.cleaned_data['first_name'],
                                        last_name=form.cleaned_data['last_name'],
                                        email=form.cleaned_data['email'])
    new_user.save()


    new_user_profile = UserProfile(user=new_user)
    new_user_profile.save()

    new_script = Script(userprofile=new_user_profile)
    new_script.save()

    # Logs in the new user and redirects to global stream
    new_user = authenticate(username=form.cleaned_data['username'],
                            password=form.cleaned_data['password1'])
    login(request, new_user)
    
    return redirect(reverse('stream'))
Esempio n. 7
0
def register(request):
    context = {}

    # Just display the registration form if this is a GET request.
    if request.method == 'GET':
        context['registerform'] = RegistrationForm()
        return render(request, 'register.html', context)

    # Creates a bound form from the request POST parameters and makes the 
    # form available in the request context dictionary.
    registerform = RegistrationForm(request.POST)
    context['registerform'] = registerform

    # Validates the form.
    if not registerform.is_valid():
        return render(request, 'register.html', context)

    # At this point, the form data is valid.  Register and login the user.
    new_user = User.objects.create_user(username=registerform.cleaned_data['username'], 
                                        password=registerform.cleaned_data['password1'],
                                        email=registerform.cleaned_data['email'])
    # Mark the user as inactive to prevent login before email confirmation.
    new_user.is_active = False
    new_user.save()

    # Generate a one-time use token and an email message body
    token = default_token_generator.make_token(new_user)

    email_body = """
Welcome to the Simple Address Book.  Please click the link below to
verify your email address and complete the registration of your account:

  http://%s%s
""" % (request.get_host(), 
       reverse('confirm', args=(new_user.username,registerform.cleaned_data['password1'],token)))

    send_mail(subject="Verify your email address",
              message= email_body,
              from_email="*****@*****.**",
              recipient_list=[new_user.email])

    context['email'] = registerform.cleaned_data['email']
    return render(request, 'needs-confirmation.html', context)
Esempio n. 8
0
def register(request):
    context = {}

    # Just display the registration form if this is a GET request.
    if request.method == 'GET':
        context['form'] = RegistrationForm()
        return render(request, 'socialnetwork/register.html', context)

    form = RegistrationForm(request.POST)
    context['form'] = form

    # Validates the form.
    if not form.is_valid():
        return render(request, 'socialnetwork/register.html', context)

    # At this point, the form data is valid.  Register and login the user.
    new_user = User.objects.create_user(
        username=form.cleaned_data['username'],
        password=form.cleaned_data['password1'],
        email=form.cleaned_data['email'],
        first_name=form.cleaned_data['first_name'],
        last_name=form.cleaned_data['last_name'])
    new_user.save()

    new_user = authenticate(username=form.cleaned_data['username'],
                            password=form.cleaned_data['password1'])
    login(request, new_user)
    profile = Profile(last_name=new_user.last_name,
                      first_name=new_user.first_name,
                      username=new_user.username,
                      bio="",
                      img=None)
    profile.user = new_user
    profile.save()
    # print profile.username
    return redirect(reverse('home'))
Esempio n. 9
0
def register(request):
    context = {}
    print request.FILES
    # Just display the registration form if this is a GET request.
    if request.method == 'GET':
        context['registration_form'] = RegistrationForm()
        context['profile_form'] = EditProfile()
        return render(request, 'socialnetwork/register.html', context)

    # Creates a bound form from the request POST parameters and makes the 
    # form available in the request context dictionary.
    registration_form = RegistrationForm(request.POST)
    profile_form = EditProfile(request.POST, request.FILES)

    # Validates the form.
    if not registration_form.is_valid():
        print "reg form not valid"
        return render(request, 'socialnetwork/register.html', {'registration_form':registration_form, 'profile_form':profile_form})

    if not profile_form.is_valid():
        print "profile form not valid"
        return render(request, 'socialnetwork/register.html', {'registration_form':registration_form, 'profile_form':profile_form})

    # At this point, the form data is valid.  Register and login the user.
    new_user = User.objects.create_user(username=registration_form.cleaned_data['username'], 
                                        password=registration_form.cleaned_data['password1'],
                                        first_name=registration_form.cleaned_data['first_name'],
                                        last_name=registration_form.cleaned_data['last_name'],
                                        email=registration_form.cleaned_data['email'])

    # Mark the user as inactive to prevent login before email confirmation.
    new_user.is_active = False
    new_user.save()

    new_profile = Profile()
    new_profile.user = new_user
    new_profile.age=profile_form.cleaned_data['age'] 
    new_profile.bio=profile_form.cleaned_data['bio']

    if profile_form.cleaned_data['picture']:
        url = s3_upload(profile_form.cleaned_data['picture'], new_user.id)
        new_profile.picture_url = url
    new_profile.save()

    # Generate a one-time use token and an email message body
    token = default_token_generator.make_token(new_user)

    email_body = """
Welcome to your Social Network. Please click the link below to
verify your email address and complete the registration of your account:

  http://%s%s
""" % (request.get_host(), 
       reverse('confirm', args=(new_user.username, token)))

    send_mail(subject="Verify your email address",
              message= email_body,
              from_email="*****@*****.**",
              recipient_list=[new_user.email])

    context['email'] = registration_form.cleaned_data['email']
    return render(request, 'socialnetwork/needsconfirmation.html', context)
def register(request):
    context = {}

    # Just display the registration form if this is a GET request
    if request.method == 'GET':
        context['form']= RegistrationForm()
        return render(request, 'socialnetwork/register.html',context)

    form = RegistrationForm(request.POST)
    context['form'] = form

    # Validates the form.
    if not form.is_valid():
        return render(request, 'socialnetwork/register.html', context)

    # At this point, the form data is valid.  Register and login the user.
    new_user = User.objects.create_user(username=form.cleaned_data['username'], 
                                        password=form.cleaned_data['password1'],
                                        first_name=form.cleaned_data['first_name'],
                                        last_name=form.cleaned_data['last_name'],
                                        email=form.cleaned_data['email'])
    # new_user.is_active = False
    new_user.save()


    new_user_profile = UserProfile(user=new_user)
    new_user_profile.save()

    new_script = Script(userprofile=new_user_profile)
    new_script.save()


    #### Email verification
    # 
    #  # Generate a one-time use token and an email message body
    # token = default_token_generator.make_token(new_user)

    # email_body = """
    # Welcome to the Social Network.  Please click the link below to
    # verify your email address and complete the registration of your account:
    # http://%s%s
    # """ % (request.get_host(), 
    #    reverse('confirm_registration', args=[new_user.username, token]))

    # send_mail(subject="Verify your email address",
    #           message= email_body,
    #           from_email="*****@*****.**",
    #           recipient_list=[new_user.email])

    # context['email'] = form.cleaned_data['email']

    # return render(request, 'socialnetwork/needs-confirmation.html',context)



    # Logs in the new user and redirects to global stream
    new_user = authenticate(username=form.cleaned_data['username'],
                            password=form.cleaned_data['password1'])
    login(request, new_user)


    return redirect(reverse('stream'))