def signup(request): user_form = UserCreateForm(data=request.POST) if request.method == 'POST': if user_form.is_valid(): username = user_form.cleaned_data['username'] password = user_form.cleaned_data['password2'] user_form.save() user = authenticate(username=username, password=password) login(request, user) return redirect('/') else: return index(request, user_form=user_form) return redirect('/')
def index(request, auth_form=None, user_form=None): # User is logged in if request.user.is_authenticated(): ribbit_form = RibbitForm() user = request.user ribbits_self = Ribbit.objects.filter(user=user.id) ribbits_buddies = Ribbit.objects.filter( user__userprofile__in=user.profile.follows.all) ribbits = ribbits_self | ribbits_buddies return render( request, 'buddies.html', { 'ribbit_form': ribbit_form, 'user': user, 'ribbits': ribbits, 'next_url': '/', }) else: # User is not logged in auth_form = auth_form or AuthenticateForm() user_form = user_form or UserCreateForm() return render(request, 'home.html', { 'auth_form': auth_form, 'user_form': user_form, })
def index(request, auth_form=None, user_form=None): # User is logged in if request.user.is_authenticated(): bookPasser_form = bookPasserForm() user = request.user bookPassers_self = bookPasser.objects.filter(user=user.id) bookPassers_buddies = bookPasser.objects.filter( user__userprofile__in=user.profile.follows.all) bookPassers = bookPassers_self | bookPassers_buddies return render( request, 'buddies.html', { 'bookPasser_form': bookPasser_form, 'user': user, 'bookPassers': bookPassers, 'next_url': '/', }) else: # User is not logged in auth_form = auth_form or AuthenticateForm() user_form = user_form or UserCreateForm() return render(request, 'home.html', { 'auth_form': auth_form, 'user_form': user_form, }) bookpasser.objects.all().delete()
def index(request, auth_form=None, user_form=None): #User is logged in context = RequestContext(request) context_dict = {} if request.user.is_authenticated(): ribbit_form = RibbitForm() user = request.user ribbits_self = Ribbit.objects.filter(user=user.id) ribbits_buddies = Ribbit.objects.filter( user__userprofile__in=user.profile.follows.all) ribbits = ribbits_self | ribbits_buddies context_dict['ribbit_form'] = ribbit_form context_dict['user'] = user context_dict['ribbits'] = ribbits context_dict['next_url'] = '/' return render(request, 'buddies.html', context_dict) else: #User is not logged in auth_form = auth_form or AuthenticateForm() user_form = user_form or UserCreateForm() return render(request, 'home.html', { 'auth_form': auth_form, 'user_form': user_form, })
def signup(request): user_form = UserCreateForm(data=request.POST) if request.method == 'POST': if user_form.is_valid(): username = user_form.clean_username() password = user_form.clean_password2() user_form.save() user = authenticate(username=username, password=password) login(request, user) return redirect('/') else: return index(request, user_form=user_form) return redirect('/')
def signup(request):#the view to sign up and register a user user_form = UserCreateForm(data=request.POST) if request.method == 'POST': #the signup view expects a POST request if user_form.is_valid(): #If the Sign Up form is valid, the user is saved to the database, authenticated, logged in and redirected to the home page. username = user_form.clean_username() password = user_form.clean_password2() user_form.save() user = authenticate(username=username, password=password) login(request, user) return redirect('/') else: #Otherwise, call the index function and pass in the instance of user_form submitted by the user to list out the errors return index(request, user_form=user_form) return redirect('/')#if the request isn't POST then the user is redirected to the root url
def signup(request): user_form = UserCreateForm(data=request.POST) if request.method == 'POST': if user_form.is_valid(): username = user_form.clean_username() password = user_form.clean_password2() if(password_entropy(password=password, tests=[more_than_length, less_than_length, lowercase_check, uppercase_check, digit_check, spcl_character_check])): user_form.save() user = authenticate(username=username, password=password) keys = create_keys(bits=1024) user_profile = user.profile user_profile.private_key = get_private_key(keys) public_key_object = user.enc public_key_object.public_key = get_public_key(keys) public_key_object.save() user_profile.save() login(request, user) return redirect('/') else: return index(request, user_form=user_form) else: return index(request, user_form=user_form) return redirect('/')