def registration_view(request): try: cart_id = request.session['cart_id'] cart = Cart.objects.get(id=cart_id) request.session['total'] = cart.items.count() except: cart = Cart() cart.save() cart_id = cart.id request.session['cart_id'] = cart_id cart = Cart.objects.get(id=cart_id) form = RegistrationForm(request.POST or None) categories = Category.objects.all() if form.is_valid(): new_user = form.save(commit=False) first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['password'] email = form.cleaned_data['email'] username = form.cleaned_data['username'] password = form.cleaned_data['password'] new_user.first_name = first_name new_user.last_name = last_name new_user.email = email new_user.username = username new_user.set_password(password) new_user.save() aunth_user = authenticate(username=username, password=password) if aunth_user: login(request, aunth_user) return HttpResponseRedirect(reverse('main_page')) context = {'form': form, 'categories': categories} return render(request, 'registration.html', context)
def register(): error = None # # if User.query.filter_by(email=request.form['email']).count()==0: # user = User( # email=request.form["email"], # username=request.form["username"], # password=request.form["password"], # register_time=datetime.utcnow() # ) # db.session.add(user) # db.session.commit() # return redirect(url_for('auth.login')) # else: # return jsonify({'error':'email already been use!'}) form = RegistrationForm() if form.validate_on_submit(): user = User(email=form.email.data, username=form.username.data, password=form.password.data, register_time=datetime.utcnow()) db.session.add(user) db.session.commit() flash('You can now login.') return redirect(url_for('main.login')) return render_template('auth/register.html', form=form)
def register(): if current_user.is_authenticated: redirect(url_for('main')) title = "Register" meta_description = "DJs, Live Musicians and Booking Agents are welcome to use this tool." \ " You can build nice PDF Riders for free, but you have to Register." form = RegistrationForm() if request.method == "GET": flash( 'You are probably going to rebuild the document multiple times,' ' so I have to store your data somehow. It is not used anywhere and you will have an opportunity' ' to completely delete yourself after you are done.', 'info') if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() login_user(user, remember=True) flash(f'User {user} created', 'success') return redirect(url_for('main')) return render_template('register.html', title=title, form=form, meta_description=meta_description)
def test_registration_form(self): """Registration form validity test""" form = RegistrationForm( data={ 'username': '******', 'email': '*****@*****.**', 'password1': 'iublnredmw', 'password2': 'iublnredmw', }) self.assertTrue(form.is_valid())
def register(): form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, password=hashed_password) db.session.add(user) db.session.commit() flash('Account created!') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('index')) form = RegistrationForm() if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data) user.set_password(form.password.data) db.session.add(user) db.session.commit() flash('Congratulations, you are now a registered user!') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def test_RegistrationForm(self): valid_data = { "username": "******", "email": "*****@*****.**", "password1": "s3cr3tshh", "password2": "s3cr3tshh", "first_name": "john", "last_name": "doe" } form = RegistrationForm(data=valid_data) self.assertEquals(form.fields['password1'].label, 'Password') form.is_valid() self.assertFalse(form.errors)
def register(): form = RegistrationForm() if form.validate_on_submit(): # Connected the registration page to database hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash(f'Your account has been created, you can now Login!', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def post(self, request, *args, **kwargs): form = RegistrationForm(request.POST) if form.is_valid(): new_user = form.save(commit=False) new_user.username = form.cleaned_data['username'] new_user.email = form.cleaned_data['email'] new_user.name = form.cleaned_data['name'] new_user.save() new_user.set_password(form.cleaned_data['password']) new_user.save() user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password']) login(request, user) messages.success(request, 'Welcomm in our club') return HttpResponseRedirect('/') context = {'form': form} return render(request, 'registration.html', context)
def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() return redirect('/myapp') else: form = RegistrationForm() return render(request, 'myapp/register.html', {'form': form})
def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('myapp:login')) else: form = RegistrationForm() return render(request, 'myapp/register.html', {'form': form})
def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() return redirect(reverse('myapp:home')) else: form = RegistrationForm() args = {'form': form} return render(request, 'reg_form.html',args)
def register(request): """Registartion page""" if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() return redirect('login') else: form = RegistrationForm() context = {'form': form} return render(request, 'registration/register.html', context)
def register(request): 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) login(request, user) return redirect(reverse('myapp:index')) else: form = RegistrationForm() return render(request, 'myapp/register.html', {'form': form})
def register(request): if request.method=='POST': form=RegistrationForm(request.POST) if form.is_valid(): user=form.save(commit=False) user.set_password(form.cleaned_data['password']) user.save() else: return render(request,"myapp/register.html",{'form':form}) form=RegistrationForm() return render(request,"myapp/register.html",{'form':form})
def register(request): args = {} args.update(csrf(request)) if request.method == 'POST': form = RegistrationForm(request.POST) args['form'] = form if form.is_valid(): form.save() # save user to database if form is valid # Email Verification Starts Here username = form.cleaned_data['username'] email = form.cleaned_data['email'] salt = hashlib.sha1(str(random.random())).hexdigest()[:5] activation_key = hashlib.sha1(salt+email).hexdigest() key_expires = datetime.today() + timedelta(2) print key_expires #Get user by username user=User.objects.get(username=username) user.is_active = True user.save() # Create and save user profile new_profile = UserProfile(user=user, activation_key=activation_key, key_expires=key_expires) new_profile.save() # Send email with activation key #send_mial(subject,message,from_email,to_list,fail_silently=True) email_subject = 'Company Name - Account confirmation' email_body = "Hey %s, thanks for signing up. To activate your account, click this link within \ 48hours http://127.0.0.1:8000/user_confirm/%s" % (username, activation_key) from_email = settings.EMAIL_HOST_USER # template = get_template('verification_email.html') # context = Context({'username': username, 'activation_key': activation_key}) html_message = ''' <div style="border:1px solid black; margin:5px"> <strong>Dear %s,</strong></br>activation_key <p> Greetings from Company Name. Thank you for registering with us<p> <p> Please click on below button to complete registration</p> <div style="text-align:center"> <input type="button" href="http://127.0.0.1:8000/user_confirm/%s" value="Click here to complete registration"> </div> <p> If the button is not visible, please click on below link or copy-paste the url in browser:</p> http://127.0.0.1:8000/user_confirm/%s <p> If you face any difficulties, write to us at <a style="color:blue; font-weight:bold">[email protected]</a > or call us on <a style="color:blue; font-weight:bold">(+91) 8179608300</a></p></br> <strong>Have a great day!!!</strong> </br> </br> <p>Regards,</p> <p>SuportTeam, NearByMedics</p> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> ''' % (username, activation_key, activation_key) # html_message = template.render(context) # send_mail(email_subject, email_body, settings.EMAIL_HOST_USER, [user.email], fail_silently=True, html_message = html_message) args['form'] = RegistrationForm() args['register_success'] = True return render(request,'register.html', args ) else: form = RegistrationForm() args['form'] = form args['register_success'] = False return render(request,'register.html', args)
def get(self, request, *args, **kwargs): form = RegistrationForm(request.POST) product = Product.objects.all() context = {'form': form, 'product': product} return render(request, 'registration.html', context)
def test_registration_form_invalid(self): """Registration form validity test""" form = RegistrationForm(data={}) self.assertFalse(form.is_valid())
def register(): form = RegistrationForm() if form.validate_on_submit(): flash(f'Account created for {form.username.data}!', 'success') return redirect(url_for('home')) return render_template('register.html', title='Register', form=form)