pyramid-fullauth 0.3.2__py2.7.egg → 0.6.0__py2.7.egg

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. EGG-INFO/PKG-INFO +53 -11
  2. EGG-INFO/SOURCES.txt +4 -0
  3. EGG-INFO/requires.txt +11 -10
  4. pyramid_fullauth/__init__.py +4 -4
  5. pyramid_fullauth/__init__.pyc +0 -0
  6. pyramid_fullauth/auth.py +5 -4
  7. pyramid_fullauth/auth.pyc +0 -0
  8. pyramid_fullauth/compat.py +20 -0
  9. pyramid_fullauth/compat.pyc +0 -0
  10. pyramid_fullauth/config/default.yaml +1 -1
  11. pyramid_fullauth/events.py +1 -20
  12. pyramid_fullauth/events.pyc +0 -0
  13. pyramid_fullauth/exceptions.py +1 -7
  14. pyramid_fullauth/exceptions.pyc +0 -0
  15. pyramid_fullauth/models/__init__.py +7 -8
  16. pyramid_fullauth/models/__init__.pyc +0 -0
  17. pyramid_fullauth/models/extensions/__init__.py +38 -0
  18. pyramid_fullauth/models/extensions/__init__.pyc +0 -0
  19. pyramid_fullauth/models/mixins/__init__.py +3 -2
  20. pyramid_fullauth/models/mixins/__init__.pyc +0 -0
  21. pyramid_fullauth/models/mixins/email.py +58 -10
  22. pyramid_fullauth/models/mixins/email.pyc +0 -0
  23. pyramid_fullauth/models/mixins/password.py +5 -11
  24. pyramid_fullauth/models/mixins/password.pyc +0 -0
  25. pyramid_fullauth/request.py +6 -5
  26. pyramid_fullauth/request.pyc +0 -0
  27. pyramid_fullauth/resources/helpers/social.mako +3 -3
  28. pyramid_fullauth/resources/locale/pyramid_fullauth.pot +23 -23
  29. pyramid_fullauth/resources/templates/403.mako +1 -1
  30. pyramid_fullauth/resources/templates/_form.login.mako +1 -1
  31. pyramid_fullauth/resources/templates/_form.register.mako +1 -1
  32. pyramid_fullauth/resources/templates/_social.login.mako +1 -1
  33. pyramid_fullauth/resources/templates/activate.mako +1 -1
  34. pyramid_fullauth/resources/templates/email_change.mako +1 -1
  35. pyramid_fullauth/resources/templates/layout.mako +1 -1
  36. pyramid_fullauth/resources/templates/login.mako +1 -1
  37. pyramid_fullauth/resources/templates/register.mako +1 -1
  38. pyramid_fullauth/resources/templates/reset.mako +1 -1
  39. pyramid_fullauth/resources/templates/reset.proceed.mako +1 -1
  40. pyramid_fullauth/routing/__init__.py +1 -1
  41. pyramid_fullauth/routing/__init__.pyc +0 -0
  42. pyramid_fullauth/routing/predicates.py +4 -3
  43. pyramid_fullauth/routing/predicates.pyc +0 -0
  44. pyramid_fullauth/tools.py +7 -4
  45. pyramid_fullauth/tools.pyc +0 -0
  46. pyramid_fullauth/views/__init__.py +2 -3
  47. pyramid_fullauth/views/__init__.pyc +0 -0
  48. pyramid_fullauth/views/basic/__init__.py +1 -1
  49. pyramid_fullauth/views/basic/__init__.pyc +0 -0
  50. pyramid_fullauth/views/basic/activate.py +1 -2
  51. pyramid_fullauth/views/basic/activate.pyc +0 -0
  52. pyramid_fullauth/views/basic/forbidden.py +3 -5
  53. pyramid_fullauth/views/basic/forbidden.pyc +0 -0
  54. pyramid_fullauth/views/basic/login.py +28 -34
  55. pyramid_fullauth/views/basic/login.pyc +0 -0
  56. pyramid_fullauth/views/basic/logout.py +1 -2
  57. pyramid_fullauth/views/basic/logout.pyc +0 -0
  58. pyramid_fullauth/views/basic/profile/__init__.py +1 -1
  59. pyramid_fullauth/views/basic/profile/__init__.pyc +0 -0
  60. pyramid_fullauth/views/basic/profile/email.py +44 -37
  61. pyramid_fullauth/views/basic/profile/email.pyc +0 -0
  62. pyramid_fullauth/views/basic/profile/password.py +6 -7
  63. pyramid_fullauth/views/basic/profile/password.pyc +0 -0
  64. pyramid_fullauth/views/basic/register.py +53 -27
  65. pyramid_fullauth/views/basic/register.pyc +0 -0
  66. pyramid_fullauth/views/social.py +7 -5
  67. pyramid_fullauth/views/social.pyc +0 -0
  68. tests/__init__.pyc +0 -0
  69. tests/conftest.py +23 -10
  70. tests/conftest.pyc +0 -0
  71. tests/tools.pyc +0 -0
  72. tests/unit/test_default_settings.pyc +0 -0
  73. tests/unit/test_groupfinder.pyc +0 -0
  74. tests/unit/test_social_view.py +28 -26
  75. tests/unit/test_social_view.pyc +0 -0
  76. tests/unit/test_tools.pyc +0 -0
  77. tests/unit/test_user_active.pyc +0 -0
  78. tests/unit/test_user_admin.pyc +0 -0
  79. tests/unit/test_user_email.pyc +0 -0
  80. tests/unit/test_user_password.py +1 -1
  81. tests/unit/test_user_password.pyc +0 -0
  82. tests/unit/test_user_providers.pyc +0 -0
  83. tests/unit/test_user_repr.py +4 -4
  84. tests/unit/test_user_repr.pyc +0 -0
  85. tests/unit/test_validators.py +1 -1
  86. tests/unit/test_validators.pyc +0 -0
  87. tests/views/__init__.pyc +0 -0
  88. tests/views/conftest.py +5 -0
  89. tests/views/conftest.pyc +0 -0
  90. tests/views/test_activation.py +13 -6
  91. tests/views/test_activation.pyc +0 -0
  92. tests/views/test_email.py +2 -2
  93. tests/views/test_email.pyc +0 -0
  94. tests/views/test_events.py +107 -49
  95. tests/views/test_events.pyc +0 -0
  96. tests/views/test_login.py +23 -2
  97. tests/views/test_login.pyc +0 -0
  98. tests/views/test_login_social.py +97 -69
  99. tests/views/test_login_social.pyc +0 -0
  100. tests/views/test_logout.pyc +0 -0
  101. tests/views/test_register.py +9 -5
  102. tests/views/test_register.pyc +0 -0
  103. tests/views/test_reset.py +9 -4
  104. tests/views/test_reset.pyc +0 -0
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2013 - 2014 by pyramid_fullauth authors and contributors <see AUTHORS file>
1
+ # Copyright (c) 2013 - 2016 by pyramid_fullauth authors and contributors <see AUTHORS file>
2
2
  #
