Ubuntu

login,logout bugfixed

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{% endblock%}</title>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
\ No newline at end of file
<h1>
hi!
</h1>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>KHUropBox</title>
<script src="/static/js/app.js"></script>
<script src="/static/js/aws-sdk.min.js"></script>
<link href="/static/css/app.css" rel="stylesheet">
<link href="/static/css/common.css" rel="stylesheet">
<link href="/static/css/override.css" rel="stylesheet">
<link href="/static/css/layout.css" rel="stylesheet">
<link href="/static/css/filebrowser.css" rel="stylesheet">
<link href="/static/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<div id="wrapper">
<div id="page-content-wrapper">
<div id="header">
<div id="logo">
<a href="/"></a>
</div>
</div>
<div id="content">
{% block content %}
{% endblock %}
</div>
</div>
</div>
</body>
\ No newline at end of file
{% extends 'layout.html' %}
{% block content %}
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">로그인</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="/login/">
{% csrf_token %}
<div class="form-group">
<div class="col-md-12">
<label for="userid">아이디</label>
<input id="userid" type="userid" class="form-control" name="username" required autofocus>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="password">비밀번호</label>
<input id="password" type="password" class="form-control" name="password" required>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<button type="submit" class="btn btn-success">
로그인
</button>
<button class="btn btn-success" onclick="location.href='/register/';">
회원가입
</button>
</div>
</div>
<div class="form-group">
<div class="col-md-12 text-center">
<h5>{{ message }}</h5>
</div>
</div>
</form>
</div>
</div>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'layout.html' %}
{% block content %}
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
{{ request.user.username }} 님 안녕하세요.
<button type="submit" class="btn right" onclick="location.href='/logout/';">로그아웃</button>
</div>
</div>
</div>
{% endblock %}
{% extends 'layout.html' %}
{% block content %}
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="/register/">
{% csrf_token %}
<div class="form-group">
<div class="col-md-12">
<label for="username"><span style="color:green;">아이디</span></label>
<input id="username" type="text" class="form-control" name="username" required autofocus>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="email"><span style="color:green;">이메일</span><h6 style="display:inline;"> - 비밀번호 분실시 사용됩니다.</h6></label>
<input id="email" type="email" class="form-control" name="email" required>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="password"><span style="color:green;">비밀번호</span><h6 style="display:inline;"> - 비밀번호는 8자리 이상으로 설정되어야 합니다.</h6></label>
<input id="password" type="password" class="form-control" name="password" required>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="first_name"><span style="color:green;"></span></label>
<input id="first_name" type="first_name" class="form-control" name="first_name" required>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="last_name"><span style="color:green;">이름</span></label>
<input id="last_name" type="last_name" class="form-control" name="last_name" required>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<button type="submit" class="btn btn-success">회원가입</button>
</div>
</div>
<div class="form-group">
<div class="col-md-12 text-center">
<h6>{{ message }}</h6>
</div>
</div>
</form>
</div>
</div>
</div>
{% endblock %}
from django.contrib.auth.models import User
from django.contrib.auth import authenticate
from django.shortcuts import render, redirect
from django.core.exceptions import PermissionDenied
from khuloud import settings
from khuloud import cognito
from django.views.decorators.csrf import csrf_exempt
import hashlib
import django
def main(request):
if request.user.is_authenticated:
return render(request, "main.html")
else:
return render(request, "login.html")
def login(request):
if request.method == "POST":
if not all(i in request.POST for i in ('username', 'password')):
return render(request, "login.html", {
"message": "please enter id and passowrd"
})
un = request.POST['username']
pw = request.POST['password']
user = authenticate(username=un, password=pw)
if user is not None:
auth = django.contrib.auth.login(request, user)
hashcode = hashlib.md5(request.POST['password'].encode('utf-8')).hexdigest()
cog = cognito.Cognito()
cog.sign_in_admin(username=un, password=hashcode)
return redirect('/main')
else:
return render(request, "login.html", {
"message": "check id and password"
})
else:
return render(request, "login.html")
def logout(request):
if request.user.is_authenticated:
django.contrib.auth.logout(request)
return redirect("/main")
def register(request):
Cog = cognito.Cognito()
if request.method == "POST":
require_keys = ('username', 'password', 'first_name', 'last_name', 'email')
if all(i in request.POST for i in require_keys):
if User.objects.filter(username=request.POST['username']).count():
return render(request, 'register.html', {
"message": 'alreay exist id!'
})
if User.objects.filter(email=request.POST['email']).count():
return render(request, 'register.html', {
"message": 'already exist email'
})
userobj = User.objects.create_user(
username=request.POST['username'],
password=request.POST['password'],
first_name=request.POST['first_name'],
last_name=request.POST['last_name'],
email=request.POST['email']
)
hashcode = hashlib.md5(request.POST['password'].encode('utf-8')).hexdigest()
Cog.sign_up(
username=request.POST['username'],
password=hashcode,
UserAttributes=[
{
'Name' : 'email',
'Value' : request.POST['email'],
},
{
'Name' : 'family_name',
'Value': request.POST['first_name'],
},
{
'Name' : 'given_name',
'Value': request.POST['last_name'],
},
])
Cog.confirm_sign_up(username=request.POST['username']);
return redirect('/main')
else:
return render(request, 'register.html', {
"message": 'erroe!'
})
else:
return render(request, 'register.html')
"""khuloud URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
import blog.views
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls import include, url
urlpatterns = [
url(r'^admin/', admin.site.urls),
url('main/',blog.views.main, name='main'),
url(r'^login/', blog.views.login, name='login'),
url(r'^logout/', blog.views.logout, name='logout'),
url(r'^register/', blog.views.register, name='register'),
]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
File mode changed