Ejemplo n.º 1
0
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.lower(), email=form.email.data.lower())
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()

        flash('Вы успешно зарегистрировались!', 'success')
        return redirect(url_for('index'))

    return render_template('register.html', title='Регистрация', form=form)
def register():
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    form = RegistrationForm()
    if form.validate_on_submit():
        h_pass = bcrybt.generate_password_hash(
            form.password.data).decode("utf-8")
        user = User(name=form.username.data,
                    password=h_pass,
                    email=form.email.data)
        db.session.add(user)
        db.session.commit()
        flash(f'Account created for {form.username.data}!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 3
0
 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, 'Welcome in our club')
         return HttpResponseRedirect('/cinema/')
     context = {'form': form}
     return render(request, 'registration.html', context)
Ejemplo n.º 4
0
def register(request):
    '''
	Page for user signup.
	'''
    # Ensure there is nobody logged in.
    if request.user.is_authenticated:
        return redirect('dashboard')

    title = 'Register'
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        # Create the user.
        if form.is_valid():
            form.save()
            # Redirect to login page.
            return redirect('login')
    else:
        # Recreate the form since we aren't posting.
        form = RegistrationForm()

    # Return the form if the form isn't valid or user just entered page.
    return render(request, 'registration/register.html', {
        'form': form,
        'title': title
    })
Ejemplo n.º 5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = RegistrationForm()
    if form.validate_on_submit():
        hashed = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed)
        db.session.add(user)
        db.session.commit()
        flash('Sua conta foi criada com sucesso.', 'success')
        return redirect(url_for('login'))

    popular = Post.query.order_by(desc(Post.total_score)).limit(3)
    return render_template('register.html',
                           title='Register',
                           form=form,
                           popular_posts=popular)
Ejemplo n.º 6
0
def register(request):
	# Ensure there is nobody logged in
	if request.user.is_authenticated:
		return redirect('index')

	title = 'Register'
	form = RegistrationForm(request.POST)

	if request.method =='POST':
		# Create the user
		if form.is_valid():
			user = form.save()
			user.refresh_from_db() #load profile created by register
			user.save()
			user.refresh_from_db()
			# Get username and password to log in with
			username = form.cleaned_data.get('username')
			raw_password = form.cleaned_data.get('password1')
			# Set the profile birth_date to the one given
			profile = Profile.objects.get(user=user)
			profile.birth_date = form.cleaned_data.get('birth_date')
			profile.save()

			# Redirect to login page
			return redirect('login')
	else:
		# Recreate the form since we aren't posting
		form = RegistrationForm()
		# Send the form to the page and render it
		return render(request, 'registration/register.html', {'form':form})

	# Return the form if the form isn't valid but post was specified
	return render(request, 'registration/register.html', {'form':form})
Ejemplo n.º 7
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    else:
        form = RegistrationForm()
        if form.validate_on_submit():
            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode('UTF-8')
            user = User(
                first_name=form.first_name.data,
                last_name=form.last_name.data,
                email=form.email.data,
                password=hashed_password,
            )
            db.session.add(user)
            db.session.commit()
            flash(f'Your account has been created! You now able to log in',
                  'success')
            return redirect(url_for('login'))
        else:
            return render_template('register.html',
                                   title='Register',
                                   form=form)
Ejemplo n.º 8
0
def register(request):
	if request.method == "POST":
		form = RegistrationForm(request.POST)
		if form.is_valid():
			user = form.save(commit=False)
			user.is_active = False
			user.save()
			current_site = get_current_site(request)
			subject = 'Activate Your MySite Account'
			message = render_to_string('main/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),
			})
			user.email_user(subject, message)
			return redirect('main:account_activation_sent')
	else:
		form = RegistrationForm()
	return render(request = request,
				  template_name = "main/register.html",
				  context={"form":form})
Ejemplo n.º 9
0
 def get(self, request, *args, **kwargs):
     form = RegistrationForm(request.POST)
     films = Seance.objects.all()
     context = {'form': form, 'product': films}
     return render(request, 'registration.html', context)