3
3
  # This module is part of pyramid_fullauth and is released under
4
4
  # the MIT License (MIT): http://opensource.org/licenses/MIT
@@ -7,10 +7,10 @@
7
7
  from pyramid.view import view_config
8
8
  from pyramid.view import view_defaults
9
9
  from pyramid.httpexceptions import HTTPSeeOther, HTTPRedirection
10
- from pyramid.security import authenticated_userid
11
10
  from pyramid.security import NO_PERMISSION_REQUIRED
12
11
 
13
12
  from sqlalchemy.orm.exc import NoResultFound
13
+ from pyramid.compat import text_type
14
14
  import pyramid_basemodel
15
15
 
16
16
  from pyramid_fullauth.views import BaseView
@@ -23,7 +23,6 @@ from pyramid_fullauth.events import AlreadyLoggedIn
23
23
  @view_defaults(route_name='login', permission=NO_PERMISSION_REQUIRED,
24
24
  renderer='pyramid_fullauth:resources/templates/login.mako')
25
25
  class BaseLoginView(BaseView):
26
-
27
26
  """Basic logic for login views."""
28
27
 
29
28
  def __init__(self, request):
@@ -43,8 +42,8 @@ class BaseLoginView(BaseView):
43
42
  redirect = HTTPSeeOther(location=self.response['after'])
