def authapp_sign_up(request): user_form = UserForm() pizzashop_form = PizzaShopForm() if request.method == "POST": user_form = UserForm(request.POST) pizzashop_form = PizzaShopForm(request.POST, request.FILES) if user_form.is_valid() and pizzashop_form.is_valid(): new_user = User.objects.create_user(**user_form.cleaned_data) new_pizzashop = pizzashop_form.save(commit=False) new_pizzashop.user = new_user new_pizzashop.save() user = authenticate( username = user_form.cleaned_data['username'], password = user_form.cleaned_data['password'] ) login(request, user) return redirect(authapp_home) return render(request, 'authapp/sign_up.html', { 'user_form': user_form, 'pizzashop_form': pizzashop_form })
def authapp_sign_up(request): user_form = UserForm() pizzashop_form = PizzaShopForm() return render(request, 'authapp/sign_up.html', { 'user_form': user_form, 'pizzashop_form': pizzashop_form })
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileInfoForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.save() profile = profile_form.save(commit=False) profile.user = user if 'profile_pic' in request.FILES: profile.profile_pic = request.FILES.profile_pic profile.save() registered = True else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = UserProfileInfoForm() return render( request, 'authapp/registration.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileInfoForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.is_active = False #+ user.save() ''' current_site = get_current_site(request) subject = 'Please Activate Your Account' # load a template like get_template() # and calls its render() method immediately. message = render_to_string('activation_request.html', { 'user': user, 'domain': current_site.domain, 'uid': urlsafe_base64_encode(force_bytes(user.pk)), # method will generate a hash value with user related data 'token': account_activation_token.make_token(user), }) user.email_user(subject, message) return redirect('activation_sent') ''' profile = profile_form.save(commit=False) profile.user = user if 'profile_pic' in request.FILES: print('found it') profile.profile_pic = request.FILES['profile_pic'] profile.save() registered = True else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = UserProfileInfoForm() return render( request, 'authapp/registration.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save( ) #here we grab the form and saves to the database user.set_password(user.password) #here we hashe the password user.save() #here we save the hashed password to the database #add the custom user attributes we created to user profile = profile_form.save( commit=False ) #we dont want to commit to the database yet bc it might have collisions and overwrite the user profile.user = user #sets a one to one relationship #check if picture was provided (or any type of file actually) if 'profile_pic' in request.FILES: profile.profile_pic = request.FILES['profile_pic'] profile.save() registered = True else: print(user_form.erros, profile_form.erros) else: user_form = UserForm() profile_form = UserProfileForm() return render( request, 'authapp/registration.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })