Skip to content
This repository has been archived by the owner on Aug 4, 2018. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Fingercomp committed Oct 3, 2016
2 parents 2fdb546 + dd50f04 commit 7aaf1bf
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 66 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.7.1
-----
- Removed ``passwd-confirm`` param.

0.7.0
-----
- Made the /auth view process ``application/json`` instead of ``application/x-www-form-urlencoded`` (that was illogical).
Expand Down
4 changes: 0 additions & 4 deletions hel/templates/home.pt
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@
<div class="col-sm-2" style="padding-left: 0px;">
<input name="password" type="password" id="reg-email" class="form-control input-lg" placeholder="Password" required>
</div>
<label for="reg-passwd-confirm" class="sr-only">Password confirmation</label>
<div class="col-sm-2" style="padding-left: 0px;">
<input name="passwd-confirm" type="password" id="reg-email" class="form-control input-lg" placeholder="Password confirmation" required>
</div>
<button name="register" type="submit" class="btn btn-lg btn-danger">Register</button>
<button class="btn btn-lg" onclick="switchTo('main')">Back</button>
</form>
Expand Down
26 changes: 8 additions & 18 deletions hel/tests/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def test_bad_reg(self):
res = self.test_app.post('/', {
'email': '',
'nickname': '',
'passwd-confirm': '',
'register': True
}, status=200)
message = res.html.find(id='login-message')
Expand All @@ -109,7 +108,6 @@ def test_failed_reg_empty_nick(self):
'email': '',
'nickname': '',
'password': '',
'passwd-confirm': '',
'register': True
}, status=200)
message = res.html.find(id='login-message')
Expand All @@ -121,7 +119,6 @@ def test_failed_reg_empty_email(self):
'email': '',
'nickname': self.user['nickname'],
'password': '',
'passwd-confirm': '',
'register': True
}, status=200)
message = res.html.find(id='login-message')
Expand All @@ -133,27 +130,24 @@ def test_failed_reg_empty_password(self):
'email': self.user['email'],
'nickname': self.user['nickname'],
'password': '',
'passwd-confirm': '',
'register': True
}, status=200)
message = res.html.find(id='login-message')
self.assertIsNotNone(message)
self.assertEqual(message.string, Messages.empty_password)

def test_failed_reg_nick_use(self):
data = copy.copy(self.user)
data['register'] = True
data['passwd-confirm'] = 'hi'
res = self.test_app.post('/', data, status=200)
self.assertIsNone(res.html.find(id='log-out'))
message = res.html.find(id='login-message')
self.assertIsNotNone(message)
self.assertEqual(message.string, Messages.password_mismatch)
# def test_failed_reg_nick_use(self):
# data = copy.copy(self.user)
# data['register'] = True
# res = self.test_app.post('/', data, status=200)
# self.assertIsNone(res.html.find(id='log-out'))
# message = res.html.find(id='login-message')
# self.assertIsNotNone(message)
# self.assertEqual(message.string, Messages.password_mismatch)

def test_reg_success(self):
data = copy.copy(self.user)
data['register'] = True
data['passwd-confirm'] = data['password']
res = self.test_app.post('/', data, status=200)
message = res.html.find(id='login-message')
self.assertIsNotNone(message)
Expand Down Expand Up @@ -214,7 +208,6 @@ def setUp(self):
FunctionalAuthTests.setUp(self)
data = copy.copy(self.user)
data['register'] = True
data['passwd-confirm'] = data['password']
res = self.test_app.post('/', data, status=200)
message = res.html.find(id='login-message')
self.assertIsNotNone(message)
Expand Down Expand Up @@ -333,7 +326,6 @@ def setUp(self):
FunctionalAuthTests.setUp(self)
data = copy.copy(self.user)
data['register'] = True
data['passwd-confirm'] = data['password']
res = self.test_app.post('/', data, status=200)
message = res.html.find(id='login-message')
self.assertIsNotNone(message)
Expand All @@ -349,7 +341,6 @@ def test_failed_reg_nick_use(self):
'nickname': 'root',
'email': 'asd',
'password': '...',
'passwd-confirm': '...',
'register': True
}, status=200)
self.assertIsNone(res.html.find(id='log-out'))
Expand All @@ -362,7 +353,6 @@ def test_failed_reg_email_use(self):
'nickname': 'root2',
'email': '[email protected]',
'password': '...',
'passwd-confirm': '...',
'register': True
}, status=200)
self.assertIsNone(res.html.find(id='log-out'))
Expand Down
2 changes: 1 addition & 1 deletion hel/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json


VERSION = '0.7.0'
VERSION = '0.7.1'


def parse_search_phrase(s):
Expand Down
81 changes: 38 additions & 43 deletions hel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ def auth(request):
nickname = params['nickname'].strip()
email = params['email'].strip()
password = params['password'].strip()
passwd_confirm = params['passwd-confirm'].strip()
except (KeyError, AttributeError):
message = Messages.bad_request
else:
Expand All @@ -158,46 +157,43 @@ def auth(request):
if user:
message = Messages.email_in_use
else:
if password != passwd_confirm:
message = Messages.password_mismatch
else:
act_phrase = ''.join(
'{:02x}'.format(x) for x in os.urandom(
request.registry.settings
['activation.length']))
act_till = (datetime.datetime.now() +
datetime.timedelta(
seconds=request.registry.settings
['activation.time']))
subrequest = Request.blank(
'/users', method='POST', POST=(
str(ModelUser(nickname=nickname,
email=email,
password=pass_hash,
activation_phrase=act_phrase,
activation_till=act_till))),
content_type='application/json')
subrequest.no_permission_check = True
response = request.invoke_subrequest(
subrequest, use_tweens=True)
if response.status_code == 201:
# TODO: send activation email
request.response.status = '200 OK'
return {'message':
Messages.account_created_success,
'code': 200,
'title': 'OK',
'success': True}
else: # pragma: no cover
message = Messages.internal_error
log.error(
'Could not create a user: subrequest'
' returned with status code %s!\n'
'Local variables in frame:%s',
response.status_code,
''.join(['\n * ' + str(x) + ' = ' + str(y)
for x, y in locals().items()])
)
act_phrase = ''.join(
'{:02x}'.format(x) for x in os.urandom(
request.registry.settings
['activation.length']))
act_till = (datetime.datetime.now() +
datetime.timedelta(
seconds=request.registry.settings
['activation.time']))
subrequest = Request.blank(
'/users', method='POST', POST=(
str(ModelUser(nickname=nickname,
email=email,
password=pass_hash,
activation_phrase=act_phrase,
activation_till=act_till))),
content_type='application/json')
subrequest.no_permission_check = True
response = request.invoke_subrequest(
subrequest, use_tweens=True)
if response.status_code == 201:
# TODO: send activation email
request.response.status = '200 OK'
return {'message':
Messages.account_created_success,
'code': 200,
'title': 'OK',
'success': True}
else: # pragma: no cover
message = Messages.internal_error
log.error(
'Could not create a user: subrequest'
' returned with status code %s!\n'
'Local variables in frame:%s',
response.status_code,
''.join(['\n * ' + str(x) + ' = ' + str(y)
for x, y in locals().items()])
)
jexc(HTTPBadRequest, message)


Expand Down Expand Up @@ -440,8 +436,7 @@ def delete_package(context, request):
context.delete()

return Response(
status='204 No Content',
content_type='application/json')
status='204 No Content')


@view_config(request_method='POST',
Expand Down

1 comment on commit 7aaf1bf

@Fingercomp
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.