Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AysKrimn authored Apr 10, 2023
1 parent 64830d0 commit d5a9329
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 0 deletions.
Empty file added userApp/__init__.py
Empty file.
Binary file added userApp/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added userApp/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file added userApp/__pycache__/apps.cpython-38.pyc
Binary file not shown.
Binary file added userApp/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file added userApp/__pycache__/views.cpython-38.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions userApp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions userApp/apps.py
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 added userApp/migrations/__init__.py
Empty file.
Binary file not shown.
3 changes: 3 additions & 0 deletions userApp/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
59 changes: 59 additions & 0 deletions userApp/templates/user-login.html
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 %}
35 changes: 35 additions & 0 deletions userApp/templates/user-register.html
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 %}
3 changes: 3 additions & 0 deletions userApp/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
69 changes: 69 additions & 0 deletions userApp/views.py
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')

0 comments on commit d5a9329

Please sign in to comment.