-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class UserappConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'userApp' |
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block siteBaslik %} Giriş Yap {% endblock siteBaslik %} | ||
|
||
{% block site-icerigi %} | ||
|
||
<div class="container mt-5"> | ||
|
||
<div class="form-area"> | ||
|
||
<h3>Giriş Yap</h3> | ||
<hr> | ||
|
||
<form action=" {% url 'user-login' %}" method="post"> | ||
|
||
{% csrf_token %} | ||
|
||
{% for message in messages %} | ||
|
||
{% if message.tag == success %} | ||
|
||
<p id="successMsg" style="color: green;"> {{message}} </p> | ||
|
||
{% else %} | ||
|
||
<p style="color: red;"> {{message}} </p> | ||
|
||
{% endif %} | ||
|
||
|
||
{% endfor %} | ||
<input type="text" class="form-control" placeholder="Kullanıcı Adı" name="k_ad"> | ||
<input type="password" class="form-control" placeholder="Şifre" name="k_sifre"> | ||
|
||
<span>Henüz hesabınız yok mu? <a href="{% url 'user-register' %}">buradan kayıt olabilirsiniz</a> </span> | ||
|
||
<div class="mt-3"> | ||
<button class="btn btn-success">Giriş Yap</button> | ||
</div> | ||
|
||
</form> | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
<script> | ||
|
||
const p = document.getElementById('successMsg') | ||
|
||
if(p) { | ||
|
||
setTimeout(() => { | ||
p.remove(); | ||
}, 5000); | ||
} | ||
|
||
</script> | ||
{% endblock site-icerigi %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block siteBaslik %} Kayıt Ol {% endblock siteBaslik %} | ||
{% block site-icerigi %} | ||
|
||
<div class="container mt-5"> | ||
|
||
<div class="form-area"> | ||
|
||
<h3>Kayıt Ol</h3> | ||
<hr> | ||
|
||
<form action="{% url 'user-register' %}" method="post"> | ||
{% csrf_token %} | ||
|
||
{% for message in messages %} | ||
<p style="color: red;"> {{message}} </p> | ||
{% endfor %} | ||
|
||
<input type="text" class="form-control" placeholder="Kullanıcı Adı" name="k_ad"> | ||
<input type="email" class="form-control" placeholder="E-mail Adresi" name="k_email"> | ||
<input type="password" class="form-control" placeholder="Şifre" name="k_sifre"> | ||
|
||
<span>Zaten bir hesabın var mı? <a href="{% url 'user-login' %}">buradan giriş yapabilirsin</a> </span> | ||
|
||
<div class="mt-3"> | ||
<button class="btn btn-success">Kayıt Ol</button> | ||
</div> | ||
|
||
</form> | ||
|
||
</div> | ||
|
||
</div> | ||
{% endblock site-icerigi %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from django.shortcuts import render, redirect | ||
from django.contrib.auth.models import User | ||
from django.contrib.auth import authenticate, login, logout | ||
from django.contrib import messages | ||
|
||
# Create your views here. | ||
# user kayıt olursa | ||
def user_register(request): | ||
|
||
if request.method == 'POST': | ||
# verileri çek | ||
# veritabanına işle | ||
k_ad = request.POST.get('k_ad') | ||
k_email = request.POST.get('k_email') | ||
k_sifre = request.POST.get('k_sifre') | ||
|
||
if k_ad and k_email and k_sifre: | ||
# sorgulama işlemleri | ||
try: | ||
User.objects.get(email=k_email) | ||
# hata mesajı verdir | ||
messages.error(request, message="Bu email adresine sahip bir kullanıcı zaten mevcut") | ||
return redirect('user-register') | ||
except User.DoesNotExist: | ||
# böyle bir kullanıcı yoktur kayıt et | ||
User.objects.create_user(username=k_ad, email=k_email, password=k_sifre) | ||
messages.success(request, 'Başarılı bir şekilde kayıt oldunuz. Lütfen giriş yapın.') | ||
# gir yapmaya yönlendir | ||
return redirect('user-login') | ||
|
||
|
||
else: | ||
return render(request, 'user-register.html') | ||
|
||
|
||
|
||
# user giriş yapmaya çalışırsa | ||
def user_login(request): | ||
|
||
if request.method == 'POST': | ||
k_ad = request.POST.get('k_ad') | ||
k_sifre = request.POST.get('k_sifre') | ||
|
||
if k_ad and k_sifre: | ||
user = authenticate(request, username=k_ad, password=k_sifre) | ||
|
||
if user is not None: | ||
# giriş yaptır | ||
login(request, user) | ||
return redirect('anasayfa') | ||
else: | ||
messages.error(request, 'Kullanıcı adı veya parola hatalı') | ||
return redirect('user-login') | ||
else: | ||
# eğer kullanıcı zaten login olmuşsa | ||
if request.user.is_authenticated: | ||
return redirect('anasayfa') | ||
else: | ||
return render(request, 'user-login.html') | ||
|
||
|
||
# user çıkış yaparsa | ||
def user_logout(request): | ||
# giriş yapmayan kullanıcıları engelle | ||
if request.user.is_authenticated: | ||
logout(request) | ||
return redirect('anasayfa') | ||
else: | ||
return redirect('anasayfa') |