44
43
  try:
45
44
  self.request.registry.notify(AlreadyLoggedIn(self.request))
46
- except HTTPRedirection as redirect:
47
- pass
45
+ except HTTPRedirection as e_redirect:
46
+ redirect = e_redirect
48
47
 
49
48
  if self.request.is_xhr:
50
49
  self.response['status'] = True
@@ -59,12 +58,11 @@ class BaseLoginView(BaseView):
59
58
 
60
59
  @view_config(request_method='GET')
61
60
  class LoginView(BaseLoginView):
62
-
63
61
  """Login view."""
64
62
 
65
63
  def __call__(self):
66
64
  """Display login page."""
67
- if authenticated_userid(self.request):
65
+ if self.request.authenticated_userid:
68
66
  return self._redirect_authenticated_user()
69
67
 
70
68
  self.request.registry.notify(BeforeLogIn(self.request, None))
@@ -77,52 +75,48 @@ class LoginView(BaseLoginView):
77
75
  @view_config(request_method='POST', check_csrf=True)
78
76
  @view_config(request_method='POST', check_csrf=True, xhr=True, renderer="json")
79
77
  class LoginViewPost(BaseLoginView):
80
-
81
78
  """Login view POST method."""
82
79
 
83
80
  def __call__(self):
84
81
  """Login action."""
85
- if authenticated_userid(self.request):
82
+ if self.request.authenticated_userid:
86
83
  return self._redirect_authenticated_user()
87
84
 
88
85
  email = self.request.POST.get('email', '')
89
86
  password = self.request.POST.get('password', '')
90
87
  try:
91
88
  user = pyramid_basemodel.Session.query(User).filter(User.email == email).one()
89
+ self.request.registry.notify(BeforeLogIn(self.request, user))
92
90
  except NoResultFound:
93
91
  self.request.registry.notify(BeforeLogIn(self.request, None))
94
92
 
95
93
  self.response['msg'] = self.request._('Wrong e-mail or password.',
96
94
  domain='pyramid_fullauth')
97
95
  return self.response
98
-
99
- try:
100
- self.request.registry.notify(BeforeLogIn(self.request, user))
101
96
  except AttributeError as e:
102
- self.response['msg'] = str(e)
97
+ self.response['msg'] = text_type(e)
103
98
  return self.response
104
99
 
105
- if user.check_password(password):
106
-
107
- login_kwargs = {'remember_me': self.request.POST.get('remember')}
108
- try:
109
- # if remember in POST set cookie timeout to one month
110
- self.request.registry.notify(AfterLogIn(self.request, user))
111
- except AttributeError as e:
112
- self.response['msg'] = str(e)
113
- return self.response
114
- except HTTPRedirection as redirect:
115
- login_kwargs['location'] = redirect.location
116
-
117
- redirect = self.request.login_perform(user, **login_kwargs)
118
- if self.request.is_xhr:
119
- self.response['status'] = True
120
- del self.response['msg']
121
- self.response['after'] = redirect.location
122
- return self.response
123
- else:
124
- return redirect
125
- else:
100
+ if not user.check_password(password):
126
101
  self.response['msg'] = self.request._('Wrong e-mail or password.',
127
102
  domain='pyramid_fullauth')
128
103
  return self.response
104
+
105
+ login_kwargs = {'remember_me': self.request.POST.get('remember')}
106
+ try:
107
+ # if remember in POST set cookie timeout to one month
108
+ self.request.registry.notify(AfterLogIn(self.request, user))
109
+ except AttributeError as e:
110
+ self.response['msg'] = text_type(e)
111
+ return self.response
112
+ except HTTPRedirection as redirect:
113
+ login_kwargs['location'] = redirect.location
114
+
115
+ redirect = self.request.login_perform(user, **login_kwargs)
116
+ if self.request.is_xhr:
117
+ self.response['status'] = True
118
+ del self.response['msg']
119
+ self.response['after'] = redirect.location
120
+ return self.response
121
+
122
+ return redirect
Binary file
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2013 - 2014 by pyramid_fullauth authors and contributors <see AUTHORS file>
1
+ # Copyright (c) 2013 - 2016 by pyramid_fullauth authors and contributors <see AUTHORS file>
2
2
  #
