Ejemplo n.º 1
0
def registration(request):
    print "Registering"
    # Like before, get the request's context.
    context = RequestContext(request)

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        print "POST request"
        user_form = RegistrationForm(request.POST)

        # If the two forms are valid...
        if user_form.is_valid():
            print "Is valid"
            # Save the user's form data to the database.
            user = user_form.save()
            print "Saved form"
            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.is_active = False
            print "Saving user"
            user.save()

            #Create And Send User Activation Email.
            confirmation_code = ''.join(
                random.choice(string.ascii_uppercase + string.digits +
                              string.ascii_lowercase) for x in range(33))
            print "adding confirmation code to user"
            p = UserProfile(user=user, confirmation_code=confirmation_code)
            p.save()

            title = "Textile Fabric Consultants, Inc. Account Activation"
            content = "Someone has recently registered at Textilefabric.com. We hope it was you. If so, please follow the link below. If not please disregard this email.\n" + "theftp.dyndns.org:8000/login/activate/" + str(
                p.confirmation_code) + "/" + user.username
            send_mail(title,
                      content,
                      '*****@*****.**', [user.email],
                      fail_silently=False)
            #Update our variable to tell the template registration was successful.
            registered = True
            print "sent email"
            # Invalid form or forms - mistakes or something else?
            # Print problems to the terminal.
            # They'll also be shown to the user.
        else:
            print user_form.errors

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.

    form = RegistrationForm(request.POST)
    form_html = render_crispy_form(form)
    result = {'success': registered, 'form_html': form_html}
    return result
Ejemplo n.º 2
0
def registration(request):
	print "Registering"
	# Like before, get the request's context.
	context = RequestContext(request)

	# A boolean value for telling the template whether the registration was successful.
	# Set to False initially. Code changes value to True when registration succeeds.
	registered = False

	# If it's a HTTP POST, we're interested in processing form data.
	if request.method == 'POST':
		print "POST request"
		user_form = RegistrationForm(request.POST)
		

		# If the two forms are valid...
		if user_form.is_valid():
			print "Is valid"
			# Save the user's form data to the database.
			user = user_form.save()
			print "Saved form"
			# Now we hash the password with the set_password method.
			# Once hashed, we can update the user object.
			user.set_password(user.password)
			user.is_active = False 
			print "Saving user"
			user.save()

			#Create And Send User Activation Email.
			confirmation_code = ''.join(random.choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for x in range(33)) 
			print "adding confirmation code to user"
			p = UserProfile(user=user, confirmation_code=confirmation_code)      
			p.save()
				
				
			title = "Textile Fabric Consultants, Inc. Account Activation"
			content = "Someone has recently registered at Textilefabric.com. We hope it was you. If so, please follow the link below. If not please disregard this email.\n" +"theftp.dyndns.org:8000/login/activate/" + str(p.confirmation_code) + "/" + user.username
			send_mail(title, content, '*****@*****.**', [user.email], fail_silently=False)
			 #Update our variable to tell the template registration was successful.
			registered = True
			print "sent email"
			# Invalid form or forms - mistakes or something else?
			# Print problems to the terminal.
			# They'll also be shown to the user.
		else:
			print user_form.errors
			
	# Not a HTTP POST, so we render our form using two ModelForm instances.
	# These forms will be blank, ready for user input.
	
	form = RegistrationForm(request.POST)
	form_html = render_crispy_form(form)
	result = {'success': registered, 'form_html': form_html}
	return result
Ejemplo n.º 3
0
def register(request):
	if request.method == 'POST':
		umail = request.POST.get('regUmail', '')
		password = request.POST.get('regPassword', '')
		username = request.POST.get('userName', '')
		salt = hashlib.sha1(str(random.random())).hexdigest()[:5]            
        activation_key = hashlib.sha1(salt+umail).hexdigest()
        user = User.objects.create_user(username, umail, password)
        user.is_active = False
        user.save()
        new_profile = UserProfile(user=user, activation_key=activation_key)
        new_profile.save()
        email_subject = 'SBB Account confirmation'
        email_body = "Hey %s, thanks for signing up. To activate your account, click this link http://127.0.0.1:8000/confirm/%s" % (username, activation_key)
        send_mail(email_subject, email_body, '*****@*****.**', [umail], fail_silently=False)
        return HttpResponse()
Ejemplo n.º 4
0
def register(request):
    form = UserCreationForm(request.POST or None)
    if form.is_valid():
        first_name = request.POST['first_name']
        last_name = request.POST['last_name']
        email = request.POST['email']
        password = request.POST['password2']
        username = request.POST['username']
        new_user = User.create_user(username=username, email=email,
                                    password=password)
        new_user.first_name = first_name
        new_user.last_name = last_name
        new_user.save()
        auth_user = authenticate(username=username, password=password)
        login(request=request, user=auth_user)

        # Create a new account for this user
        new_account = Account(admin=new_user, company=request.POST['company'])
        new_account.save()


        # Create a user profile to link this user to this account
        new_profile = UserProfile(username=new_user.username,
                                  user=new_user,
                                  company=new_account)
        new_profile.save()

        msg = 'Created username: %s and Company: %s' % (new_user.username,
                                                        new_account.company)
        messages.success(request, msg)
        return HttpResponseRedirect('/devices/')

    data = {'title': 'Kolabria - Registration Page',
            'form': form,}
    return render_to_response('account/create.html', data,
                              context_instance=RequestContext(request))
Ejemplo n.º 5
0
def register(request):
    if request.session.get('is_login', None):
        return redirect(reverse('social:index'))

    if request.method == 'POST':
        register_form = forms.RegisterForm(request.POST)
        message = "请检查填写的内容!"
        if register_form.is_valid():
            username = register_form.cleaned_data.get('username')
            password1 = register_form.cleaned_data.get('password1')
            password2 = register_form.cleaned_data.get('password2')
            email = register_form.cleaned_data.get('email')
            sex = register_form.cleaned_data.get('sex')

            if password1 != password2:
                message = '两次输入的密码不同!'
                return render(request, 'login/register.html', locals())
            else:
                same_name_user = UserProfile.objects.filter(username=username)
                if same_name_user:
                    message = '用户名已经存在'
                    return render(request, 'login/register.html', locals())
                same_email_user = UserProfile.objects.filter(email=email)
                if same_email_user:
                    message = '该邮箱已经被注册了!'
                    return render(request, 'login/register.html', locals())

                new_user = UserProfile()
                new_user.username = username
                new_user.password = hash_code(password1)
                new_user.email = email
                new_user.sex = sex
                new_user.save()

                code = make_confirm_string(new_user)
                a = send_mail(email, code)
                print(a)

                message = '请前往邮箱进行确认!'
                return render(request, 'login/confirm.html', locals())
        else:
            return render(request, 'login/register.html', locals())

    register_form = forms.RegisterForm()
    return render(request, 'login/register.html', locals())
Ejemplo n.º 6
0
    def post(self, request):
        register_form = registerForm(request.POST)
        if register_form.is_valid():
            user_name = request.POST.get("email", "")
            if UserProfile.objects.filter(email=user_name):
                return render(request, "register.html", {
                    "register_form": register_form,
                    "msg": "用户已经存在!"
                })

            pass_word = request.POST.get("password", "")
            user_profile = UserProfile()
            user_profile.username = user_name
            user_profile.email = user_name
            user_profile.password = make_password(pass_word)
            user_profile.save()

            send_register_email(user_name, "register")
            return render(request, "success.html")
        else:

            return render(request, "register.html",
                          {"register_form": register_form})