request token takes username or email now
This commit is contained in:
parent
657ecdf9f0
commit
258675f9eb
1 changed files with 45 additions and 43 deletions
|
@ -226,37 +226,36 @@ def resetPassword(request):
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(resetPassword)
|
actions.register(resetPassword)
|
||||||
|
|
||||||
class RecoverForm(forms.Form):
|
|
||||||
username_or_email = forms.TextInput()
|
|
||||||
|
|
||||||
def requestToken(request):
|
def requestToken(request):
|
||||||
'''
|
'''
|
||||||
param data {
|
param data {
|
||||||
username_or_email: username
|
username: username,
|
||||||
|
email: email
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: {'code': int, 'text': string}
|
status: {'code': int, 'text': string}
|
||||||
data: {
|
data: {
|
||||||
errors: {
|
errors: {
|
||||||
username_or_email: 'Username or email address not found'
|
username: 'Unknown Username'
|
||||||
|
email: 'Unknown Email'
|
||||||
}
|
}
|
||||||
username: user
|
username: user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
form = RegisterForm(data, request.FILES)
|
|
||||||
if form.is_valid():
|
|
||||||
username = data['username_or_email']
|
|
||||||
user = None
|
user = None
|
||||||
q = models.User.objects.filter(username=username)
|
if 'username' in data:
|
||||||
if q.count() > 0:
|
try:
|
||||||
user = q[0]
|
user = models.User.objects.get(username=data['username'])
|
||||||
else:
|
except models.User.DoesNotExist:
|
||||||
q = models.User.objects.filter(email=username)
|
user = None
|
||||||
if q.count() > 0:
|
elif 'email' in data:
|
||||||
user = q[0]
|
try:
|
||||||
|
user = models.User.objects.get(email=data['email'])
|
||||||
|
except models.User.DoesNotExist:
|
||||||
|
user = None
|
||||||
if user:
|
if user:
|
||||||
while True:
|
while True:
|
||||||
token = ox.to32(random.randint(32768, 1048575))
|
token = ox.to32(random.randint(32768, 1048575))
|
||||||
|
@ -277,13 +276,16 @@ def requestToken(request):
|
||||||
user.email_user(subject, message)
|
user.email_user(subject, message)
|
||||||
response = json_response({
|
response = json_response({
|
||||||
'username': user.username
|
'username': user.username
|
||||||
}, text='recover email sent')
|
}, text='password reset email sent')
|
||||||
else:
|
else:
|
||||||
response = json_response({
|
response = json_response({
|
||||||
'errors': {
|
'errors': {
|
||||||
'username_or_email': 'Username or email address not found'
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if 'username' in data:
|
||||||
|
response['data']['errors']['username'] = 'Unknown Username'
|
||||||
|
elif 'email' in data:
|
||||||
|
response['data']['errors']['email'] = 'Unknown Email'
|
||||||
else:
|
else:
|
||||||
response = json_response(status=400, text='invalid data')
|
response = json_response(status=400, text='invalid data')
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
|
|
Loading…
Reference in a new issue