3
3
  # This module is part of pyramid_fullauth and is released under
4
4
  # the MIT License (MIT): http://opensource.org/licenses/MIT
@@ -13,7 +13,6 @@ from pyramid_fullauth.views import BaseView
13
13
 
14
14
  @view_config(route_name='logout', permission=NO_PERMISSION_REQUIRED)
15
15
  class LogoutView(BaseView):
16
-
17
16
  """Logout view."""
18
17
 
19
18
  def __call__(self):
Binary file
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2013 - 2014 by pyramid_fullauth authors and contributors <see AUTHORS file>
1
+ # Copyright (c) 2013 - 2016 by pyramid_fullauth authors and contributors <see AUTHORS file>
2
2
  #
3
3
  # This module is part of pyramid_fullauth and is released under
4
4
  # the MIT License (MIT): http://opensource.org/licenses/MIT
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2013 - 2014 by pyramid_fullauth authors and contributors <see AUTHORS file>
1
+ # Copyright (c) 2013 - 2016 by pyramid_fullauth authors and contributors <see AUTHORS file>
2
2
  #
3
3
  # This module is part of pyramid_fullauth and is released under
4
4
  # the MIT License (MIT): http://opensource.org/licenses/MIT
@@ -8,7 +8,7 @@ from pyramid.view import view_config, view_defaults
8
8
  from pyramid.httpexceptions import HTTPRedirection, HTTPSeeOther
9
9
  from pyramid.security import NO_PERMISSION_REQUIRED
10
10
 
11
- from sqlalchemy.orm.exc import NoResultFound
11
+ from pyramid.compat import text_type
12
12
  import pyramid_basemodel
13
13
 
14
14
  from pyramid_fullauth.views import BaseView
@@ -23,7 +23,6 @@ from pyramid_fullauth.exceptions import EmptyError, EmailValidationError
23
23
  @view_defaults(route_name='email:change', permission='email_change',
24
24
  renderer='pyramid_fullauth:resources/templates/email_change.mako')
25
25
  class EmailChangeViews(BaseView):
26
-
27
26
  """Email change related views."""
28
27
 
29
28
  @view_config(request_method='GET')
@@ -35,43 +34,14 @@ class EmailChangeViews(BaseView):
35
34
  @view_config(request_method='POST', check_csrf='csrf_token', xhr=True, renderer="json")
36
35
  def post(self):
37
36
  """Process email change request."""
38
- csrf_token = self.request.session.get_csrf_token()
39
- try:
40
- pyramid_basemodel.Session.query(User).filter(
41
- User.email == self.request.POST.get('email', '')
42
- ).one()
43
- return {'status': False,
44
- 'msg': self.request._('User with this email exists',
45
- domain='pyramid_fullauth'),
46
- 'csrf_token': csrf_token}
47
- except NoResultFound:
48
- pass
49
-
50
37
  user = self.request.user
51
- try:
52
- self.request.registry.notify(BeforeEmailChange(self.request, user))
53
- except AttributeError as e:
54
- return {'status': False, 'msg': e.message, 'csrf_token': csrf_token}
55
-
56
- try:
57
- user.set_new_email(self.request.POST.get('email', ''))
58
- except EmptyError:
59
- return {'status': False,
60
- 'msg': self.request._(
61
- 'E-mail is empty',
62
- domain='pyramid_fullauth'),
63
- 'csrf_token': csrf_token}
64
- except EmailValidationError:
65
- return {'status': False,
66
- 'msg': self.request._(
67
- 'Incorrect e-mail format',
68
- domain='pyramid_fullauth'),
69
- 'csrf_token': csrf_token}
38
+ response = self.validate_email(user)
39
+ if response:
40
+ return response
70
41
 
