def register(request): args = {} args.update(csrf(request)) if request.method == 'POST': register_form = RegistrationForm(request.POST) # create form object if register_form.is_valid(): register_form.save() username = request.POST['username'] password = request.POST['password1'] user = authenticate(username=username, password=password) if user is not None: auth.login(request, user) html_register = get_template('email_register.html', ) register_html = Context({'first_name': request.user.first_name, 'last_name': request.user.last_name}) html_content = html_register.render(register_html) subject = 'Regisration' from_email = '*****@*****.**' to = auth.get_user(request).email msg = EmailMultiAlternatives(subject, '', from_email, [to]) msg.attach_alternative(html_content, "text/html") try: msg.send() except: pass return redirect('index') else: args['custom_error'] = register_form args['register_form'] = register_form else: register_form = RegistrationForm() args['register_form'] = register_form return render(request, 'register.html', args)
def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() return redirect('/qwer') else: form = RegistrationForm() arg = {'form': form} return render(request, 'main/register.html', arg)
def register(request): """Register and create a user if a valid form is submitted""" if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') user = authenticate(username=username, password=raw_password) return redirect('login') else: form = RegistrationForm() return render(request, 'main/register.html', {'form': form})
def analyzer_signup(request): """ Sign up for an assistant account. """ if request.user.is_authenticated(): return redirect('internal:profile') if request.method == 'POST': post = request.POST.copy() request.POST = post form = RegistrationForm(request.POST) if form.is_valid(): cd = form.cleaned_data password = cd['password1'] user = form.save() g, created = Group.objects.get_or_create(name='assistant') g.user_set.add(user) g.save() user = auth.authenticate(username=user.email, password=password) auth.login(request, user) return redirect('internal:profile') return render(request, 'analyzer_signup.html', {'form': form}) else: form = RegistrationForm() return render(request, 'analyzer_signup.html', {'form': form})
def registration_view(request): cart = try_session(request) form = RegistrationForm(request.POST or None) if form.is_valid(): new_user = form.save(commit=False) username = form.cleaned_data['username'] password = form.cleaned_data['password'] new_user.username = username new_user.set_password(password) new_user.first_name = form.cleaned_data['first_name'] new_user.last_name = form.cleaned_data['last_name'] phone = Phone(user= username, phone =form.cleaned_data['phone'] ) new_user.email = form.cleaned_data['email'] new_user.save() phone.save() login_user = authenticate(username=username, password=password) if login_user: login(request, login_user) return HttpResponseRedirect(reverse('base')) c = count(cart) context = { 'c': c, 'cart': cart, 'categories': get_categories(), 'form': form, } return render(request,'registration.html',context)
def index_page(request): was_saved = False show_message = u'' if request.method == 'POST': if 'new_register' in request.POST: form = RegistrationForm() else: form = RegistrationForm(request.POST) if form.is_valid(): form.save() was_saved = True show_message = form.message form = RegistrationForm() else: form = RegistrationForm() ctx = {'show_message': show_message, 'was_saved': was_saved, 'form': form} return render(request, 'index.html', ctx)
def registration(request): edit_form = RegistrationForm() if request.method == 'POST': edit_form = RegistrationForm(data=request.POST) if edit_form.is_valid(): user = edit_form.save(commit=False) user.username = str(uuid.uuid4().int)[:10] user.save() return redirect('login') return render(request, 'main/registration.html', {'edit_form': edit_form})
def index_page(request): was_saved = False show_message = u'' if request.method == 'POST': if 'new_register' in request.POST: form = RegistrationForm() else: form = RegistrationForm(request.POST) if form.is_valid(): form.save() was_saved = True show_message = form.message form = RegistrationForm() else: form = RegistrationForm() ctx = { 'show_message': show_message, 'was_saved': was_saved, 'form': form } return render(request, 'index.html', ctx)
def register(request): # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = RegistrationForm(request.POST) # check whether it's valid: if form.is_valid(): post = form.save(commit=False) post.save() # process the data in form.cleaned_data as required # ... # redirect to a new URL: messages.success(request, 'You successfully registered.') # if a GET (or any other method) we'll create a blank form else: form = RegistrationForm() return render(request, 'register.html', {'form': form})