Ejemplo n.º 1
0
def register(request):  # 20210325
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        print("Errors", form.errors)
        if form.is_valid():
            form.save()
            #
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            first_name = form.cleaned_data.get('first_name')
            last_name = form.cleaned_data.get('last_name')
            email = form.cleaned_data.get('email')

            user = authenticate(username=username,
                                password=raw_password,
                                first_name=first_name,
                                last_name=last_name,
                                email=email)
            login(request, user)
            #
            print('user created!!!')
            messages.success(request, 'Account created successfully')
            return render(request, 'index.html')
        else:
            messages.success(request, 'Account created " NOT " successfully')
            context = {'form': form}
            return render(request, 'registration/signup.html', context)
    else:
        form = RegistrationForm()
        context = {'form': form}
        return render(request, 'registration/signup.html', context)
Ejemplo n.º 2
0
def register(request):
    if request.method == "POST":
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/home')
    else:
        form = RegistrationForm()
        args = {'form': form}
        return render(request, 'home/regis.html', args)
Ejemplo n.º 3
0
def registration(request):
    form = RegistrationForm()
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()

        #messages.success(request, "Registration successfully completed")
        return redirect('/')
    return render(request, 'home/register.html', {"form": form})
Ejemplo n.º 4
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            update_session_auth_hash(request, form.user)
            return redirect('/home')

    form = RegistrationForm()
    args = {'form': form}
    return render(request, 'home/reg_form.html', args)
Ejemplo n.º 5
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect(reverse('home:home'))

    else:
        form = RegistrationForm()

    args = {'form': form}
    return render(request, 'home/reg_form.html', args)
Ejemplo n.º 6
0
def SignUpController(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            emailadd = form.cleaned_data.get('email')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(email = emailadd, password=raw_password)
            login(request, user)
            return redirect('/')
    else:
        form = RegistrationForm()
    return render(request, 'signup/SignUpUI.html', {'form': form})
Ejemplo n.º 7
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('photo')
        else:
            return HttpResponse(u'Форма не валідна')
    else:
        form = RegistrationForm()

        args = {'form': form}
        return render(request, 'accounts/reg_form.html', args)
Ejemplo n.º 8
0
def register_page(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username=form.cleaned_data['username'],
                password=form.cleaned_data['password1'],
                email=form.cleaned_data['email'],
                )
            return HttpResponseRedirect('/accounts/register/success/')
    else:
        form = RegistrationForm()
    return render_to_response('registration/register.html',{'form':form}, context_instance=RequestContext(request))
Ejemplo n.º 9
0
def register(request):
    form = RegistrationForm()
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            new_user = authenticate(
                username=form.cleaned_data['username'],
                password=form.cleaned_data['password1'],
            )
            login(request, new_user)
            return render(request, 'home/register-success.html')
    return render(request, 'home/register.html', {'form': form})
Ejemplo n.º 10
0
def register(request):
    if request.method =='POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            user = authenticate(username=username, password=password)
            login(request, user)
            return redirect(reverse('home:view_profile'))
    else:
        form = RegistrationForm()
    args = {'form': form}
    return render(request, 'home/register.html', args)
Ejemplo n.º 11
0
def register(request):
    #if data is posted (from user submission) perform this
    if request.method == 'POST':
        #form reads user input
        form = RegistrationForm(request.POST)
        #if the form contains valid data perform this
        if form.is_valid():
            #save information and redirect to specified location
            form.save()
            return redirect('/home')
    #if request method is 'get' generate empty form
    else:
        form = RegistrationForm()
        args = {'form': form}
        return render(request, 'personal/register.html', args)
Ejemplo n.º 12
0
def signup_view(request):
    if request.method == 'GET':
        from home.forms import RegistrationForm
        form = RegistrationForm
        args = {'form': form}
        return render(request, 'home/signup.html', args)
    else:
        from home.forms import RegistrationForm
        form = RegistrationForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            user = User.objects.filter(email=email)
            if user.count() == 0:
                saved = form.save(commit=False)
                username = form.cleaned_data['username']
                password = form.cleaned_data['password1']
                saved.email = form.cleaned_data['email'].lower()
                saved.save()
                user = authenticate(username=username, password=password)

                if user is not None:
                    if user.is_active:
                        login(request, user)
                        return redirect('home:home')
            else:
                messages.add_message(request, messages.ERROR,
                                     'email has already been used')
                return render(request, 'home/signup.html', {'form': form})
        else:
            return render(request, 'home/signup.html', {'form': form})
Ejemplo n.º 13
0
 def get(self, request):
     form = RegistrationForm()
     page = get_object_or_404(Page, slug="home")
     return TemplateResponse(request, 'home/index.html', {
         'registration_form': form,
         'page': page
     })
Ejemplo n.º 14
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, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Registration Succesful!')
        return redirect(url_for('login'))

    return render_template('register.html', form=form, title='Register')
Ejemplo n.º 15
0
def signup_view(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)
            mail_subject = 'Activate your Event Manager account.'
            message = render_to_string(
                'home/acc_active_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(
                        user.pk)).decode(),
                    'token': account_activation_token.make_token(user),
                })
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()
            return render(request, 'home/email_confirm.html')
    else:
        form = RegistrationForm()
    return render(request, 'home/signup.html', {'form': form})
Ejemplo n.º 16
0
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('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)
Ejemplo n.º 17
0
 def post(self, request):
     form = RegistrationForm(request.POST)
     if form.is_valid():
         result = self.validateRecaptcha(
             request.POST.get('g-recaptcha-response'))
         if result['success']:
             participant = form.save(request)
             return HttpResponseRedirect('/thank-you')
         else:
             messages.error(request, 'Invalid reCAPTCHA. Please try again.')
             return TemplateResponse(request, 'home/index.html', {
                 'registration_form': form,
                 'invalid': True
             })
     else:
         return TemplateResponse(request, 'home/index.html', {
             'registration_form': form,
             'invalid': True
         })
Ejemplo n.º 18
0
    def register_view(self):
        form = RegistrationForm(request.form)
        if admin_helpers.validate_form_on_submit(form):
            adminuser = AdminUser()

            form.populate_obj(adminuser)

            adminuser.password = generate_password_hash(form.password.data)

            db.session.add(adminuser)

            try:
                db.session.commit()
            except:
                db.session.rollback()

            login.login_user(adminuser)
            return redirect(url_for('.index'))
        return self.render("admin/register.html", form=form)