71
42
  response_values = {
72
43
  'status': True,
73
- 'msg': self.request._('We sent you email to activate your new email address',
74
- domain='pyramid_fullauth')
44
+ 'msg': self.request._('We sent you email to activate your new email address', domain='pyramid_fullauth')
75
45
  }
76
46
 
77
47
  try:
@@ -88,11 +58,48 @@ class EmailChangeViews(BaseView):
88
58
  else:
89
59
  return HTTPSeeOther(location='/')
90
60
 
61
+ def validate_email(self, user):
62
+ """
63
+ Validate and set email on a user object.
64
+
65
+ :param pyramid_fullauth.models.User user: user to set an email passed on POST arguments.
66
+
67
+ :returns: response in case of an invalid email, None otherwise
68
+ :rtype: dict
69
+ """
70
+ csrf_token = self.request.session.get_csrf_token()
71
+ email = self.request.POST.get('email', text_type(''))
72
+ if pyramid_basemodel.Session.query(User).filter(User.email == email).first():
73
+ return {
74
+ 'status': False,
75
+ 'msg': self.request._('User with this email exists', domain='pyramid_fullauth'),
76
+ 'csrf_token': csrf_token
77
+ }
78
+
79
+ try:
80
+ self.request.registry.notify(BeforeEmailChange(self.request, user))
81
+ except AttributeError as e:
82
+ return {'status': False, 'msg': text_type(e), 'csrf_token': csrf_token}
83
+
84
+ try:
85
+ user.set_new_email(email)
86
+ except EmptyError:
87
+ return {
88
+ 'status': False,
89
+ 'msg': self.request._('E-mail is empty', domain='pyramid_fullauth'),
90
+ 'csrf_token': csrf_token
91
+ }
92
+ except EmailValidationError:
93
+ return {
94
+ 'status': False,
95
+ 'msg': self.request._('Incorrect e-mail format', domain='pyramid_fullauth'),
96
+ 'csrf_token': csrf_token
97
+ }
98
+
91
99
 
92
100
  @view_config(route_name='email:change:continue', permission=NO_PERMISSION_REQUIRED,
93
101
  renderer='pyramid_fullauth:resources/templates/email_change.mako')
94
102
  class EmailChangeAccept(BaseView):
95
-
96
103
  """Display email change success."""
97
104
 
98
105
  def __call__(self):
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2013 - 2014 by pyramid_fullauth authors and contributors <see AUTHORS file>
1
+ # Copyright (c) 2013 - 2016 by pyramid_fullauth authors and contributors <see AUTHORS file>
2
2
  #
3
3
  # This module is part of pyramid_fullauth and is released under
4
4
  # the MIT License (MIT): http://opensource.org/licenses/MIT
@@ -9,6 +9,7 @@ from pyramid.httpexceptions import HTTPRedirection, HTTPSeeOther
9
9
  from pyramid.security import NO_PERMISSION_REQUIRED
10
10
 
11
11
  from sqlalchemy.orm.exc import NoResultFound
12
+ from pyramid.compat import text_type
12
13
  import pyramid_basemodel
13
14
 
14
15
  from pyramid_fullauth.views import BaseView
@@ -24,7 +25,6 @@ from pyramid_fullauth.tools import validate_passsword
24
25
  @view_defaults(route_name='password:reset', permission=NO_PERMISSION_REQUIRED,
25
26
  renderer='pyramid_fullauth:resources/templates/reset.mako')
26
27
  class PasswordResetView(BaseView):
27
-
28
28
  """Profile related views."""
29
29
 
30
30
  @view_config()
@@ -45,7 +45,7 @@ class PasswordResetView(BaseView):
45
45
  except NoResultFound:
46
46
  return {'status': False,
47
47
  'msg': self.request._('user-not-exists',
48
- default='User does not exists',
48
+ default='User does not exist',
49
49
  domain='pyramid_fullauth'),
50
50
  'csrf_token': csrf_token}
51
51
 
