<s> from django . shortcuts import render_to_response <EOL> from django . http import HttpResponseRedirect <EOL> from django . contrib . auth import authenticate <EOL> from django . contrib . auth import login as auth_login <EOL> from django . template import RequestContext <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . core . urlresolvers import reverse <EOL> from django . contrib . auth . decorators import login_required <EOL> from forms import SignupForm , AddEmailForm , LoginForm , ChangePasswordForm , ResetPasswordForm , ChangeTimezoneForm , ChangeLanguageForm , TwitterForm , PownceForm <EOL> from emailconfirmation . models import EmailAddress , EmailConfirmation <EOL> def login ( request , form_class = LoginForm , template_name = "<STR_LIT>" ) : <EOL> redirect_to = request . REQUEST . get ( "<STR_LIT>" , reverse ( "<STR_LIT>" ) ) <EOL> if request . method == "<STR_LIT:POST>" : <EOL> form = form_class ( request . POST ) <EOL> if form . login ( request ) : <EOL> return HttpResponseRedirect ( redirect_to ) <EOL> else : <EOL> form = form_class ( ) <EOL> return render_to_response ( template_name , { <EOL> "<STR_LIT>" : form , <EOL> } , context_instance = RequestContext ( request ) ) <EOL> def signup ( request , form_class = SignupForm , <EOL> template_name = "<STR_LIT>" , success_url = None ) : <EOL> if success_url is None : <EOL> success_url = reverse ( "<STR_LIT>" ) <EOL> if request . method == "<STR_LIT:POST>" : <EOL> form = form_class ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> username , password = form . save ( ) <EOL> user = authenticate ( username = username , password = password ) <EOL> auth_login ( request , user ) <EOL> request . user . message_set . create ( message = _ ( "<STR_LIT>" ) % { '<STR_LIT:username>' : user . username } ) <EOL> return HttpResponseRedirect ( success_url ) <EOL> else : <EOL> form = form_class ( ) <EOL> return render_to_response ( template_name , { <EOL> "<STR_LIT>" : form , <EOL> } , context_instance = RequestContext ( request ) ) <EOL> def email ( request , form_class = AddEmailForm , <EOL> template_name = "<STR_LIT>" ) : <EOL> if request . method == "<STR_LIT:POST>" and request . user . is_authenticated ( ) : <EOL> if request . POST [ "<STR_LIT:action>" ] == "<STR_LIT>" : <EOL> add_email_form = form_class ( request . user , request . POST ) <EOL> if add_email_form . is_valid ( ) : <EOL> add_email_form . save ( ) <EOL> add_email_form = form_class ( ) <EOL> else : <EOL> add_email_form = form_class ( ) <EOL> if request . POST [ "<STR_LIT:action>" ] == "<STR_LIT>" : <EOL> email = request . POST [ "<STR_LIT:email>" ] <EOL> try : <EOL> email_address = EmailAddress . objects . get ( user = request . user , email = email ) <EOL> request . user . message_set . create ( message = "<STR_LIT>" % email ) <EOL> EmailConfirmation . objects . send_confirmation ( email_address ) <EOL> except EmailAddress . DoesNotExist : <EOL> pass <EOL> elif request . POST [ "<STR_LIT:action>" ] == "<STR_LIT>" : <EOL> email = request . POST [ "<STR_LIT:email>" ] <EOL> try : <EOL> email_address = EmailAddress . objects . get ( user = request . user , email = email ) <EOL> email_address . delete ( ) <EOL> request . user . message_set . create ( message = "<STR_LIT>" % email ) <EOL> except EmailAddress . DoesNotExist : <EOL> pass <EOL> elif request . POST [ "<STR_LIT:action>" ] == "<STR_LIT>" : <EOL> email = request . POST [ "<STR_LIT:email>" ] <EOL> email_address = EmailAddress . objects . get ( user = request . user , email = email ) <EOL> email_address . set_as_primary ( ) <EOL> else : <EOL> add_email_form = form_class ( ) <EOL> return render_to_response ( template_name , { <EOL> "<STR_LIT>" : add_email_form , <EOL> } , context_instance = RequestContext ( request ) ) <EOL> email = login_required ( email ) <EOL> def password_change ( request , form_class = ChangePasswordForm , <EOL> template_name = "<STR_LIT>" ) : <EOL> if request . method == "<STR_LIT:POST>" : <EOL> password_change_form = form_class ( request . user , request . POST ) <EOL> if password_change_form . is_valid ( ) : <EOL> password_change_form . save ( ) <EOL> password_change_form = form_class ( request . user ) <EOL> else : <EOL> password_change_form = form_class ( request . user ) <EOL> return render_to_response ( template_name , { <EOL> "<STR_LIT>" : password_change_form , <EOL> } , context_instance = RequestContext ( request ) ) <EOL> password_change = login_required ( password_change ) <EOL> def password_reset ( request , form_class = ResetPasswordForm , <EOL> template_name = "<STR_LIT>" , <EOL> template_name_done = "<STR_LIT>" ) : <EOL> if request . method == "<STR_LIT:POST>" : <EOL> password_reset_form = form_class ( request . POST ) <EOL> if password_reset_form . is_valid ( ) : <EOL> email = password_reset_form . save ( ) <EOL> return render_to_response ( template_name_done , { <EOL> "<STR_LIT:email>" : email , <EOL> } , context_instance = RequestContext ( request ) ) <EOL> else : <EOL> password_reset_form = form_class ( ) <EOL> return render_to_response ( template_name , { <EOL> "<STR_LIT>" : password_reset_form , <EOL> } , context_instance = RequestContext ( request ) ) <EOL> def timezone_change ( request , form_class = ChangeTimezoneForm , <EOL> template_name = "<STR_LIT>" ) : <EOL> if request . method == "<STR_LIT:POST>" : <EOL> form = form_class ( request . user , request . POST ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> else : <EOL> form = form_class ( request . user ) <EOL> return render_to_response ( template_name , { <EOL> "<STR_LIT>" : form , <EOL> } , context_instance = RequestContext ( request ) ) <EOL> timezone_change = login_required ( timezone_change ) <EOL> def language_change ( request , form_class = ChangeLanguageForm , <EOL> template_name = "<STR_LIT>" ) : <EOL> if request . method == "<STR_LIT:POST>" : <EOL> form = form_class ( request . user , request . POST ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> next = request . META . get ( '<STR_LIT>' , None ) <EOL> return HttpResponseRedirect ( next ) <EOL> else : <EOL> form = form_class ( request . user ) <EOL> return render_to_response ( template_name , { <EOL> "<STR_LIT>" : form , <EOL> } , context_instance = RequestContext ( request ) ) <EOL> language_change = login_required ( language_change ) <EOL> def other_services ( request , template_name = "<STR_LIT>" ) : <EOL> from zwitschern . utils import twitter_verify_credentials <EOL> from zwitschern . pownce_utils import pownce_verify_credentials <EOL> twitter_form = TwitterForm ( request . user ) <EOL> pownce_form = PownceForm ( request . user ) <EOL> twitter_authorized = False <EOL> pownce_authorized = False <EOL> if request . method == "<STR_LIT:POST>" : <EOL> twitter_form = TwitterForm ( request . user , request . POST ) <EOL> if request . POST [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> if twitter_form . is_valid ( ) : <EOL> from zwitschern . utils import twitter_account_raw <EOL> twitter_account = twitter_account_raw ( request . POST [ '<STR_LIT:username>' ] , request . POST [ '<STR_LIT:password>' ] ) <EOL> twitter_authorized = twitter_verify_credentials ( twitter_account ) <EOL> if not twitter_authorized : <EOL> request . user . message_set . create ( message = "<STR_LIT>" ) <EOL> else : <EOL> twitter_form . save ( ) <EOL> if request . POST [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> pownce_form = PownceForm ( request . user , request . POST ) <EOL> if pownce_form . is_valid ( ) : <EOL> from zwitschern . pownce_utils import pownce_account_raw <EOL> pownce_account = pownce_account_raw ( request . POST [ '<STR_LIT>' ] , request . POST [ '<STR_LIT>' ] ) <EOL> pownce_authorized = pownce_verify_credentials ( pownce_account ) <EOL> if not pownce_authorized : <EOL> request . user . message_set . create ( message = "<STR_LIT>" ) <EOL> else : <EOL> pownce_form . save ( ) <EOL> else : <EOL> from zwitschern . utils import twitter_account_for_user <EOL> from zwitschern . pownce_utils import pownce_account_for_user <EOL> twitter_account = twitter_account_for_user ( request . user ) <EOL> pownce_account = pownce_account_for_user ( request . user ) <EOL> twitter_authorized = twitter_verify_credentials ( twitter_account ) <EOL> pownce_authorized = pownce_verify_credentials ( pownce_account ) <EOL> twitter_form = TwitterForm ( request . user ) <EOL> pownce_form = PownceForm ( request . user ) <EOL> return render_to_response ( template_name , { <EOL> "<STR_LIT>" : twitter_form , <EOL> "<STR_LIT>" : twitter_authorized , <EOL> "<STR_LIT>" : pownce_form , <EOL> "<STR_LIT>" : pownce_authorized , <EOL> } , context_instance = RequestContext ( request ) ) <EOL> other_services = login_required ( other_services ) </s>
