Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #89 from minhoryang/issue_44_withdrawal_really
Browse files Browse the repository at this point in the history
Issue 44 withdrawal really
  • Loading branch information
JimJeon committed Mar 6, 2016
2 parents 2df4124 + 944d020 commit 1f6de9b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
6 changes: 6 additions & 0 deletions templates/_includes/manager/withdrawal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
정말로 탈퇴하시겠습니까?<p>
<div>
<form method="POST" action="/api/user/delete/">
<input type="submit" value="탈퇴"/>
</form>
</div>
12 changes: 11 additions & 1 deletion templates/manager.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,19 @@
</li>
</a>

{% if manager__right_html_for_menu == "_includes/manager/withdrawal.html" %}
<a class="nav-link active" href="/{{ get_logged_in_username }}/manage/withdraw/">
{% else %}
<a class="nav-link" href="/{{get_logged_in_username}}/manage/withdraw/">
{% endif %}
<li class="nav-item">
회원탈퇴
</li>
</a>

<a class="nav-link" target="_blank" href="https://github.com/minhoryang/AwesomeTitle/issues">
<li class="nav-item">
버그 신고
버그신고
</li>
</a>

Expand Down
77 changes: 76 additions & 1 deletion user.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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('/<logged_in_user>/manage/withdraw/')(withdraw_manager)
app.route('/api/user/delete/', methods=["POST"])(delete_user)


def register():
Expand Down Expand Up @@ -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('/')

0 comments on commit 1f6de9b

Please sign in to comment.