def userSignUp(request): context = {} if request.method == "POST": formData = SignUpForm(request.POST) if formData.is_valid(): username = formData.cleaned_data['username'] first_name = formData.cleaned_data['name'] email = formData.cleaned_data['email'] password = formData.cleaned_data['password'] contact_no = formData.cleaned_data['contact_no'] address = formData.cleaned_data['address'] try: User.objects.get(username=username, password=password) messages.warning(request, "User already Registered") return redirect('/authentication/authenticate.do/') except ObjectDoesNotExist: user = User.objects.create_user(username=username, email=email, first_name=first_name, password=password) user_add = Address(address=address, contact_no=contact_no, user_id=user) user_add.save() messages.success(request, "Signed Up Successfully") return redirect('/authentication/authenticate.do/') else: context['form'] = formData return render(request, 'authentication/signup.html', context) else: context['form'] = SignUpForm(None) return render(request, 'authentication/signup.html', context)
def signup(request): """Render sign up view.""" if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): user = form.save(commit=False) user.is_active = False user.save() current_site = get_current_site(request) subject = _('Activá tu cuenta de NFL prode') message = render_to_string('authentication/account_activation_email.html', { 'user': user, 'domain': current_site.domain, 'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(), 'token': account_activation_token.make_token(user), }) user.email_user(subject, message) return redirect('account_activation_sent') else: form = SignUpForm() return render(request, 'authentication/signup.html', {'form': form, 'view': 'signup'})
def registerView(request): if request.method == 'POST': form = SignUpForm(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) login(request, user) return redirect('/') else: form = SignUpForm() if (request.user.is_authenticated): user = User.objects.get(username=request.user.username) context = { 'form': form, 'user': user, } else: context = { 'form': form, } return render(request, 'register.html', context=context)
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if not form.is_valid(): return render(request, 'authentication/signup.html', {'form': form}) else: user = form.save(commit=False) email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') user.set_password(password) user.is_active = False user.save() current_site = get_current_site(request) subject = 'Activate Your Onlinebookshare Account' message = render_to_string('authentication/account_activation_email.html', { 'user': user, 'domain': current_site.domain, 'uid': urlsafe_base64_encode(force_bytes(user.pk)), 'token': account_activation_token.make_token(user), }) send_mail(subject, message, '*****@*****.**', [email]) return redirect('account_activation_sent') else: return render(request, 'authentication/signup.html', {'form': SignUpForm()})
def signup(request): if request.method == 'POST': form = SignUpForm(data=request.POST) if form.is_valid(): user = form.save(commit=False) # Setting as False to prevent login without confirming email user.is_active = False user.save() current_site = get_current_site(request) subject = 'Verify your DjangoLogin Account' message = render_to_string( 'authentication/account_activation_email.html', { 'user': user, 'domain': current_site.domain, 'uid': urlsafe_base64_encode(force_bytes( user.pk)).decode(), 'token': account_activation_token.make_token(user), }) user.email_user(subject, message) print("Mail Done!") return redirect(to='authentication:account_activation_sent') else: return render(request, template_name='authentication/signup.html', context={'form': form}) else: form = SignUpForm() return render(request, template_name='authentication/signup.html', context={'form': form})
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if not form.is_valid(): ## Lin,Leo - provide a context with error message to the user ## of why form validation failed! return render(request, 'authentication/signup.html', {'form': form}) else: username = form.cleaned_data.get('username') email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') User.objects.create_user(username=username, password=password, email=email) user = authenticate(username=username, password=password) login(request, user) ## Lin,Leo - once the user has successfully signed-in, we ## redirect them to their own portal return redirect( 'home') ## - TODO: redirect user to their own portal else: return render(request, 'authentication/signup.html', {'form': SignUpForm()})
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if not form.is_valid(): return render(request, 'authentication/signup.html', {'form': form}) else: username = form.cleaned_data.get('username') password = form.cleaned_data.get('password') email = form.cleaned_data.get('email') birthday = form.cleaned_data.get('birthday') randomId = form.cleaned_data.get('randomId') User.objects.create_user(username=username, password=password, email=email, randomId=randomId, birthday=birthday) #import pdb; pdb.set_trace() user = authenticate(username=username, password=password) login(request, user) welcome_post = '{0} has joined the network.'.format( user.username, user.username) return redirect('list') else: return render(request, 'authentication/signup.html', {'form': SignUpForm()})
def user_management(request): msg = None success = False if request.method == "POST": form = SignUpForm(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) msg = 'User created' success = True #return redirect("/login/") else: msg = 'Form is not valid' else: form = SignUpForm() context = {} context['segment'] = 'user-management.html' context['page_name'] = 'User Management' context['users'] = User.objects.all() context['form'] = form context['msg'] = msg context['success'] = success html_template = loader.get_template('user-management.html') return HttpResponse(html_template.render(context, request))
def signUp(request): form = SignUpForm() if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): # Comprobar que no haya usuario con el mismo correo if User.objects.filter( email=form.cleaned_data['email']).count() > 0: form.add_error('email', 'El email indicado ya está en uso') return render(request, 'signUp.html', {'form': form}) # Comprobar que no haya usuario con mismo username if User.objects.filter( username=form.cleaned_data['username']).count() > 0: form.add_error('username', 'El nombre de usuario indicado ya está en uso') return render(request, 'signUp.html', {'form': form}) user = User.objects.create_user(form.cleaned_data['username'], form.cleaned_data['email'], form.cleaned_data['password']) user.first_name = form.cleaned_data['nombre'] user.last_name = form.cleaned_data['apellidos'] user.save() perfil = Perfil(user=user) perfil.save() for dieta in form.cleaned_data['dieta']: perfil.dietas.add(get_object_or_404(Dieta, nombre=dieta)) return redirect('/authentication/login') return render(request, 'signUp.html', {'form': form})
def sign_up(request): if request.method == "GET": form = SignUpForm() return render(request, 'authentication/sign_up.html', {'form': form}) elif request.method == "POST": form = SignUpForm(request.POST) if form.is_valid(): user = form.save() return redirect('authentication:login') return render(request, 'authentication/sign_up.html', {'form': form})
def signup_view(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): data = form.cleaned_data new_twitter_user = TwitterUser.objects.create_user(username=data.get('username'), password=data.get('password'), tagname=data.get('tagname'), bio=data.get('bio')) login(request, new_twitter_user) return HttpResponseRedirect(reverse('homepage')) form = SignUpForm() return render(request, 'signupform.html', {'form': form})
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if not form.is_valid(): messages.add_message( request, messages.ERROR, 'There was some problems while creating your account. Please review some fields before submiting again.') return render(request, 'auth/signup.html', {'form': form}) else: return HttpResponse('is valid') else: return render(request, 'auth/signup.html', {'form': SignUpForm()})
def signup_view(request): if request.method == "POST": form = SignUpForm(request.POST) if form.is_valid(): data = form.cleaned_data new_user = TwitterUser.objects.create_user( username=data.get("username"), password=data.get("password")) login(request, new_user) return HttpResponseRedirect(reverse("homepage")) form = SignUpForm() return render(request, "generic_form.html", {"form": form})
def register(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): form.save() return redirect('authentication:login') else: form = SignUpForm() return render(request, 'register.html', {'form': form})
def signupview(request): if request.method == "POST": form = SignUpForm(request.POST) if form.is_valid(): data = form.cleaned_data user = TwitterUser.objects.create_user( username=data['username'], password=data['password'], ) return HttpResponseRedirect(reverse('homepage')) form = SignUpForm() return render(request, 'generic_form.htm', {'form': form})
def signup(request): if request.method == 'POST': form = SignUpForm(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) login(request, user) return redirect('/books/') else: form = SignUpForm() return render(request, 'signup.html', {'form': form})
def signup_view(request): if request.method == "POST": form = SignUpForm(request.POST) if form.is_valid(): data = form.cleaned_data user = TwitterUser.objects.create_user( username=data['username'], password=data['password'], displayname=data['displayname']) if user: login(request, user) return HttpResponseRedirect(reverse('loginpage')) form = SignUpForm() return render(request, 'signup.html', {"form": form})
def signupview(request): if request.method == "POST": form = SignUpForm(request.POST) if form.is_valid(): data = form.cleaned_data user = authenticate(request, username=data['username'], password=data['password']) if user: login(request, user) return HttpResponseRedirect( request.GET.get('next', reverse('homepage'))) form = SignUpForm() return render(request, 'generic_form.html', {'form': form})
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): if form.validate(): # Custom validation username = form.cleaned_data['username'] first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] email = form.cleaned_data['email'] new_password = form.cleaned_data['new_password'] # Create user user = User.objects.create( username=username, email=email, first_name=first_name, last_name=last_name, ) user.set_password(new_password) user.is_active = False user.save() # Create authentication object for activation auth_object = UserAuthentication.objects.create(user=user) auth_object.save() # Send mail about activation email_subject = 'Bruker @ hackerspace NTNU' message = 'Gratulerer! Du har nå laget deg en bruker hos Hackerspace NTNU.' \ ' Aktiver brukeren ved å trykke på følgende link: ' email_message = render_to_string( 'signup_mail.html', { 'request': request, 'message': message, 'hash_key': auth_object.key.hex }) thread = Thread(target=send_password_email, args=(email_subject, email_message, email)) thread.start() return HttpResponseRedirect(reverse('signup_done')) else: form = SignUpForm() context = {'form': form} return render(request, 'signup.html', context)
def signup(request, **kwargs): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): user = form.save() user.refresh_from_db() user.profile.birth_date = form.cleaned_data.get('birth_date') user.save() username = user.username raw_password = form.cleaned_data.get('password1') user = authenticate(username=username, password=raw_password) login(request, user) return redirect('home') else: form = SignUpForm() return render(request, 'signup.html', {'form': form})
def signup(request): html = 'signupform.html' form = SignUpForm() if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): data = form.cleaned_data user = TwitterUser.objects.create_user( username=data['username'], displayname=data['displayname'], password=data['password'], ) login(request, user) return HttpResponseRedirect(reverse('homepage')) form = SignUpForm() return render(request, html, {'form': form})
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): user = form.save() user.profile.brith_day = form.cleaned_data.get('birth_date') user.save() raw_password = form.cleaned_data.get('password1') user = authenticate(username=user.username, password=raw_password) login(request, user) return redirect('/home') else: return render(request, 'registration/signup.html', {'form': form}) else: form = SignUpForm() return render(request, 'registration/signup.html', {'form': form})
def signup(request): html = 'generic_form.htm' if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): data = form.cleaned_data user = CustomUser.objects.create_user( username=data['username'], password=data['password'], display_name=data['display_name'], homepage=data['homepage'], age=data['age']) return HttpResponseRedirect(reverse('home')) form = SignUpForm() return render(request, html, {'form': form})
def test_when_missing_required_fields(self): """To check the response when a required fields is missing""" for field in ('email', 'password1', 'password2'): with self.subTest(field=field): my_data = self.data.copy() my_data[field] = '' form = SignUpForm(my_data) self.assertFalse(form.is_valid())
def signup_view(request): context = {} if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): data = form.cleaned_data user_info = TwitterUser.objects.create_user( first_name=data['first_name'], last_name=data['last_name'], username=data['username'], email=data['email'], password=data['password'], ) return HttpResponseRedirect(reverse('twitteruser:home_view')) form = SignUpForm() context.update({'form': form, 'heading_two': 'Sign Up'}) return render(request, 'forms/generic.html', context)
def signup_view(request): if request.method == "POST": form = SignUpForm(request.POST, request.FILES) if form.is_valid(): data = form.cleaned_data new_user = InstaUser.objects.create_user( username=data.get("username"), password=data.get("password"), bio=data.get("bio"), website=data.get("website"), profile_image=data.get("profile_image")) login(request, new_user) return HttpResponseRedirect(reverse("homepage")) else: return HttpResponse(form.errors.values()) form = SignUpForm() return render(request, 'generic_form.html', {"form": form})
def get(self, request): form = SignUpForm() subreddit_filter = subreddit_search(request) context = { 'form': form, 'subreddit_filter': subreddit_filter, 'search_subreddits': search_subreddits } return render(request, 'authentication/signupform.html', context)
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): username = form.cleaned_data.get('username') email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') user = User.objects.create_user(username=username, password=password, email=email) user.refresh_from_db() user.profile.role = form.cleaned_data.get('role') user.save() user = authenticate(username=username, password=password) login(request, user) return redirect('/account/login/') else: form = SignUpForm() return render(request, 'authentication/signup.html', {'form': form})
def login(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): user = form.save(commit=False) try: user.refresh_from_db() if user.profile.authenticates_by_mail: send_activation(request, user) return redirect('authentication:account_activation_sent', is_new=False) except ObjectDoesNotExist: print('ObjectDoesNotExist') pass # I'm not sure this can ever happen. # There should be precisely one or zero existing user with the # given email, but since the django user model doesn't impose # a unique constraint on user emails, I'm stuck verifying this. existing_users = User.objects.filter( email=form.cleaned_data['email']) if len(existing_users) > 1: return HttpResponseServerError( "Data error: Multiple email addresses found") if len(existing_users) == 1: existing_user = existing_users[0] if existing_user.profile.authenticates_by_mail: send_activation(request, existing_user) return redirect('authentication:account_activation_sent', is_new=False) user.email = form.cleaned_data['email'] user.username = get_random_string(20) user.is_active = False user.save() send_activation(request, user) return redirect('authentication:account_activation_sent', is_new=True) else: # Form is not valid. pass else: form = SignUpForm() return render(request, 'authentication/login.html', {'form': form})
def post(self, request): form = SignUpForm(request.POST) if form.is_valid(): data = form.cleaned_data new_user = TwitterUser.objects.create_user( username=data['username'], password=data['password1'], ) new_user.save() login(request, new_user) return HttpResponseRedirect(reverse('home'))