mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-05 16:58:59 +00:00

* master: (589 commits) Adding delete user flow. About time, since I'm sick of doing this myself. Deractivating premiums. Adding a lock for the intelligence slider for focus stories. If the user selects focus and there are actually focus stories, lock it for the future when there are no unread focus stories. Uppiung the find next unread story titles page limit from 12 to 50. Hiding folders with no unread stories in Unread/Focus mode. Adding autocomplete to emailing a story dialog. Using queue for scheduling feed fetches on load. Renaming celerybeat supervisor task. Fixing insta-fetching. Attempting to correctly save duplicate feeds. Adding tons of logging (especially user-facing) to feed exception handling. Much much better feed address and link fetch history. New enterprise ios build includes full training. Changing intelligence training on social feeds to apply to original feed as well. Using a popover for training on the iPad. Also adding the train button to the bottom of every story. Finishing training on iPad. Works in river too. Just need to test social and it's shipping. Fixing title selectin bug when the title was too short to register the selection loupe. Training feeds and stories in feeds. Needs testing on ipad, in river, and on social. Finish look and feel of ios training for both story and feed. Just need to send requests, redraw intelligence, recount and reclassify stories, and update scores. All already written to support inline training. A few more log color tweaks. Adding clean stories task. Updating log colors. ... Conflicts: .gitignore apps/reader/views.py apps/social/views.py templates/social/social_page.xhtml templates/social/social_story.xhtml templates/social/story_comments.xhtml
145 lines
No EOL
6.4 KiB
Python
145 lines
No EOL
6.4 KiB
Python
import datetime
|
|
from django import forms
|
|
from django.utils.translation import ugettext_lazy as _
|
|
from django.contrib.auth.models import User
|
|
from django.contrib.auth import authenticate
|
|
from django.db.models import Q
|
|
from apps.reader.models import Feature
|
|
from apps.profile.tasks import EmailNewUser
|
|
from apps.social.models import MActivity
|
|
from utils import log as logging
|
|
|
|
class LoginForm(forms.Form):
|
|
username = forms.CharField(label=_("Username or Email"), max_length=30,
|
|
widget=forms.TextInput(attrs={'tabindex': 1, 'class': 'NB-input'}),
|
|
error_messages={'required': 'Please enter a username.'})
|
|
password = forms.CharField(label=_("Password"),
|
|
widget=forms.PasswordInput(attrs={'tabindex': 2, 'class': 'NB-input'}),
|
|
required=False)
|
|
# error_messages={'required': 'Please enter a password.'})
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
self.user_cache = None
|
|
super(LoginForm, self).__init__(*args, **kwargs)
|
|
|
|
def clean(self):
|
|
username = self.cleaned_data.get('username', '').lower()
|
|
password = self.cleaned_data.get('password', '')
|
|
|
|
user = User.objects.filter(Q(username__iexact=username) | Q(email=username))
|
|
if username and user:
|
|
self.user_cache = authenticate(username=user[0].username, password=password)
|
|
if self.user_cache is None:
|
|
self.user_cache = authenticate(username=user[0].username, password="")
|
|
if self.user_cache is None:
|
|
email_username = User.objects.filter(email=username)
|
|
if email_username:
|
|
self.user_cache = authenticate(username=email_username[0].username, password=password)
|
|
if self.user_cache is None:
|
|
self.user_cache = authenticate(username=email_username[0].username, password="")
|
|
if self.user_cache is None:
|
|
# logging.info(" ***> [%s] Bad Login: TRYING JK-LESS PASSWORD" % username)
|
|
jkless_password = password.replace('j', '').replace('k', '')
|
|
self.user_cache = authenticate(username=username, password=jkless_password)
|
|
if self.user_cache is None:
|
|
logging.info(" ***> [%s] Bad Login" % username)
|
|
raise forms.ValidationError(_("Whoopsy-daisy. Try again."))
|
|
else:
|
|
# Supreme fuck-up. Accidentally removed the letters J and K from
|
|
# all user passwords. Re-save with correct password.
|
|
logging.info(" ***> [%s] FIXING JK-LESS PASSWORD" % username)
|
|
self.user_cache.set_password(password)
|
|
self.user_cache.save()
|
|
if not self.user_cache.is_active:
|
|
raise forms.ValidationError(_("This account is inactive."))
|
|
elif username and not user:
|
|
raise forms.ValidationError(_("That username is not registered. Please try again."))
|
|
|
|
return self.cleaned_data
|
|
|
|
def get_user_id(self):
|
|
if self.user_cache:
|
|
return self.user_cache.id
|
|
return None
|
|
|
|
def get_user(self):
|
|
return self.user_cache
|
|
|
|
|
|
class SignupForm(forms.Form):
|
|
username = forms.RegexField(regex=r'^\w+$',
|
|
max_length=30,
|
|
widget=forms.TextInput(attrs={'class': 'NB-input'}),
|
|
label=_(u'username'),
|
|
error_messages={
|
|
'required': 'Please enter a username.',
|
|
'invalid': "Your username may only contain letters and numbers."
|
|
})
|
|
email = forms.EmailField(widget=forms.TextInput(attrs={'maxlength': 75, 'class': 'NB-input'}),
|
|
label=_(u'email address'),
|
|
required=False)
|
|
# error_messages={'required': 'Please enter your email.'})
|
|
password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'NB-input'}),
|
|
label=_(u'password'),
|
|
required=False)
|
|
# error_messages={'required': 'Please enter a password.'})
|
|
|
|
def clean_username(self):
|
|
username = self.cleaned_data['username']
|
|
return username
|
|
|
|
def clean_password(self):
|
|
if not self.cleaned_data['password']:
|
|
return ""
|
|
return self.cleaned_data['password']
|
|
|
|
def clean_email(self):
|
|
if not self.cleaned_data['email']:
|
|
return ""
|
|
return self.cleaned_data['email']
|
|
|
|
def clean(self):
|
|
username = self.cleaned_data.get('username', '')
|
|
password = self.cleaned_data.get('password', '')
|
|
exists = User.objects.filter(username__iexact=username).count()
|
|
if exists:
|
|
user_auth = authenticate(username=username, password=password)
|
|
if not user_auth:
|
|
raise forms.ValidationError(_(u'Someone is already using that username.'))
|
|
return self.cleaned_data
|
|
|
|
def save(self, profile_callback=None):
|
|
username = self.cleaned_data['username']
|
|
password = self.cleaned_data['password']
|
|
|
|
exists = User.objects.filter(username__iexact=username).count()
|
|
if exists:
|
|
user_auth = authenticate(username=username, password=password)
|
|
if not user_auth:
|
|
raise forms.ValidationError(_(u'Someone is already using that username.'))
|
|
else:
|
|
return user_auth
|
|
|
|
new_user = User(username=username)
|
|
new_user.set_password(password)
|
|
new_user.is_active = True
|
|
new_user.email = self.cleaned_data['email']
|
|
new_user.save()
|
|
new_user = authenticate(username=username,
|
|
password=password)
|
|
|
|
MActivity.new_signup(user_id=new_user.pk)
|
|
|
|
if new_user.email:
|
|
EmailNewUser.delay(user_id=new_user.pk)
|
|
|
|
return new_user
|
|
|
|
class FeatureForm(forms.Form):
|
|
description = forms.CharField(required=True)
|
|
|
|
def save(self):
|
|
feature = Feature(description=self.cleaned_data['description'],
|
|
date=datetime.datetime.utcnow() + datetime.timedelta(minutes=1))
|
|
feature.save()
|
|
return feature |