Ejemplo n.º 1
0
def login(request, template="login.html"):
    if request.method == "POST":
        if request.POST["type"] == "register":
            register_form = RegisterationForm(request.POST)
            login_form = AuthenticationForm()
            if register_form.is_valid():
                user = register_form.save(commit=False)
                user.email = register_form.cleaned_data.get("email")
                user.save()
                profile = Profile.objects.create(user=user)
                send_mail_with_template(u"Selamlar efendim!", user.email, "mails/wellcome.html", {"user": user})
                send_mail_with_template(u"Yeni üye kaydı!", settings.MY_MAIL, "mails/wellcome.html", {"user": user})
                user.backend = "django.contrib.auth.backends.ModelBackend"
                login_func(request, user)
                return redirect("home")
        else:
            login_form = AuthenticationForm(data=request.POST)
            register_form = RegisterationForm()
            if login_form.is_valid():
                login_func(request, login_form.get_user())
                return redirect("home")
    else:
        register_form = RegisterationForm()
        login_form = AuthenticationForm()

    ctx = {"register_form": register_form, "login_form": login_form}

    return render(request, template, ctx)
Ejemplo n.º 2
0
def contact(request, template="contact.html"):
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            contact = form.save()
            send_mail_with_template(
                u"Yeni iletişim maili", settings.MY_MAIL, "mails/newmessage.html", {"contact": contact}
            )
            messages.add_message(request, messages.SUCCESS, u"Tamamdır")
            return redirect("contact")
    else:
        form = ContactForm()
    ctx = {"form": form}
    return render(request, template, ctx)
Ejemplo n.º 3
0
def create_post(request, template="create_post.html"):
    if request.method == "POST":
        form = ArticleForm(data=request.POST, files=request.FILES)
        if form.is_valid():
            post = form.save(commit=False)
            post.user = request.user
            post.date = date.today()
            post.is_active = False
            post.save()
            send_mail_with_template(
                u"Yeni yazı var", settings.MY_MAIL, "mails/newpost.html", {"post": post, "user": request.user}
            )
            return redirect("detail", post.slug)
    else:
        form = ArticleForm()
    return render(request, template, {"form": form})
Ejemplo n.º 4
0
 def save_model(self, request, obj, form, change):
     if change and request.user != obj.user and obj.is_active:
         send_mail_with_template(u"Yazın onaylandı!", obj.user.email, "mails/post-accepted.html", {"post": obj})
     super(PostAdmin, self).save_model(request, obj, form, change)