@@ -61,7 +61,6 @@ class PasswordResetView(BaseView):
61
61
  @view_defaults(route_name='password:reset:continue', permission=NO_PERMISSION_REQUIRED,
62
62
  renderer='pyramid_fullauth:resources/templates/reset.proceed.mako')
63
63
  class PasswordResetContinueView(BaseView):
64
-
65
64
  """
66
65
  Password reset views.
67
66
 
@@ -94,12 +93,12 @@ class PasswordResetContinueView(BaseView):
94
93
  try:
95
94
  pyramid_basemodel.Session.query(AuthenticationProvider).filter(
96
95
  AuthenticationProvider.user_id == user.id,
97
- AuthenticationProvider.provider == u'email'
96
+ AuthenticationProvider.provider == text_type('email')
98
97
  ).one()
99
98
  except NoResultFound:
100
99
  user.providers.append(
101
100
  AuthenticationProvider(
102
- provider=u'email',
101
+ provider=text_type('email'),
103
102
  provider_id=user.id
104
103
  )
105
104
  )
@@ -108,7 +107,7 @@ class PasswordResetContinueView(BaseView):
108
107
  except (ValidateError, AttributeError) as e:
109
108
  return {
110
109
  'status': False,
111
- 'msg': str(e),
110
+ 'msg': text_type(e),
112
111
  'csrf_token': self.request.session.get_csrf_token()
113
112
  }
114
113
 
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2013 - 2014 by pyramid_fullauth authors and contributors <see AUTHORS file>
1
+ # Copyright (c) 2013 - 2016 by pyramid_fullauth authors and contributors <see AUTHORS file>
2
2
  #
3
3
  # This module is part of pyramid_fullauth and is released under
4
4
  # the MIT License (MIT): http://opensource.org/licenses/MIT
@@ -8,6 +8,7 @@ from pyramid.view import view_config, view_defaults
8
8
  from pyramid.httpexceptions import HTTPRedirection
9
9
  from pyramid.security import NO_PERMISSION_REQUIRED
10
10
 
11
+ from pyramid.compat import text_type
11
12
  import pyramid_basemodel
12
13
 
13
14
  from pyramid_fullauth.views import BaseView
@@ -20,7 +21,6 @@ from pyramid_fullauth.exceptions import ValidateError
20
21
  @view_defaults(route_name='register', permission=NO_PERMISSION_REQUIRED,
21
22
  renderer="pyramid_fullauth:resources/templates/register.mako")
22
23
  class RegisterView(BaseView):
23
-
24
24
  """Registration views."""
25
25
 
26
26
  @view_config(request_method='GET')
@@ -68,43 +68,69 @@ class RegisterView(BaseView):
68
68
  :returns: response
69
69
  :rtype: dict
70
70
  """
71
- email = self.request.POST.get('email', u'')
71
+ email = self.request.POST.get('email', text_type(''))
72
+ password = self.request.POST.get('password', text_type(''))
72
73
  # here if e-mail is already in database
73
74
 
74
- if pyramid_basemodel.Session.query(User).filter(User.email == email).count() != 0:
75
- response['errors']['email'] = self.request._(
76
- 'User with given e-mail already exists!',
77
- domain='pyramid_fullauth')
78
- try:
79
- try:
80
- user.email = email
81
- except ValidateError as e:
82
- # do not overwrite existing error
83
- if 'email' not in response['errors']:
84
- response['errors']['email'] = str(e)
85
-
86
- if self.config.register.password.require:
87
- try:
88
- tools.validate_passsword(self.request,
89
- self.request.POST.get('password', u''),
90
- user)
91
- except ValidateError as e:
92
- response['errors']['password'] = e.message
93
- else:
94
- user.password = tools.password_generator(
95
- self.config.register.password.length_min)
75
+ email_error = self._set_email(email, user)
76
+ if email_error:
77
+ response['errors']['email'] = email_error
96
78
 
79
+ password_error = self._set_password(password, user)
80
+ if password_error:
81
+ response['errors']['password'] = password_error
82
+
83
+ try:
97
84
  self.request.registry.notify(BeforeRegister(self.request, user, response['errors']))
85
+
98
86
  if not response['errors']:
