<s> """<STR_LIT>""" <EOL> from django . core . urlresolvers import reverse <EOL> from django import forms <EOL> from django . core . mail import send_mail <EOL> from django . conf import settings <EOL> from django . http import HttpResponseRedirect <EOL> import logging <EOL> STATUS_UPDATES = False <EOL> def create_user ( username , password , name = None ) : <EOL> from helios_auth . models import User <EOL> user = User . get_by_type_and_id ( '<STR_LIT:password>' , username ) <EOL> if user : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> info = { '<STR_LIT:password>' : password , '<STR_LIT:name>' : name } <EOL> user = User . update_or_create ( user_type = '<STR_LIT:password>' , user_id = username , info = info ) <EOL> user . save ( ) <EOL> class LoginForm ( forms . Form ) : <EOL> username = forms . CharField ( max_length = <NUM_LIT:50> ) <EOL> password = forms . CharField ( widget = forms . PasswordInput ( ) , max_length = <NUM_LIT:100> ) <EOL> def password_check ( user , password ) : <EOL> return ( user and user . info [ '<STR_LIT:password>' ] == password ) <EOL> def password_login_view ( request ) : <EOL> from helios_auth . view_utils import render_template <EOL> from helios_auth . views import after <EOL> from helios_auth . models import User <EOL> error = None <EOL> if request . method == "<STR_LIT:GET>" : <EOL> form = LoginForm ( ) <EOL> else : <EOL> form = LoginForm ( request . POST ) <EOL> request . session [ '<STR_LIT>' ] = '<STR_LIT:password>' <EOL> if request . POST . has_key ( '<STR_LIT>' ) : <EOL> request . session [ '<STR_LIT>' ] = request . POST . get ( '<STR_LIT>' ) <EOL> if form . is_valid ( ) : <EOL> username = form . cleaned_data [ '<STR_LIT:username>' ] . strip ( ) <EOL> password = form . cleaned_data [ '<STR_LIT:password>' ] . strip ( ) <EOL> try : <EOL> user = User . get_by_type_and_id ( '<STR_LIT:password>' , username ) <EOL> if password_check ( user , password ) : <EOL> request . session [ '<STR_LIT>' ] = user . user_id <EOL> return HttpResponseRedirect ( reverse ( after ) ) <EOL> except User . DoesNotExist : <EOL> pass <EOL> error = '<STR_LIT>' <EOL> return render_template ( request , '<STR_LIT>' , { '<STR_LIT>' : form , '<STR_LIT:error>' : error } ) <EOL> def password_forgotten_view ( request ) : <EOL> """<STR_LIT>""" <EOL> from helios_auth . view_utils import render_template <EOL> from helios_auth . models import User <EOL> if request . method == "<STR_LIT:GET>" : <EOL> return render_template ( request , '<STR_LIT>' , { '<STR_LIT>' : request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> else : <EOL> username = request . POST [ '<STR_LIT:username>' ] <EOL> return_url = request . POST [ '<STR_LIT>' ] <EOL> try : <EOL> user = User . get_by_type_and_id ( '<STR_LIT:password>' , username ) <EOL> except User . DoesNotExist : <EOL> return render_template ( request , '<STR_LIT>' , { '<STR_LIT>' : request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT:error>' : '<STR_LIT>' } ) <EOL> body = """<STR_LIT>""" % ( user . user_id , user . info [ '<STR_LIT:password>' ] , settings . SITE_TITLE ) <EOL> send_mail ( '<STR_LIT>' , body , settings . SERVER_EMAIL , [ "<STR_LIT>" % ( user . info [ '<STR_LIT:name>' ] , user . info [ '<STR_LIT:email>' ] ) ] , fail_silently = False ) <EOL> return HttpResponseRedirect ( return_url ) <EOL> def get_auth_url ( request , redirect_url = None ) : <EOL> return reverse ( password_login_view ) <EOL> def get_user_info_after_auth ( request ) : <EOL> from helios_auth . models import User <EOL> user = User . get_by_type_and_id ( '<STR_LIT:password>' , request . session [ '<STR_LIT>' ] ) <EOL> del request . session [ '<STR_LIT>' ] <EOL> return { '<STR_LIT:type>' : '<STR_LIT:password>' , '<STR_LIT>' : user . user_id , '<STR_LIT:name>' : user . name , '<STR_LIT:info>' : user . info , '<STR_LIT>' : None } <EOL> def update_status ( token , message ) : <EOL> pass <EOL> def send_message ( user_id , user_name , user_info , subject , body ) : <EOL> email = user_id <EOL> name = user_name or user_info . get ( '<STR_LIT:name>' , email ) <EOL> send_mail ( subject , body , settings . SERVER_EMAIL , [ "<STR_LIT>" % ( name , email ) ] , fail_silently = False ) <EOL> def can_create_election ( user_id , user_info ) : <EOL> return True </s>
