Skip to content

Commit

Permalink
add resend verify email and notify login function
Browse files Browse the repository at this point in the history
  • Loading branch information
hustlzp committed Feb 28, 2013
1 parent eb2ee2e commit b4c20dd
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
11 changes: 7 additions & 4 deletions xichuangzhu/controllers/love.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@

@app.route('/mylove')
def my_love():
works = Love.get_works_by_user_love(session['user_id'])
for work in works:
work['Content'] = re.sub(r'<([^<]+)>', '', work['Content'])
return render_template('my_love.html', works=works)
if not 'user_id' in session:
return render_template('my_love.html', is_login=False)
else:
works = Love.get_works_by_user_love(session['user_id'])
for work in works:
work['Content'] = re.sub(r'<([^<]+)>', '', work['Content'])
return render_template('my_love.html', works=works)

# # proc - add love work
# #--------------------------------------------------
Expand Down
Binary file modified xichuangzhu/controllers/love.pyc
Binary file not shown.
10 changes: 4 additions & 6 deletions xichuangzhu/controllers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ def auth():
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
info = eval(response.read())

user_id = int(info['douban_user_id'])
access_token = info['access_token']

# if user exist
if User.check_user_exist(user_id):
# if user unactive
if not User.check_user_active(user_id):
return redirect(url_for('verify_email_callback', state='unactive'))
return redirect(url_for('verify_email_callback', state='unactive', user_id=user_id))
else:
# set session
session['user_id'] = user_id
Expand All @@ -52,9 +50,8 @@ def auth():
# if not exist
else:
# get user info
url = "https://api.douban.com/v2/user/~me"
url = "https://api.douban.com/v2/user/" + str(user_id)
req = urllib2.Request(url)
req.add_header('Authorization', 'Bearer ' + access_token)
response = urllib2.urlopen(req)
user_info = eval(response.read().replace('\\', '')) # remove '\' and convert str to dict

Expand Down Expand Up @@ -126,7 +123,8 @@ def verify_email(user_id, verify_code):
@app.route('/verify_email_callback/douban/')
def verify_email_callback():
state = request.args['state']
return render_template('verify_email_callback.html', state=state)
user_id = int(request.args['user_id']) if 'user_id' in request.args else 0
return render_template('verify_email_callback.html', state=state, user_id=user_id)

# proc - logout
@app.route('/logout')
Expand Down
Binary file modified xichuangzhu/controllers/user.pyc
Binary file not shown.
2 changes: 0 additions & 2 deletions xichuangzhu/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

<ul class="nav">
<li><a href="{{ url_for('index') }}">首页</a></li>
{% if session.user_id %}
<li><a href="{{ url_for('my_love') }}">收藏</a></li>
{% endif %}
<!-- <li><a href="#">论坛</a></li> -->
<li><a href="{{ url_for('shop') }}"></a></li>
</ul>
Expand Down
10 changes: 10 additions & 0 deletions xichuangzhu/templates/my_love.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

<div class="row">
<div class="span8">

{% if is_login == False %}

<h2>提示</h2>
<div>只有登陆用户才能收藏哦,请点击豆瓣图标登陆吧!</div>

{% else %}

<h2>我的收藏</h2>

{% for work in works %}
Expand All @@ -19,6 +27,8 @@ <h2>我的收藏</h2>
</div>
{% endfor %}

{% endif %}

</div>

<div class="span4"></div>
Expand Down
4 changes: 3 additions & 1 deletion xichuangzhu/templates/verify_email_callback.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

{% block body %}

<h2>提示</h2>

{% if state == 'send_succ' %}
<div>邮件已发送,请进入邮箱完成绑定。</div>

{% elif state == 'send_failed' %}
<div>邮件发送失败。</div>

{% elif state == 'unactive' %}
<div>您尚未绑定邮箱,请进入邮箱完成绑定。</div>
<div>您尚未绑定邮箱,请进入邮箱完成绑定(或 <a href="{{ url_for('send_verify_email', user_id=user_id) }}">再发一次</a></div>

{% elif state == 'active_succ' %}
<div>邮箱绑定成功!<span id="second-count"></span>秒后进入首页。</div>
Expand Down

0 comments on commit b4c20dd

Please sign in to comment.