99
87
  pyramid_basemodel.Session.add(user)
100
88
  pyramid_basemodel.Session.flush()
101
89
 
102
90
  # lets add AuthenticationProvider as email!
103
91
  user.providers.append(
104
- AuthenticationProvider(provider=u'email', provider_id=user.id))
92
+ AuthenticationProvider(provider=text_type('email'), provider_id=user.id))
105
93
  else:
106
94
  return response
107
95
  except AttributeError as e:
108
- response['errors']['msg'] = str(e)
96
+ response['errors']['msg'] = text_type(e)
109
97
 
110
98
  return response
99
+
100
+ def _set_password(self, password, user):
101
+ """
102
+ Set password on a User object.
103
+
104
+ :param str password: email address
105
+ :param pyramid_fullauth.models.User user: user object
106
+
107
+ :returns: error or None if no error occured.
108
+ :rtype: str
109
+ """
110
+ if self.config.register.password.require:
111
+ try:
112
+ tools.validate_passsword(self.request, password, user)
113
+ except ValidateError as e:
114
+ return text_type(e)
115
+ else:
116
+ user.password = tools.password_generator(
117
+ self.config.register.password.length_min)
118
+
119
+ def _set_email(self, email, user):
120
+ """
121
+ Set email on a User object.
122
+
123
+ :param str email: email address
124
+ :param pyramid_fullauth.models.User user: user object
125
+
126
+ :returns: error or None if no error occured.
127
+ :rtype: str
128
+ """
129
+ if pyramid_basemodel.Session.query(User).filter(User.email == email).count() != 0:
130
+ return self.request._('User with given e-mail already exists!', domain='pyramid_fullauth')
131
+
132
+ try:
133
+ user.email = email
134
+ except ValidateError as e:
135
+ # do not overwrite existing error
136
+ return text_type(e)
Binary file
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2013 - 2014 by pyramid_fullauth authors and contributors <see AUTHORS file>
1
+ # Copyright (c) 2013 - 2016 by pyramid_fullauth authors and contributors <see AUTHORS file>
2
2
  #
3
3
  # This module is part of pyramid_fullauth and is released under
4
4
  # the MIT License (MIT): http://opensource.org/licenses/MIT
@@ -11,6 +11,7 @@ from pyramid.security import NO_PERMISSION_REQUIRED
11
11
 
12
12
  from sqlalchemy.orm.exc import NoResultFound
13
13
  from sqlalchemy.exc import IntegrityError
14
+ from pyramid.compat import text_type
14
15
  import pyramid_basemodel
15
16
 
16
17
  from pyramid_fullauth.views import BaseView
@@ -29,7 +30,6 @@ logger = logging.getLogger(__name__)
29
30
  permission=NO_PERMISSION_REQUIRED,
30
31
  renderer="pyramid_fullauth:resources/templates/register.mako")
31
32
  class SocialLoginViews(BaseView):
32
-
33
33
  """Social login views definition."""
34
34
 
35
35
  def set_provider(self, user, provider_name, user_provider_id):
@@ -212,7 +212,9 @@ class SocialLoginViews(BaseView):
212
212
  return context.profile['emails'][0]['value']
213
213
  # generating some random email address based on social userid and provider domain
214
214
  else:
