diff options
author | Alvin Li <liweitianux@gmail.com> | 2013-10-04 23:56:35 +0800 |
---|---|---|
committer | Alvin Li <liweitianux@gmail.com> | 2013-10-04 23:56:35 +0800 |
commit | f552b41f4b337e6844f71c29ff177915abbfa417 (patch) | |
tree | 7ade59430c6767a5b379c7a8cb95af3387622b13 /97suifangqa/apps/sfaccount/views.py | |
parent | 816730ff659e1338ab3e37a1d45ea337e337b3dd (diff) | |
download | 97dev-f552b41f4b337e6844f71c29ff177915abbfa417.tar.bz2 |
* indicator/static/javascripts/card_chart.js:
improved the display position of 'detail_card_info'
* indicator/templates/indicator/SheetDefault.html:
destroy 'qtip' when close card
* added new app 'apps/sfaccount'
* implemented 'signup' and 'activate' functions
* implemented async sending activation mail
(using 'django-celery' and 'redis')
* moved 'registration/*' templates to 'sfaccount/templates'
* implemented 'password_change' function:
o password_change
o password_change_done
* implemented 'password_reset' function
o password_reset
o password_reset_done
o password_reset_confirm
o password_reset_complete
o re-write 'sfaccount.fomrs.SFPasswordResetForm'
o re-write 'sfaccount.views.password_reset_view'
* improved 'sfaccount.functional' send mail functions
o to send 'multipart' mail
* added 'README.txt'
* added app 'apps/recommend':
for comparing with the SCI papers and then recommending
most related papers for user.
Diffstat (limited to '97suifangqa/apps/sfaccount/views.py')
-rw-r--r-- | 97suifangqa/apps/sfaccount/views.py | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/97suifangqa/apps/sfaccount/views.py b/97suifangqa/apps/sfaccount/views.py new file mode 100644 index 0000000..94670a6 --- /dev/null +++ b/97suifangqa/apps/sfaccount/views.py @@ -0,0 +1,143 @@ +# -*- coding: utf-8 -*- + +from django.conf import settings +from django.http import HttpResponse, HttpResponseRedirect +from django.template.response import TemplateResponse +from django.core.urlresolvers import reverse +from django.views.decorators.csrf import csrf_protect +from django.utils.translation import ugettext as _ +from django.shortcuts import render, redirect + +from django.contrib.auth.tokens import default_token_generator + +from sfaccount.models import Account +from sfaccount.forms import AccountForm, SFPasswordResetForm + +# email address shown in the sent mail +FROM_EMAIL = getattr(settings, 'SF_EMAIL').get('display_from') + + +# go_home {{{ +def go_home_view(request): + """ + go to home page (profile) + """ + if request.user.is_authenticated(): + username = request.user.username + return redirect(reverse('profile_home', + kwargs={'username': username})) + else: + # not logged in + return redirect(reverse('login')) +# }}} + + +# signup {{{ +def signup_view(request): + """ + 用户注册 + """ + if request.user.is_authenticated(): + return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL) + + if request.method == 'POST': + form = AccountForm(data=request.POST) + if form.is_valid(): + cd = form.cleaned_data + new_account = Account.objects.create_inactive_account( + username=cd['username'], + email=cd['email'], + password=cd['password1'], + send_email=True + ) + return HttpResponseRedirect(request.REQUEST.get('next')) + else: + form = AccountForm() + + data = { + 'form': form, + } + return render(request, 'sfaccount/signup.html', data) +# }}} + + +# activate {{{ +def activate_view(request, activation_key=None): + """ + activate account + + if activation_key=None, then render a page ask user + to provide the activation key; + otherwise, directly activate the account and redirect + """ + if activation_key: + account = Account.objects.activate(activation_key) + if account: + # activated + home_url = '/profile/%s/' % account.user.username + return HttpResponseRedirect(home_url) + else: + # activate failed + data = {'activate_failed': True} + return render(request, 'sfaccount/activate.html', data) + else: + # ask user for the 'activation_key' + return render(request, 'sfaccount/activate.html') +# }}} + + +# password_reset_view {{{ +# own password_reset_view: enable to send multipart email +@csrf_protect +def password_reset_view(request, is_admin_site=False, + template_name='sfaccount/password_reset.html', + email_template_name='sfaccount/password_reset_email.txt', + subject_template_name='sfaccount/password_reset_subject.txt', + password_reset_form=SFPasswordResetForm, + token_generator=default_token_generator, + post_reset_redirect=None, + from_email=FROM_EMAIL, + current_app=None, + extra_context=None, + html_email_template_name='sfaccount/password_reset_email.html'): + """ + re-write view to replace django's one + able to send multipart email by using + own 'SFPasswordResetForm' and 'send_mail' + """ + if post_reset_redirect is None: + post_reset_redirect = reverse('password_reset_done') + if request.method == "POST": + form = password_reset_form(request.POST) + if form.is_valid(): + opts = { + 'use_https': request.is_secure(), + 'token_generator': token_generator, + 'from_email': from_email, + 'email_template_name': email_template_name, + 'subject_template_name': subject_template_name, + 'request': request, + 'html_email_template_name': html_email_template_name, + } + if is_admin_site: + opts = dict(opts, domain_override=request.get_host()) + form.save(**opts) + return HttpResponseRedirect(post_reset_redirect) + else: + form = password_reset_form() + context = { + 'form': form, + 'title': _('Password reset'), + } + if extra_context is not None: + context.update(extra_context) + return TemplateResponse(request, template_name, context, + current_app=current_app) +# }}} + + +# social_login_callback {{{ +def social_login_callback(request, sitename): + return HttpResponse('%s' % sitename) +# }}} + |