Beispiel #1
0
def register(request):
    if request.method == 'POST':
        form = forms.RegisterForm(request.POST)
        if form.is_valid():
            user = User.objects.get(id=request.user.id)
            user.userprofile.real_first_name = form.cleaned_data.get(
                'real_first_name')
            user.userprofile.real_last_name = form.cleaned_data.get(
                'real_last_name')
            user.userprofile.phone_number = form.cleaned_data.get(
                'phone_number')
            user.userprofile.email = form.cleaned_data.get('email')
            user.save()
            user.userprofile.save()
            current_site = get_current_site(request)
            mail_subject = 'Activate your account.'
            message = render_to_string(
                'accounts/acc_active_email.html', {
                    'user': user.userprofile,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    '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 HttpResponse(
                'Please confirm your email address to complete the registration'
            )
    else:
        form = RegisterForm()
    return render(request, 'accounts/register.html', {'form': form})
Beispiel #2
0
def register(request):
    if request.method == "POST":
        form = forms.RegisterForm(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:
            return render(
                request,
                "registration/signup.html",
                {
                    "form": form,
                    "errors": form.errors
                },
            )
    else:
        form = forms.RegisterForm()
    return render(request, "registration/signup.html", {"form": form})
Beispiel #3
0
    def post(self, request):
        form = forms.RegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']

            user = User.objects.create_superuser(username, email, password)

            # Create admin group
            group = create_admin_group()

            # Create editor group
            group = create_editor_group()

            # Create writer group
            group = create_writer_group()

            # Create contributor group
            group = create_contributor_group()

            # Create reader group
            group = create_reader_group()

            # Create default category
            default_category, created = models.Category.objects.get_or_create(
                name='default')

            initialization, created = models.BlogMeta.objects.get_or_create(
                key='initialization')
            initialization.flag = True
            initialization.save()

            # Blog meta data
            # obj, created = models.BlogMeta.objects.get_or_create(key='blog_name', defaults={'value':'MayBlog'})
            # obj, created = models.BlogMeta.objects.get_or_create(key='blog_subtitle', defaults={'value':'Welcome to MayBlog'})
            # obj, created = models.BlogMeta.objects.get_or_create(key='blog_desc', defaults={'value':'desc'})
            # obj, created = models.BlogMeta.objects.get_or_create(key='owner', defaults={'value':'MayBlog'})
            # obj, created = models.BlogMeta.objects.get_or_create(key='keywords', defaults={'value':'MayBlog'})
            # obj, created = models.BlogMeta.objects.get_or_create(key='google_verify', defaults={'value':''})
            # obj, created = models.BlogMeta.objects.get_or_create(key='baidu_verify', defaults={'value':''})
            init_blog_meta()

            msg = 'Successfully Initialized'
            messages.add_message(request, messages.SUCCESS, msg)
            url = reverse('main:admin_index')
            return redirect(url)

        else:
            return self.get(request, form)
Beispiel #4
0
    def post(self, request):
        form = forms.RegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']

            user = User.objects.create_superuser(username, email, password)

            # Create admin group
            group = create_admin_group()

            # Create editor group
            group = create_editor_group()

            # Create writer group
            group = create_writer_group()

            # Create contributor group
            group = create_contributor_group()

            # Create reader group
            group = create_reader_group()

            initialization, created = models.BlogMeta.objects.get_or_create(
                key='initialization')
            initialization.flag = True
            initialization.save()

            obj = models.BlogMeta()
            obj.key = 'blog_name'
            obj.value = 'MayBlog'
            obj.save()

            obj = models.BlogMeta()
            obj.key = 'blog_subtitle'
            obj.value = 'Welcome to MayBlog'
            obj.save()

            msg = 'Successfully Initialized'
            messages.add_message(request, messages.SUCCESS, msg)
            url = reverse('main:admin_index')
            return redirect(url)

        else:
            return self.get(request, form)
Beispiel #5
0
    def get(self, request, form=None):
        initialized = False

        try:
            initialization = models.BlogMeta.objects.get(key='initialization')
            initialized = initialization.flag
        except models.BlogMeta.DoesNotExist:
            initialized = False

        if initialized:
            url = reverse('main:admin_index')
            return redirect(url)

        if not form:
            form = forms.RegisterForm()
        data = {'form': form}
        data['title'] = 'System Initialization'
        data['heading'] = 'Create Superuser'
        return render(request, self.template_name, data)