215
- return u'{0}@{1}'.format(
216
- context.profile['accounts'][0]['userid'],
217
- context.profile['accounts'][0]['domain']
215
+ return text_type(
216
+ '{0}@{1}'.format(
217
+ context.profile['accounts'][0]['userid'],
218
+ context.profile['accounts'][0]['domain']
219
+ )
218
220
  )
Binary file
tests/__init__.pyc CHANGED
Binary file
tests/conftest.py CHANGED
@@ -37,21 +37,22 @@ def web_request():
37
37
 
38
38
  @pytest.fixture(scope='function', params=['sqlite', 'mysql', 'postgresql'])
39
39
  def db_session(request):
40
- """SQLAlchemy session."""
40
+ """Session for SQLAlchemy."""
41
41
  from pyramid_fullauth.models import Base
42
42
 
43
43
  if request.param == 'sqlite':
44
44
  connection = 'sqlite:///fullauth.sqlite'
45
45
  elif request.param == 'mysql':
46
- request.getfuncargvalue('mysqldb') # takes care of creating database
46
+ request.getfixturevalue('mysql') # takes care of creating database
47
47
  connection = 'mysql+mysqldb://root:@127.0.0.1:3307/tests?charset=utf8'
48
48
  elif request.param == 'postgresql':
49
- request.getfuncargvalue('postgresql') # takes care of creating database
49
+ request.getfixturevalue('postgresql') # takes care of creating database
50
50
  connection = 'postgresql+psycopg2://postgres:@127.0.0.1:5433/tests'
51
51
 
52
52
  engine = create_engine(connection, echo=False, poolclass=NullPool)
53
53
  pyramid_basemodel.Session = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
54
- pyramid_basemodel.bind_engine(engine, pyramid_basemodel.Session, should_drop=True)
54
+ pyramid_basemodel.bind_engine(
55
+ engine, pyramid_basemodel.Session, should_create=True, should_drop=True)
55
56
 
56
57
  def destroy():
57
58
  transaction.commit()
@@ -114,6 +115,9 @@ default_config = factories.pyramid_config({
114
115
  })
115
116
 
116
117
 
118
+ default_app = factories.pyramid_app('default_config')
119
+
120
+
117
121
  extended_config = factories.pyramid_config({
118
122
  'pyramid.includes': [
119
123
  'pyramid_tm',
@@ -123,6 +127,9 @@ extended_config = factories.pyramid_config({
123
127
  })
124
128
 
125
129
 
130
+ extended_app = factories.pyramid_app('extended_config')
131
+
132
+
126
133
  short_config = factories.pyramid_config({
127
134
  'yml.location': 'tests:config/short_memory.yaml',
128
135
  'pyramid.includes': [
@@ -134,6 +141,9 @@ short_config = factories.pyramid_config({
134
141
  })
135
142
 
136
143
 
144
+ short_app = factories.pyramid_app('short_config')
145
+
146
+
137
147
  social_config = factories.pyramid_config({
138
148
  'yml.location': 'tests:config/social.yaml',
139
149
  'pyramid.includes': [
@@ -145,6 +155,9 @@ social_config = factories.pyramid_config({
145
155
  })
146
156
 
147
157
 
158
+ social_app = factories.pyramid_app('social_config')
159
+
160
+
148
161
  authable_config = factories.pyramid_config({
149
162
  'yml.location': 'tests:config',
150
163
  'env': 'login',
@@ -157,6 +170,9 @@ authable_config = factories.pyramid_config({
157
170
  })
158
171
 
159
172
 
173
+ authable_app = factories.pyramid_app('authable_config')
174
+
175
+
160
176
  nopassconfirm_config = factories.pyramid_config({
161
177
  'yml.location': 'tests:config/no_password_confirm.yaml',
162
178
  'env': 'login',
@@ -169,6 +185,9 @@ nopassconfirm_config = factories.pyramid_config({
169
185
  })
170
186
 
171
187
 
188
+ nopassconfirm_app = factories.pyramid_app('nopassconfirm_config')
189
+
190
+
172
191
  nopassregister_config = factories.pyramid_config({
173
192
  'yml.location': 'tests:config/no_password_register.yaml',
174
193
  'env': 'login',
@@ -181,10 +200,4 @@ nopassregister_config = factories.pyramid_config({
181
200
  })
182
201
 
183
202
 
184
- default_app = factories.pyramid_app('default_config')
185
- extended_app = factories.pyramid_app('extended_config')
186
- short_app = factories.pyramid_app('short_config')
187
- social_app = factories.pyramid_app('social_config')
188
- authable_app = factories.pyramid_app('authable_config')
189
- nopassconfirm_app = factories.pyramid_app('nopassconfirm_config')
190
203
  nopassregister_app = factories.pyramid_app('nopassregister_config')
tests/conftest.pyc CHANGED
Binary file
tests/tools.pyc CHANGED
Binary file
Binary file
Binary file