def register(request): context = RequestContext(request) registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) if user_form.is_valid(): user = user_form.save() user.set_password(user.password) user.is_active = False user.save() profile = Profile.create_profile(user) profile.host = "http://cs410.cs.ualberta.ca:41024" profile.save() registered = True else: print user_form.errors else: user_form = UserForm() if registered == True: return HttpResponse("<script>alert(\"Account Successfully Created!!\"); window.location = \'/login\';</script>") else: return render_to_response('authors/register.html', {'user_form': user_form, 'registered': registered}, context)
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() user.save() profile = profile_form.save(commit=False) profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] profile.save() registered = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render(request, 'register.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() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if "picture" in request.FILES: profile.picture = request.FILES["picture"] profile.save() registered = True else: print user_form.erros, profile_forms.errors else: user_form = UserForm() profile_form = UserProfileForm() return render( request, "register.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(): profile = profile_form.save(commit=False) user = user_form.save() profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] profile.save() #Email confirmation to user subject = 'PVSAT: Author registration confirmation' text_content = render_to_string("user_sub_conf.txt", {'user': user, 'URL': settings.SITE_URL}) html_content = render_to_string("user_sub_conf.html", {'user': user, 'URL': settings.SITE_URL}) email = user.email msg1 = EmailMultiAlternatives(subject, text_content, '', [email]) msg1.attach_alternative(html_content, "text/html") #Email confirmation to admin subject = 'New Author' text_content = render_to_string("user_to_admin.txt", {'user': user, 'profile': profile, 'URL': settings.SITE_URL}) msg2 = EmailMultiAlternatives(subject, text_content, '', [settings.ADMIN_EMAIL]) if settings.EMAIL_STATUS: msg1.send() msg2.send() registered = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render(request, 'register.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() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] profile.save() registered = True else: print user_form.erros, profile_forms.errors else: user_form = UserForm() profile_form = UserProfileForm() return render(request, 'register.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(): profile = profile_form.save(commit=False) user = user_form.save() profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] profile.save() #Email confirmation to user subject = 'PVSAT: Author registration confirmation' text_content = render_to_string("user_sub_conf.txt", { 'user': user, 'URL': settings.SITE_URL }) html_content = render_to_string("user_sub_conf.html", { 'user': user, 'URL': settings.SITE_URL }) email = user.email msg1 = EmailMultiAlternatives(subject, text_content, '', [email]) msg1.attach_alternative(html_content, "text/html") #Email confirmation to admin subject = 'New Author' text_content = render_to_string("user_to_admin.txt", { 'user': user, 'profile': profile, 'URL': settings.SITE_URL }) msg2 = EmailMultiAlternatives(subject, text_content, '', [settings.ADMIN_EMAIL]) if settings.EMAIL_STATUS: msg1.send() msg2.send() registered = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render( request, 'register.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })