diff --git a/templates/_includes/manager/withdrawal.html b/templates/_includes/manager/withdrawal.html
new file mode 100644
index 0000000..d180fbd
--- /dev/null
+++ b/templates/_includes/manager/withdrawal.html
@@ -0,0 +1,6 @@
+정말로 탈퇴하시겠습니까?
+
+
+
diff --git a/templates/manager.html b/templates/manager.html
index b5ef124..706427f 100644
--- a/templates/manager.html
+++ b/templates/manager.html
@@ -55,9 +55,19 @@
+ {% if manager__right_html_for_menu == "_includes/manager/withdrawal.html" %}
+
+ {% else %}
+
+ {% endif %}
+
+ 회원탈퇴
+
+
+
- 버그 신고
+ 버그신고
diff --git a/user.py b/user.py
index e076789..45e4b1a 100644
--- a/user.py
+++ b/user.py
@@ -1,18 +1,26 @@
from datetime import datetime
from flask import (
+ current_app,
render_template,
- session,
request,
redirect,
+ session,
)
from flask.ext.bcrypt import Bcrypt
from db import (
db,
User,
+ URL,
+ Photo,
+ Nickname,
+ NickRecom,
N,
)
+
+import os
+
from url import addURL
@@ -26,6 +34,8 @@ def add_routes(app):
app.route('/logout/')(logout)
app.route('/api/check_pwd/', methods=["POST"])(check_password)
app.route('/manage/password/', methods=["GET", "POST"])(change_password)
+ app.route('//manage/withdraw/')(withdraw_manager)
+ app.route('/api/user/delete/', methods=["POST"])(delete_user)
def register():
@@ -219,3 +229,68 @@ def change_password():
db.session.commit()
return redirect('/%s/' % username)
+
+
+def withdraw_manager(logged_in_user):
+ """ issue #44 회원탈퇴 """
+
+ username = get_logged_in_username()
+
+ if logged_in_user != username:
+ return '누가 당신을 싫어하나봐요 ^^', 400
+
+ return render_template(
+ "manager.html",
+ manager__right_html_for_menu="_includes/manager/withdrawal.html",
+ currently_logged_in_user=username,
+ )
+
+def delete_user():
+
+ username = get_logged_in_username()
+
+ # User DB 삭제
+ found = User.query.filter(
+ User.username == username,
+ ).first()
+ db.session.delete(found)
+
+ # URL DB 삭제
+ found = URL.query.filter(
+ URL.username == username,
+ ).all()
+ for url in found:
+ db.session.delete(url)
+
+ # Photo DB 삭제
+ found = Photo.query.filter(
+ Photo.username == username,
+ ).first()
+ if found:
+ db.session.delete(found)
+ os.remove(os.path.join(
+ current_app.config['UPLOAD_FOLDER'],
+ found.photo,
+ )
+ )
+
+ # NickRecom DB 삭제
+ found = NickRecom.query.filter(
+ NickRecom.username == username,
+ ).all()
+ for nickrecomm in found:
+ db.session.delete(nickrecomm)
+
+ # Nickname DB 삭제
+ found = Nickname.query.filter(
+ Nickname.username == username,
+ ).all()
+ for nickname in found:
+ db.session.delete(nickname)
+
+ # DB commit
+ db.session.commit()
+
+ # Logout
+ session.pop('username', None)
+ return redirect('/')