diff options
Diffstat (limited to 'forum')
-rwxr-xr-x | forum/authentication/__init__.py | 27 | ||||
-rwxr-xr-x | forum/authentication/base.py | 44 | ||||
-rwxr-xr-x | forum/authentication/forms.py | 73 | ||||
-rwxr-xr-x | forum/skins/default/media/jquery-openid/jquery.openid.js | 24 | ||||
-rwxr-xr-x | forum/skins/default/media/jquery-openid/openid.css | 14 | ||||
-rwxr-xr-x | forum/skins/default/templates/auth/auth_settings.html | 35 | ||||
-rwxr-xr-x | forum/skins/default/templates/auth/complete.html | 95 | ||||
-rwxr-xr-x | forum/skins/default/templates/auth/email_validation.html | 20 | ||||
-rwxr-xr-x | forum/skins/default/templates/auth/signin.html | 165 | ||||
-rwxr-xr-x | forum/skins/default/templates/auth/signup.html | 32 | ||||
-rwxr-xr-x | forum/skins/default/templates/auth/temp_login_email.html | 20 | ||||
-rwxr-xr-x | forum/skins/default/templates/auth/temp_login_request.html | 28 | ||||
-rwxr-xr-x | forum/skins/default/templates/authopenid/signin.html | 92 | ||||
-rw-r--r-- | forum/views/auth.py | 359 |
14 files changed, 69 insertions, 959 deletions
diff --git a/forum/authentication/__init__.py b/forum/authentication/__init__.py deleted file mode 100755 index 75099303..00000000 --- a/forum/authentication/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ -import re -from forum.modules import get_modules_script_classes -from forum.authentication.base import AuthenticationConsumer, ConsumerTemplateContext - -class ConsumerAndContext(): - def __init__(self, id, consumer, context): - self.id = id - self.consumer = consumer() - - context.id = id #add extra field to context - self.context = context - -consumers = dict([ - (re.sub('AuthConsumer$', '', name).lower(), cls) for name, cls - in get_modules_script_classes('authentication', AuthenticationConsumer).items() - if not re.search('AbstractAuthConsumer$', name) - ]) - -contexts = dict([ - (re.sub('AuthContext$', '', name).lower(), cls) for name, cls - in get_modules_script_classes('authentication', ConsumerTemplateContext).items() - ]) - -AUTH_PROVIDERS = dict([ - (name, ConsumerAndContext(name, consumers[name], contexts[name])) for name in consumers.keys() - if name in contexts - ]) diff --git a/forum/authentication/base.py b/forum/authentication/base.py deleted file mode 100755 index 99005866..00000000 --- a/forum/authentication/base.py +++ /dev/null @@ -1,44 +0,0 @@ - -class AuthenticationConsumer(object): - - def prepare_authentication_request(self, request, redirect_to): - raise NotImplementedError() - - def process_authentication_request(self, response): - raise NotImplementedError() - - def get_user_data(self, key): - raise NotImplementedError() - - -class ConsumerTemplateContext(object): - """ - Class that provides information about a certain authentication provider context in the signin page. - - class attributes: - - mode - one of BIGICON, SMALLICON, FORM - - human_name - the human readable name of the provider - - extra_js - some providers require us to load extra javascript on the signin page for them to work, - this is the place to add those files in the form of a list - - extra_css - same as extra_js but for css files - """ - mode = '' - weight = 500 - human_name = '' - extra_js = [] - extra_css = [] - show_to_logged_in_user = True - - @classmethod - def readable_key(cls, key): - return key.key - -class InvalidAuthentication(Exception): - def __init__(self, message): - self.message = message - -
\ No newline at end of file diff --git a/forum/authentication/forms.py b/forum/authentication/forms.py deleted file mode 100755 index 24e76c08..00000000 --- a/forum/authentication/forms.py +++ /dev/null @@ -1,73 +0,0 @@ -from forum.utils.forms import NextUrlField, UserNameField, UserEmailField, SetPasswordForm -from forum.models import EmailFeedSetting, Question, User -from django.contrib.contenttypes.models import ContentType -from django.utils.translation import ugettext as _ -from django.utils.safestring import mark_safe -from django import forms -from forum.forms import EditUserEmailFeedsForm -import logging - -class SimpleRegistrationForm(forms.Form): - next = NextUrlField() - username = UserNameField() - email = UserEmailField() - -class TemporaryLoginRequestForm(forms.Form): - def __init__(self, data=None): - super(TemporaryLoginRequestForm, self).__init__(data) - self.user_cache = None - - email = forms.EmailField( - required=True, - label=_("Your account email"), - error_messages={ - 'required': _("You cannot leave this field blank"), - 'invalid': _('please enter a valid email address'), - } - ) - - def clean_email(self): - try: - user = User.objects.get(email=self.cleaned_data['email']) - except: - raise forms.ValidationError(_("Sorry, but this email is not on our database.")) - - self.user_cache = user - return self.cleaned_data['email'] - - -class SimpleEmailSubscribeForm(forms.Form): - SIMPLE_SUBSCRIBE_CHOICES = ( - ('y',_('okay, let\'s try!')), - ('n',_('no community email please, thanks')) - ) - subscribe = forms.ChoiceField(widget=forms.widgets.RadioSelect(), \ - error_messages={'required':_('please choose one of the options above')}, - choices=SIMPLE_SUBSCRIBE_CHOICES) - - def save(self,user=None): - EFF = EditUserEmailFeedsForm - if self.cleaned_data['subscribe'] == 'y': - email_settings_form = EFF() - logging.debug('%s wants to subscribe' % user.username) - else: - email_settings_form = EFF(initial=EFF.NO_EMAIL_INITIAL) - email_settings_form.save(user,save_unbound=True) - -class ChangePasswordForm(SetPasswordForm): - """ change password form """ - oldpw = forms.CharField(widget=forms.PasswordInput(attrs={'class':'required'}), - label=mark_safe(_('Current password'))) - - def __init__(self, data=None, user=None, *args, **kwargs): - if user is None: - raise TypeError("Keyword argument 'user' must be supplied") - super(ChangePasswordForm, self).__init__(data, *args, **kwargs) - self.user = user - - def clean_oldpw(self): - """ test old password """ - if not self.user.check_password(self.cleaned_data['oldpw']): - raise forms.ValidationError(_("Old password is incorrect. \ - Please enter the correct password.")) - return self.cleaned_data['oldpw'] diff --git a/forum/skins/default/media/jquery-openid/jquery.openid.js b/forum/skins/default/media/jquery-openid/jquery.openid.js index 8d1cd204..eae7b3ea 100755 --- a/forum/skins/default/media/jquery-openid/jquery.openid.js +++ b/forum/skins/default/media/jquery-openid/jquery.openid.js @@ -36,7 +36,7 @@ $.fn.openid = function() { }; var local = function() { var $li = $(this); - $('#openid_form .providers li').removeClass('highlight'); + $('#openid_form .providers td').removeClass('highlight'); $li.addClass('highlight'); $usrfs.hide(); $idfs.hide(); @@ -47,19 +47,19 @@ $.fn.openid = function() { var direct = function() { var $li = $(this); - $('#openid_form .providers li').removeClass('highlight'); + $('#openid_form .providers td').removeClass('highlight'); $li.addClass('highlight'); $usrfs.fadeOut('slow'); $localfs.fadeOut('slow'); $idfs.fadeOut('slow'); - $id.val($this.find("li.highlight span").text()); + $id.val($this.find("td.highlight span").text()); setTimeout(function(){$('#bsignin').click();},1000); return false; }; var openid = function() { var $li = $(this); - $('#openid_form .providers li').removeClass('highlight'); + $('#openid_form .providers td').removeClass('highlight'); $li.addClass('highlight'); $usrfs.hide(); $localfs.hide(); @@ -71,7 +71,7 @@ $.fn.openid = function() { var username = function() { var $li = $(this); - $('#openid_form .providers li').removeClass('highlight'); + $('#openid_form .providers td').removeClass('highlight'); $li.addClass('highlight'); $idfs.hide(); $localfs.hide(); @@ -84,10 +84,10 @@ $.fn.openid = function() { return false; }; - $this.find('li.local').click(local); - $this.find('li.direct').click(direct); - $this.find('li.openid').click(openid); - $this.find('li.username').click(username); + $this.find('td.local').click(local); + $this.find('td.direct').click(direct); + $this.find('td.openid').click(openid); + $this.find('td.username').click(username); $id.keypress(function(e) { if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { return submitid(); @@ -98,12 +98,12 @@ $.fn.openid = function() { return submitusr(); } }); - $this.find('li span').hide(); - $this.find('li').css('line-height', 0).css('cursor', 'pointer'); + $this.find('td span').hide(); + $this.find('td').css('line-height', 0).css('cursor', 'pointer'); $usrfs.hide(); $idfs.hide(); $localfs.hide(); - $this.find('li:eq(0)').click(); + $this.find('td:eq(0)').click(); return this; }; diff --git a/forum/skins/default/media/jquery-openid/openid.css b/forum/skins/default/media/jquery-openid/openid.css index 1b7aaf82..307d5624 100755 --- a/forum/skins/default/media/jquery-openid/openid.css +++ b/forum/skins/default/media/jquery-openid/openid.css @@ -1,7 +1,7 @@ fieldset { border-style:none; } img {border-style:none;} -.logo_box {display:inline-block;float:left;width:90px;height:40px;background:white;border:1px solid #dddddd;} +.logo_box {width:90px;height:40px;background:white;border:1px solid #dddddd;} .openid_box img {margin-top:6px;} .aol_box img {margin-top:6px;} .yahoo_box img {margin-top:13px;} @@ -9,13 +9,11 @@ img {border-style:none;} .local_login_box img {margin-top:2px;margin-left:-3px;} form.openid ul{ margin:0;padding:0;text-align:center; list-style-type:none; display:block;} -form.openid ul li {float:left; padding:4px;display:inline-block;} -form.openid ul li div {display:inline-block;} +form.openid ul li {padding:4px;} form.openid ul li span {padding:0 1em 0 3px} form.openid ul li.first_tiny_li {clear:left;} form.openid fieldset {clear:both;padding:10px 0px 0px 0px;} form.openid div+fieldset {display:none} -form.openid label {display:block; font-weight:bold;} input[name=openid_username] {width:8em} input[name=openid_identifier] {width:18em} form.openid ul li.highlight { -moz-border-radius:4px; -webkit-border-radius:4px; background-color: #FD6} @@ -24,7 +22,6 @@ form.openid fieldset div { -webkit-border-radius:4px; background: #DCDCDC; padding:10px; - display:inline-block; float:left; } form.openid p {margin-bottom:4px;} @@ -67,9 +64,16 @@ form.openid ul.errorlist li { float: none; color:blue; } +ul.providers { + clear:left; + float:left; +} #openid_small_providers li { margin-top:4px; } #openid_small_providers li.facebook { margin-top:0px; } +ul.providers { + display: block; +} diff --git a/forum/skins/default/templates/auth/auth_settings.html b/forum/skins/default/templates/auth/auth_settings.html deleted file mode 100755 index 051fb6ba..00000000 --- a/forum/skins/default/templates/auth/auth_settings.html +++ /dev/null @@ -1,35 +0,0 @@ -{% extends "base.html" %} -<!-- changepw.html --> -{% load i18n %} -{% block head %}{% endblock %} -{% block title %}{% spaceless %}{% trans "Authentication settings" %}{% endspaceless %}{% endblock %} -{% block content %} -<div class="headNormal">{% trans "Authentication settings" %}</div> -{% if auth_keys %} - <p class="message">{% blocktrans %}These are the external authentication providers currently associated with your account.{% endblocktrans %}</p> - <div> - {% for key in auth_keys %} - <p>{{ key.name }} (<a href="{% url user_remove_external_provider id=key.id %}">{% trans "remove" %}</a>)</p> - {% endfor %} - </div> -{% endif %} -{% if not auth_keys %} - <p class="message">{% blocktrans %}You currently have no external authentication provider associated with your account.{% endblocktrans %}</p> -{% endif %} -<input type="button" class="submit" value="{% trans "Add new provider" %}" onclick="window.location='{% url user_add_external_provider %}'" /> -{% if has_password %} - <p class="message">{% blocktrans %}This is where you can change your password. Make sure you remember it!{% endblocktrans %}</p> -{% endif %} -{% if not has_password %} - <p class="message">{% blocktrans %}You can set up a password for your account, so you can login using standard username and password!{% endblocktrans %}</p> -{% endif %} -<div class="aligned"> - <form action="" method="post" accept-charset="utf-8"> - <ul id="changepw-form" class="form-horizontal-rows"> - {{form.as_ul}} - </ul> - <div class="submit-row"><input type="submit" class="submit" value="{% if has_password %}{% trans "Change password" %}{% endif %}{% if not has_password %}{% trans "Create password" %}{% endif %}" /></div> - </form> - </div> -{% endblock %} -<!-- end changepw.html --> diff --git a/forum/skins/default/templates/auth/complete.html b/forum/skins/default/templates/auth/complete.html deleted file mode 100755 index cb2dc5aa..00000000 --- a/forum/skins/default/templates/auth/complete.html +++ /dev/null @@ -1,95 +0,0 @@ -{% extends "base_content.html" %} -<!-- complete.html --> -{% load i18n %} -{% block head %}{% endblock %} -{% block title %}{% spaceless %}{% trans "Connect your OpenID with this site" %}{% endspaceless %}{% endblock %} -{% block content %} - <div id="main-bar" class="headNormal"> - {% trans "Connect your OpenID with your account on this site" %} - </div> - <div id="completetxt" > - <div class="message"> - <b>{% trans "You are here for the first time with " %}{{ provider }}</b> - {% trans "Please create your screen name and save your email address. Saved email address will let you subscribe for the updates on the most interesting questions and will be used to create and retrieve your unique avatar image. " %} - </div> - <p style="display:none">{% trans "This account already exists, please use another." %}</p> - </div> - - {% if form1.errors %} - <ul class="errorlist"> - {% if form1.non_field_errors %} - {% for error in form1.non_field_errors %} - <li>{{error}}</li> - {% endfor %} - {% endif %} - </ul> - {% endif %} - {% comment %} - {% if form2.errors %}<!--form2 is dysfunctional so commented out --> - <div class="errors"> - <span class="big">{% trans "Sorry, looks like we have some errors:" %}</span><br/> - <ul class="error-list"> - {% if form2.username.errors %} - <li><span class="error">{{ form2.username.errors|join:", " }}</span></li> - {% endif %} - {% if form2.password.errors %} - <li><span class="error">{{ form2.password.errors|join:", " }}</span></li> - {% endif %} - </ul> - </div> - {% endif %} - {% endcomment %} - - <div class="login"> - <form name="fregister" action="" method="POST"> - {{ form1.next }} - <div class="form-row-vertical"> - <label for="id_username">{% trans "Screen name label" %}</label> - {% if form1.username.errors %} - <p class="error">{{ form1.username.errors|join:", " }}</p> - {% endif %} - {{ form1.username }} - </div> - <div class="form-row-vertical margin-bottom"> - <label for="id_email">{% trans "Email address label" %}</label> - {% if form1.email.errors %} - <p class="error">{{ form1.email.errors|join:", " }}</p> - {% endif %} - {{ form1.email }} - </div> - <p>{% trans "receive updates motivational blurb" %}</p> - <div class='simple-subscribe-options'> - {{email_feeds_form.subscribe}} - {% if email_feeds_form.errors %} - <p class="error">{% trans "please select one of the options above" %}</p> - {% endif %} - </div> - <p class='space-above'>{% trans "Tag filter tool will be your right panel, once you log in." %}</p> - <div class="submit-row"><input type="submit" class="submit" name="bnewaccount" value="{% trans "create account" %}"/></div> - </form> - </div> - {% comment %}<!-- this form associates openID with an existing password-protected account, not yet functional --> - {% if form2 %} - <div class="login" style="display:none"> - <form name="fverify" action="{% url user_register %}" method="POST"> - {{ form2.next }} - <fieldset style="padding:10px"> - <legend class="big">{% trans "Existing account" %}</legend> - <div class="form-row"><label for="id_username">{% trans "user name" %}</label><br/>{{ form2.username }}</div> - <div class="form-row"><label for="id_passwordl">{% trans "password" %}</label><br/>{{ form2.password }}</div> - <p><span class='big strong'>(Optional) receive updates by email</span> - only sent when there are any.</p> - <div class='simple-subscribe-options'> - {{email_feeds_form.subscribe}} - </div> - <!--todo double check translation from chinese 确认 = "Register" --> - <div class="submit-row"> - <input type="submit" class="submit" name="bverify" value="{% trans "Register" %}"/> - <a href="{% url user_sendpw %}">{% trans "Forgot your password?" %}</a> - </div> - </fieldset> - </form> - </div> - {% endif %} - {% endcomment %} -{% endblock %} -<!-- end complete.html --> diff --git a/forum/skins/default/templates/auth/email_validation.html b/forum/skins/default/templates/auth/email_validation.html deleted file mode 100755 index a4126a69..00000000 --- a/forum/skins/default/templates/auth/email_validation.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends "email_base.html" %}
-{% load i18n %}
-{% load extra_tags %}
-
-{% block content %}
- <p>{% trans "Greetings from the Q&A forum" %},</p>
-
- <p>{% trans "To make use of the Forum, please follow the link below:" %}</p>
-
- <a href="{% fullurl auth_validate_email user=user.id,code=validation_code %}">{% fullurl auth_validate_email user=user.id,code=validation_code %}</a>
-
- <p>{% trans "Following the link above will help us verify your email address." %}</p>
-
- <p>{% blocktrans %}If you beleive that this message was sent in mistake -
- no further action is needed. Just ingore this email, we apologize
- for any inconvenience{% endblocktrans %}</p>
-
- <p>{% blocktrans %}Sincerely,<br />
- Forum Administrator{% endblocktrans %}</p>
-{% endblock %}
diff --git a/forum/skins/default/templates/auth/signin.html b/forum/skins/default/templates/auth/signin.html deleted file mode 100755 index 78e6c76d..00000000 --- a/forum/skins/default/templates/auth/signin.html +++ /dev/null @@ -1,165 +0,0 @@ -{% extends "base.html" %}
-
-{% load i18n %}
-{% load extra_tags %}
-
-{% block forejs %}
- <link rel="stylesheet" type="text/css" media="screen" href="{% media "/media/style/auth.css" %}"/>
- {% for provider in all_providers %}
- {% for location in provider.extra_css %}
- <link rel="stylesheet" type="text/css" media="screen" href="{{ location }}"/>
- {% endfor %}
- {% endfor %}
-{% endblock %}
-
-{% block content %}
- {% for provider in all_providers %}
- {% if provider.pre_code %}
- {{ provider.pre_code|safe }}
- {% endif %}
- {% endfor %}
- <div class="headNormal">
- {% trans "User login" %}
- </div>
- {% if msg %}
- <p class="warning">{{ msg }}</p>
- {% endif %}
-
- <div style="width:600px;float:left;margin-bottom:5px;">
- {% trans "Click to sign in through any of these services." %}
- </div>
- {% if request.user.is_anonymous %}
- <div style="width:600px;float:left;margin-bottom:5px;">
- <input type="checkbox" checked="checked" id="validate_email" />
- {% trans "Take the oppurtunity to validate my email next to the external provider I choose." %}
- </div>
- {% endif %}
- <div id="bigicon_providers">
- {% for provider in bigicon_providers %}
- <div class="provider_logo big" name="{{ provider.id }}">
- {% ifequal provider.type "DIRECT" %}
- <a class="provider_direct" href="{% url auth_provider_signin provider=provider.id %}">
- <img src="{% media provider.icon %}" />
- </a>
- {% endifequal %}
- {% ifequal provider.type "CUSTOM" %}
- {% include provider.code_template %}
- {% endifequal %}
- {% ifequal provider.type "SIMPLE_FORM" %}
- <img alt="{{ provider.simple_form_context.your_what }}" class="simple_form_provider" src="{% media provider.icon %}" />
- {% endifequal %}
- </div>
- {% endfor %}
- </div>
- <div id="smallicon_providers">
- {% for provider in smallicon_providers %}
- <div class="provider_logo small" name="{{ provider.id }}">
- {% ifequal provider.type "DIRECT" %}
- <a class="provider_direct" href="{% url auth_provider_signin provider=provider.id %}">
- <img src="{% media provider.icon %}" />
- </a>
- {% endifequal %}
- {% ifequal provider.type "CUSTOM" %}
- {% include provider.code_template %}
- {% endifequal %}
- {% ifequal provider.type "SIMPLE_FORM" %}
- <img alt="{{ provider.simple_form_context.your_what }}" class="simple_form_provider" src="{% media provider.icon %}" />
- {% endifequal %}
- </div>
- {% endfor %}
- </div>
- <form name="signin_form" id="signin_form" class="signin_form" method="POST" action="">
- <div id="signin_form_slot"></div>
- <input type="hidden" class="validate_email" name="validate_email" value="yes" />
- </form>
- {% for provider in stackitem_providers %}
- <h3 class="or_label">{% trans 'Or...' %}</h3>
- <form class="signin_form" method="POST" action="{% url auth_provider_signin provider=provider.id %}">
- {% include provider.stack_item_template %}
- <input type="hidden" class="validate_email" name="validate_email" value="yes" />
- </form>
- {% endfor %}
- <h3 class="or_label">{% trans 'Or...' %}</h3>
- <fieldset>
- {% trans 'Click' %} <a href="{% url auth_request_tempsignin %}">here</a> {% trans "if you're having troubles signing in." %}
- </fieldset>
- <script type="text/html" id="simple_form_template">
- <fieldset id="slot_form">
- <p id="provider_name_slot">{% trans 'Enter your ' %}%%YOUR_WHAT%%</p>
- <div><p><span></span>
- <input id="input_field" type="text" name="input_field" /><span></span>
- <input id="ssignin" name="ssignin" type="submit" value="Login" />
- </p></div>
- <input type="hidden" class="validate_email" name="validate_email" value="yes" />
- </fieldset>
- </script>
- <script type="text/javascript">
- $(function() {
- var signin_url = "{% url auth_provider_signin provider='PROVIDER' %}";
-
- function set_validate_email() {
- var validate = $('#validate_email').attr('checked') ? 'yes' : 'no';
- $('.validate_email').attr('value', validate);
-
- $('.provider_direct').each(function() {
- var current_url = $(this).attr('href');
- if (!/\?validate_email\=(yes|no)$/.test(current_url)) {
- current_url += ('?validate_email=' + validate);
- } else {
- current_url = current_url.replace(/(yes|no)$/, validate);
- }
-
- $(this).attr('href', current_url);
- })
- }
-
- $('#validate_email').change(set_validate_email);
-
- function set_form_action(el) {
- var provider = el.parents('.provider_logo').attr('name');
- $('#signin_form').attr('action', signin_url.replace('PROVIDER', provider));
- }
-
- $('.provider_logo').click(function() {
- $('.provider_logo').removeClass('selected');
- $(this).addClass('selected');
- });
-
- $('.simple_form_provider').click(function() {
- $('#signin_form_slot').html('');
- var new_html = $('#simple_form_template').html()
- .replace('%%YOUR_WHAT%%', $(this).attr('alt'));
- $('#signin_form_slot').html(new_html);
- set_form_action($(this));
- set_validate_email();
- })
-
- set_validate_email();
- });
- </script>
-{% endblock %}
-
-{% block sidebar %}
-<div class="boxC">
- <h3 class="subtitle">{% trans "Why use OpenID?" %}</h3>
- <ul class="list-item">
- <li>
- {% trans "with openid it is easier" %}
- </li>
- <li>
- {% trans "reuse openid" %}
- </li>
- <li>
- {% trans "openid is widely adopted" %}
- </li>
- <li>
- {% trans "openid is supported open standard" %}
- </li>
-
- </ul>
- <p class="info-box-follow-up-links">
- <a href="http://openid.net/what/" target="_blank">{% trans "Find out more" %} </a><br/>
- <a href="http://openid.net/get/" target="_blank">{% trans "Get OpenID" %} </a>
- </p>
-</div>
-{% endblock%}
\ No newline at end of file diff --git a/forum/skins/default/templates/auth/signup.html b/forum/skins/default/templates/auth/signup.html deleted file mode 100755 index ac5eb241..00000000 --- a/forum/skins/default/templates/auth/signup.html +++ /dev/null @@ -1,32 +0,0 @@ -{% extends "base_content.html" %} -<!--signup.html--> -{% load i18n %} -{% block title %}{% spaceless %}{% trans "Signup" %}{% endspaceless %}{% endblock %} - -{% block content %} -<div class="headNormal"> - {% trans "Create login name and password" %} -</div> -<p class="message">{% trans "Traditional signup info" %}</p> -<form action="" method="post" accept-charset="utf-8"> - <ul class="form-horizontal-rows"> - <li><label for="usename_id">{{form.username.label}}</label>{{form.username}}{{form.username.errors}}</li> - <li><label for="email_id">{{form.email.label}}</label>{{form.email}}{{form.email.errors}}</li> - <li><label for="password1_id">{{form.password1.label}}</label>{{form.password1}}{{form.password1.errors}}</li> - <li><label for="password2_id">{{form.password2.label}}</label>{{form.password2}}{{form.password2.errors}}</li> - </ul> - <p class="margin-top">{% trans "receive updates motivational blurb" %}</p> - <div class='simple-subscribe-options'> - {{ email_feeds_form.subscribe }} - {% if email_feeds_form.errors %} - <p class="error">{% trans "please select one of the options above" %}</p> - {% endif %} - </div> - {% comment %}<p class="signup_p">{% trans "Please read and type in the two words below to help us prevent automated account creation." %}</p> - {{form.recaptcha}}{% endcomment %} - <div class="submit-row"><input type="submit" class="submit" value="{% trans "Create Account" %}" /> - <strong>{% trans "or" %} - <a href="{% url user_signin %}">{% trans "return to login page" %}</a></strong></div> -</form> -{% endblock %} -<!--end signup.html--> diff --git a/forum/skins/default/templates/auth/temp_login_email.html b/forum/skins/default/templates/auth/temp_login_email.html deleted file mode 100755 index 063608fe..00000000 --- a/forum/skins/default/templates/auth/temp_login_email.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends "email_base.html" %}
-{% load i18n %}
-{% load extra_tags %}
-
-{% block content %}
- <p>{% trans "Greetings from the Q&A forum" %},</p>
-
- <p>{% trans "You're seeing this because someone requested a temporary login link" %}</p>
-
- <a href="{% fullurl auth_tempsignin user=user.id,code=temp_login_code %}">{% fullurl auth_tempsignin user=user.id,code=temp_login_code %}</a>
-
- <p>{% trans "Following the link above will give you access to your account." %}</p>
-
- <p>{% blocktrans %}If you beleive that this message was sent in mistake -
- no further action is needed. Just ingore this email, we apologize
- for any inconvenience{% endblocktrans %}</p>
-
- <p>{% blocktrans %}Sincerely,<br />
- Forum Administrator{% endblocktrans %}</p>
-{% endblock %}
diff --git a/forum/skins/default/templates/auth/temp_login_request.html b/forum/skins/default/templates/auth/temp_login_request.html deleted file mode 100755 index 772f18fb..00000000 --- a/forum/skins/default/templates/auth/temp_login_request.html +++ /dev/null @@ -1,28 +0,0 @@ -{% extends "base.html" %}
-
-{% load i18n %}
-{% block head %}{% endblock %}
-{% block title %}{% spaceless %}{% trans "Request temporary login key" %}{% endspaceless %}{% endblock %}
-{% block content %}
-<div class="headNormal">{% trans "Account: request temporary login key" %}</div>
-<p class="message">{% blocktrans %}
- If you're experiencing problems accessing your account, or if you forgot your password,
- here you can request a temporary login key. Fill out your account email and we'll send you a temporary access link that
- will enable you to access your account. This token is valid only once and for a limited period of time.
- {% endblocktrans %}</p>
-<div class="aligned">
- {% if form.errors %}
- <ul class="errorlist">
- {% for error in form.errors %}
- <li>{{ error }}</li>
- {% endfor %}
- </ul>
- {% endif %}
- <form action="" method="post" accept-charset="utf-8">
- <ul id="changepw-form" class="form-horizontal-rows">
- {{form.as_ul}}
- </ul>
- <div class="submit-row"><input type="submit" class="submit" value="{% trans "Send link" %}" /></div>
- </form>
- </div>
-{% endblock %}
\ No newline at end of file diff --git a/forum/skins/default/templates/authopenid/signin.html b/forum/skins/default/templates/authopenid/signin.html index 04e58255..66ef2f78 100755 --- a/forum/skins/default/templates/authopenid/signin.html +++ b/forum/skins/default/templates/authopenid/signin.html @@ -38,10 +38,10 @@ </div>
{% endif %}
<form id="openid_form" name="openid_form" class="openid" method="post" action="{% url user_signin %}">
- <div style="width:600px;float:left;margin-bottom:5px;">
+ <div><!-- style="width:600px;float:left;margin-bottom:5px;"> -->
{% trans "Click to sign in through any of these services." %}
</div>
- <ul class="providers">
+ <table>
{% comment %}
<li class="local" title="Local login">
<div class="logo_box local_login_box">
@@ -50,29 +50,32 @@ <span></span>
</li>
{% endcomment %}
- <li class="username" title="OpenID URL">
- <div class="logo_box openid_box">
- <img src="{% media "/media/jquery-openid/images/openid.gif" %}" alt="icon" />
- <span>http://<strong>username</strong></span>
- </div>
- </li>
- <li class="direct" title="Google">
- <div class="logo_box google_box">
- <img src="{% media "/media/jquery-openid/images/google.gif" %}" alt="icon" /><span>https://www.google.com/accounts/o8/id</span>
- </div>
- </li>
- <li class="direct" title="Yahoo">
- <div class="logo_box yahoo_box">
- <img src="{% media "/media/jquery-openid/images/yahoo.gif" %}" alt="icon" /><span>http://yahoo.com/</span>
- </div>
- </li>
- <li class="username" title="AOL screen name">
- <div class="logo_box aol_box">
- <img src="{% media "/media/jquery-openid/images/aol.gif" %}" alt="icon" /><span>http://openid.aol.com/<strong>username</strong></span>
- </div>
- </li>
- </ul>
- <ul id="openid_small_providers" class="providers">
+ <tr class="providers">
+ <td class="username" title="OpenID URL">
+ <div class="logo_box openid_box">
+ <img src="{% media "/media/jquery-openid/images/openid.gif" %}" alt="icon" />
+ <span>http://<strong>username</strong></span>
+ </div>
+ </td>
+ <td class="direct" title="Google">
+ <div class="logo_box google_box">
+ <img src="{% media "/media/jquery-openid/images/google.gif" %}" alt="icon" /><span>https://www.google.com/accounts/o8/id</span>
+ </div>
+ </td>
+ <td class="direct" title="Yahoo">
+ <div class="logo_box yahoo_box">
+ <img src="{% media "/media/jquery-openid/images/yahoo.gif" %}" alt="icon" /><span>http://yahoo.com/</span>
+ </div>
+ </td>
+ <td class="username" title="AOL screen name">
+ <div class="logo_box aol_box">
+ <img src="{% media "/media/jquery-openid/images/aol.gif" %}" alt="icon" /><span>http://openid.aol.com/<strong>username</strong></span>
+ </div>
+ </td>
+ </tr>
+ </table>
+ <table>
+ <tr id="openid_small_providers" class="providers">
<!--<li class="openid" title="OpenID">
<div class="logo_box openid_box">
<img src="/media/jquery-openid/images/openid.gif" alt="icon" />
@@ -98,43 +101,44 @@ <span>http://{your-openid-url}</span>
</li>
{% endcomment %}
- <li class="username first_tiny_li" title="MyOpenID user name">
+ <td class="username first_tiny_li" title="MyOpenID user name">
<img src="{% media "/media/jquery-openid/images/myopenid-2.png" %}" alt="icon" />
<span>http://<strong>username</strong>.myopenid.com/</span>
- </li>
- <li class="username" title="Flickr user name">
+ </td>
+ <td class="username" title="Flickr user name">
<img src="{% media "/media/jquery-openid/images/flickr.png" %}" alt="icon" />
<span>http://flickr.com/<strong>username</strong>/</span>
- </li>
- <li class="username" title="Technorati user name">
+ </td>
+ <td class="username" title="Technorati user name">
<img src="{% media "/media/jquery-openid/images/technorati-1.png" %}" alt="icon" />
<span>http://technorati.com/people/technorati/<strong>username</strong>/</span>
- </li>
- <li class="username" title="Wordpress blog name">
+ </td>
+ <td class="username" title="Wordpress blog name">
<img src="{% media "/media/jquery-openid/images/wordpress.png" %}" alt="icon" />
<span>http://<strong>username</strong>.wordpress.com</span>
- </li>
- <li class="username" title="Blogger blog name">
+ </td>
+ <td class="username" title="Blogger blog name">
<img src="{% media "/media/jquery-openid/images/blogger-1.png" %}" alt="icon" />
<span>http://<strong>username</strong>.blogspot.com/</span>
- </li>
- <li class="username" title="LiveJournal blog name">
+ </td>
+ <td class="username" title="LiveJournal blog name">
<img src="{% media "/media/jquery-openid/images/livejournal-1.png" %}" alt="icon" />
<span>http://<strong>username</strong>.livejournal.com</span>
- </li>
- <li class="username" title="ClaimID user name">
+ </td>
+ <td class="username" title="ClaimID user name">
<img src="{% media "/media/jquery-openid/images/claimid-0.png" %}" alt="icon" />
<span>http://claimid.com/<strong>username</strong></span>
- </li>
- <li class="username" title="Vidoop user name">
+ </td>
+ <td class="username" title="Vidoop user name">
<img src="{% media "/media/jquery-openid/images/vidoop.png" %}" alt="icon" />
<span>http://<strong>username</strong>.myvidoop.com/</span>
- </li>
- <li class="username" title="Verisign user name">
+ </td>
+ <td class="username" title="Verisign user name">
<img src="{% media "/media/jquery-openid/images/verisign-2.png" %}" alt="icon" />
<span>http://<strong>username</strong>.pip.verisignlabs.com/</span>
- </li>
- </ul>
+ </td>
+ </tr>
+ </table>
{{ form2.next }}
<fieldset>
<p id="provider_name_slot">{% trans 'Enter your <span id="enter_your_what">Provider user name</span>' %}</p>
diff --git a/forum/views/auth.py b/forum/views/auth.py deleted file mode 100644 index 648bda80..00000000 --- a/forum/views/auth.py +++ /dev/null @@ -1,359 +0,0 @@ -from django.shortcuts import render_to_response, get_object_or_404 -from django.template import RequestContext -from django.core.urlresolvers import reverse -from django.contrib.auth.models import User -from django.http import HttpResponseRedirect, Http404 -from django.utils.safestring import mark_safe -from django.utils.translation import ugettext as _ -from django.utils.http import urlquote_plus -from django.contrib.auth.decorators import login_required -from django.contrib.auth import login, logout -from django.http import get_host -import types -import datetime - -from forum.models import AuthKeyUserAssociation, ValidationHash -from forum.authentication.forms import SimpleRegistrationForm, SimpleEmailSubscribeForm, \ - TemporaryLoginRequestForm, ChangePasswordForm, SetPasswordForm -from forum.utils.email import send_email - -from forum.authentication.base import InvalidAuthentication -from forum.authentication import AUTH_PROVIDERS - -from forum.models import Question, Answer - -def signin_page(request, action=None): - if action is None: - request.session['on_signin_url'] = request.META.get('HTTP_REFERER', '/') - else: - request.session['on_signin_action'] = action - request.session['on_signin_url'] = reverse('auth_action_signin', kwargs={'action': action}) - - all_providers = [provider.context for provider in AUTH_PROVIDERS.values()] - - sort = lambda c1, c2: c1.weight - c2.weight - can_show = lambda c: not request.user.is_authenticated() or c.show_to_logged_in_user - - bigicon_providers = sorted([ - context for context in all_providers if context.mode == 'BIGICON' and can_show(context) - ], sort) - - smallicon_providers = sorted([ - context for context in all_providers if context.mode == 'SMALLICON' and can_show(context) - ], sort) - - stackitem_providers = sorted([ - context for context in all_providers if context.mode == 'STACK_ITEM' and can_show(context) - ], sort) - - try: - msg = request.session['auth_error'] - del request.session['auth_error'] - except: - msg = None - - return render_to_response( - 'auth/signin.html', - { - 'msg': msg, - 'all_providers': all_providers, - 'bigicon_providers': bigicon_providers, - 'stackitem_providers': stackitem_providers, - 'smallicon_providers': smallicon_providers, - }, - RequestContext(request)) - -def prepare_provider_signin(request, provider): - force_email_request = request.REQUEST.get('validate_email', 'yes') == 'yes' - request.session['force_email_request'] = force_email_request - - if provider in AUTH_PROVIDERS: - provider_class = AUTH_PROVIDERS[provider].consumer - - try: - request_url = provider_class.prepare_authentication_request(request, - reverse('auth_provider_done', kwargs={'provider': provider})) - - return HttpResponseRedirect(request_url) - except NotImplementedError, e: - return process_provider_signin(request, provider) - except InvalidAuthentication, e: - request.session['auth_error'] = e.message - - return HttpResponseRedirect(reverse('user_signin')) - - -def process_provider_signin(request, provider): - if provider in AUTH_PROVIDERS: - provider_class = AUTH_PROVIDERS[provider].consumer - - try: - assoc_key = provider_class.process_authentication_request(request) - except InvalidAuthentication, e: - request.session['auth_error'] = e.message - return HttpResponseRedirect(reverse('user_signin')) - - if request.user.is_authenticated(): - if isinstance(assoc_key, (type, User)): - if request.user != assoc_key: - request.session['auth_error'] = _("Sorry, these login credentials belong to anoother user. Plese terminate your current session and try again.") - else: - request.session['auth_error'] = _("You are already logged in with that user.") - else: - try: - assoc = AuthKeyUserAssociation.objects.get(key=assoc_key) - if assoc.user == request.user: - request.session['auth_error'] = _("These login credentials are already associated with your account.") - else: - request.session['auth_error'] = _("Sorry, these login credentials belong to anoother user. Plese terminate your current session and try again.") - except: - uassoc = AuthKeyUserAssociation(user=request.user, key=assoc_key, provider=provider) - uassoc.save() - request.user.message_set.create(message=_('The new credentials are now associated with your account')) - return HttpResponseRedirect(reverse('user_authsettings')) - - return HttpResponseRedirect(reverse('user_signin')) - else: - if isinstance(assoc_key, (type, User)): - return login_and_forward(request, assoc_key) - - try: - assoc = AuthKeyUserAssociation.objects.get(key=assoc_key) - user_ = assoc.user - return login_and_forward(request, user_) - except: - request.session['assoc_key'] = assoc_key - request.session['auth_provider'] = provider - return HttpResponseRedirect(reverse('auth_external_register')) - - return HttpResponseRedirect(reverse('user_signin')) - -def external_register(request): - if request.method == 'POST' and 'bnewaccount' in request.POST: - form1 = SimpleRegistrationForm(request.POST) - email_feeds_form = SimpleEmailSubscribeForm(request.POST) - - if (form1.is_valid() and email_feeds_form.is_valid()): - user_ = User(username=form1.cleaned_data['username'], email=form1.cleaned_data['email']) - user_.email_isvalid = request.session.get('auth_validated_email', '') == form1.cleaned_data['email'] - user_.set_unusable_password() - - user_.save() - - if not user_.email_isvalid: - send_validation_email(user_) - - try: - assoc_key = request.session['assoc_key'] - auth_provider = request.session['auth_provider'] - except: - request.session['auth_error'] = _("Oops, something went wrong in the middle of this process. Please try again.") - return HttpResponseRedirect(request.session.get('on_signin_url', reverse('user_signin'))) - - uassoc = AuthKeyUserAssociation(user=user_, key=request.session['assoc_key'], provider=request.session['auth_provider']) - uassoc.save() - - email_feeds_form.save(user_) - - del request.session['assoc_key'] - del request.session['auth_provider'] - - if user_.email_isvalid: - return login_and_forward(request, user_) - else: - return HttpResponseRedirect(reverse('index')) - else: - provider_class = AUTH_PROVIDERS[request.session['auth_provider']].consumer - user_data = provider_class.get_user_data(request.session['assoc_key']) - - username = user_data.get('username', '') - email = user_data.get('email', '') - - if not email: - email = request.session.get('auth_email_request', '') - - if email: - request.session['auth_validated_email'] = email - - form1 = SimpleRegistrationForm(initial={ - 'next': '/', - 'username': username, - 'email': email, - }) - email_feeds_form = SimpleEmailSubscribeForm() - - provider_context = AUTH_PROVIDERS[request.session['auth_provider']].context - - return render_to_response('auth/complete.html', { - 'form1': form1, - 'email_feeds_form': email_feeds_form, - 'provider':mark_safe(provider_context.human_name), - 'login_type':provider_context.id, - 'gravatar_faq_url':reverse('faq') + '#gravatar', - }, context_instance=RequestContext(request)) - -def request_temp_login(request): - if request.method == 'POST': - form = TemporaryLoginRequestForm(request.POST) - - if form.is_valid(): - user = form.user_cache - - try: - hash = get_object_or_404(ValidationHash, user=user, type='templogin') - if hash.expiration < datetime.datetime.now(): - hash.delete() - return request_temp_login(request) - except: - hash = ValidationHash.objects.create_new(user, 'templogin', [user.id]) - - send_email(_("Temporary login link"), [user.email], "auth/temp_login_email.html", { - 'temp_login_code': hash, - 'user': user - }) - - request.user.message_set.create(message=_("An email has been sent with your temporary login key")) - - return HttpResponseRedirect(reverse('index')) - else: - form = TemporaryLoginRequestForm() - - return render_to_response( - 'auth/temp_login_request.html', {'form': form}, - context_instance=RequestContext(request)) - -def temp_signin(request, user, code): - user = get_object_or_404(User, id=user) - - if (ValidationHash.objects.validate(code, user, 'templogin', [user.id])): - return login_and_forward(request, user, reverse('user_authsettings'), - _("You are logged in with a temporary access key, please take the time to fix your issue with authentication.")) - else: - raise Http404() - -def send_validation_email(user): - hash = ValidationHash.objects.create_new(user, 'email', [user.email]) - send_email(_("Email Validation"), [user.email], "auth/email_validation.html", { - 'validation_code': hash, - 'user': user - }) - -def validate_email(request, user, code): - user = get_object_or_404(User, id=user) - - if (ValidationHash.objects.validate(code, user, 'email', [user.email])): - user.email_isvalid = True - user.save() - return login_and_forward(request, user, None, _("Thank you, your email is now validated.")) - else: - raise Http404() - -@login_required -def auth_settings(request): - """ - change password view. - - url : /changepw/ - template: authopenid/changepw.html - """ - user_ = request.user - auth_keys = user_.auth_keys.all() - - if user_.has_usable_password(): - FormClass = ChangePasswordForm - else: - FormClass = SetPasswordForm - - if request.POST: - form = FormClass(request.POST, user=user_) - if form.is_valid(): - if user_.has_usable_password(): - request.user.message_set.create(message=_("Your password was changed")) - else: - request.user.message_set.create(message=_("New password set")) - form = ChangePasswordForm(user=user_) - - user_.set_password(form.cleaned_data['password1']) - user_.save() - return HttpResponseRedirect(reverse('user_authsettings')) - else: - form = FormClass(user=user_) - - auth_keys_list = [] - - for k in auth_keys: - provider = AUTH_PROVIDERS.get(k.provider, None) - - if provider is not None: - name = "%s: %s" % (provider.context.human_name, provider.context.readable_key(k)) - else: - from forum.authentication.base import ConsumerTemplateContext - "unknown: %s" % ConsumerTemplateContext.readable_key(k) - - auth_keys_list.append({ - 'name': name, - 'id': k.id - }) - - return render_to_response('auth/auth_settings.html', { - 'form': form, - 'has_password': user_.has_usable_password(), - 'auth_keys': auth_keys_list, - }, context_instance=RequestContext(request)) - -def remove_external_provider(request, id): - association = get_object_or_404(AuthKeyUserAssociation, id=id) - request.user.message_set.create(message=_("You removed the association with %s") % association.provider) - association.delete() - return HttpResponseRedirect(reverse('user_authsettings')) - -def newquestion_signin_action(user): - question = Question.objects.filter(author=user).order_by('-added_at')[0] - return question.get_absolute_url() - -def newanswer_signin_action(user): - answer = Answer.objects.filter(author=user).order_by('-added_at')[0] - return answer.get_absolute_url() - -POST_SIGNIN_ACTIONS = { - 'newquestion': newquestion_signin_action, - 'newanswer': newanswer_signin_action, -} - -def login_and_forward(request, user, forward=None, message=None): - old_session = request.session.session_key - user.backend = "django.contrib.auth.backends.ModelBackend" - login(request, user) - - from forum.models import user_logged_in - user_logged_in.send(user=user,session_key=old_session,sender=None) - - if not forward: - signin_action = request.session.get('on_signin_action', None) - if not signin_action: - forward = request.session.get('on_signin_url', None) - - if not forward: - forward = reverse('index') - else: - try: - forward = POST_SIGNIN_ACTIONS[signin_action](user) - except: - forward = reverse('index') - - if message is None: - message = _("Welcome back %s, you are now logged in") % user.username - - request.user.message_set.create(message=message) - return HttpResponseRedirect(forward) - -@login_required -def signout(request): - """ - signout from the website. Remove openid from session and kill it. - - url : /signout/" - """ - - logout(request) - return HttpResponseRedirect(reverse('index')) |