+3
-2
@@ -19,8 +19,9 @@ from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^oauth/authorize$', views.authorize),
|
||||
url(r'^oauth/requireemail/(?P<oauthid>\d+)', views.RequireEmailView.as_view(), name='require_email'),
|
||||
url(r'^oauth/emailconfirm/(?P<id>\d+)/(?P<sign>\S+)', views.emailconfirm, name='email_confirm'),
|
||||
url(r'^oauth/requireemail/(?P<oauthid>\d+).html', views.RequireEmailView.as_view(), name='require_email'),
|
||||
url(r'^oauth/emailconfirm/(?P<id>\d+)/(?P<sign>\S+).html', views.emailconfirm, name='email_confirm'),
|
||||
url(r'^oauth/bindsuccess/(?P<oauthid>\d+).html', views.bindsuccess, name='bindsuccess'),
|
||||
]
|
||||
|
||||
"""
|
||||
|
||||
+34
-4
@@ -34,7 +34,10 @@ def authorize(request):
|
||||
|
||||
if user:
|
||||
try:
|
||||
token = user.token
|
||||
user = OAuthUser.objects.get(type=type, openid=user.openid)
|
||||
if token:
|
||||
user.token = token
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
email = user.email
|
||||
@@ -50,7 +53,7 @@ def authorize(request):
|
||||
if result[1]:
|
||||
author.username = user.nikename + '_' + str(user.openid)
|
||||
author.save()
|
||||
|
||||
|
||||
user.author = author
|
||||
user.save()
|
||||
login(request, author)
|
||||
@@ -67,6 +70,8 @@ def authorize(request):
|
||||
})
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
else:
|
||||
return HttpResponseRedirect('/')
|
||||
|
||||
|
||||
def emailconfirm(request, id, sign):
|
||||
@@ -104,8 +109,11 @@ def emailconfirm(request, id, sign):
|
||||
如果上面链接无法打开,请将此链接复制至浏览器。
|
||||
{url}
|
||||
'''.format(type=oauthuser.type, url='http://' + site), [oauthuser.email, ])
|
||||
|
||||
return HttpResponseRedirect('/')
|
||||
url = reverse('oauth:bindsuccess', kwargs={
|
||||
'oauthid': id
|
||||
})
|
||||
url = url + '?type=success'
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
class RequireEmailView(FormView):
|
||||
@@ -162,4 +170,26 @@ class RequireEmailView(FormView):
|
||||
{url}
|
||||
""".format(url=url)
|
||||
send_email('绑定您的电子邮箱', content, [email, ])
|
||||
return HttpResponseRedirect('/')
|
||||
url = reverse('oauth:bindsuccess', kwargs={
|
||||
'oauthid': oauthid
|
||||
})
|
||||
url = url + '?type=email'
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
def bindsuccess(request, oauthid):
|
||||
type = request.GET.get('type', None)
|
||||
|
||||
title = ''
|
||||
content = ''
|
||||
oauthuser = get_object_or_404(OAuthUser, pk=oauthid)
|
||||
if type == 'email':
|
||||
title = '绑定成功'
|
||||
content = "恭喜您,还差一步就绑定成功了,请登录您的邮箱查看邮件完成绑定,谢谢。"
|
||||
else:
|
||||
title = '绑定成功'
|
||||
content = "恭喜您绑定成功,您以后可以使用{type}来直接免密码登录本站啦,感谢您对本站对关注。".format(type=oauthuser.type)
|
||||
return render(request, 'oauth/bindsuccess.html', {
|
||||
'title': title,
|
||||
'content': content
|
||||
})
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
{% extends 'share_layout/base.html' %}
|
||||
{% block header %}
|
||||
<title> {{ title }}</title>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<div id="primary" class="site-content">
|
||||
<div id="content" role="main">
|
||||
|
||||
<header class="archive-header">
|
||||
|
||||
<h2 class="archive-title"> {{ content }}</h2>
|
||||
</header><!-- .archive-header -->
|
||||
<br/>
|
||||
<header class="archive-header" style="text-align: center">
|
||||
|
||||
<a href="{% url "account:login" %}">Sign In</a>
|
||||
|
|
||||
<a href="/">Home Page</a>
|
||||
</header><!-- .archive-header -->
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user