Skip to content

Commit 3e41ca2

Browse files
authored
Merge pull request #52 from zfi/1.1
1.1
2 parents 6f68268 + 67905fe commit 3e41ca2

File tree

5 files changed

+47
-22
lines changed

5 files changed

+47
-22
lines changed

Failures.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def unknown_user_id(id_user):
1212

1313

1414
def unknown_user_email(email):
15-
logging.debug('Failures: Unknown user: %s', email)
15+
logging.debug('Failures: Unknown user email: %s', email)
1616
return {
1717
'success': False,
1818
'message': 'Unknown user',
@@ -41,17 +41,17 @@ def email_already_in_use(email):
4141
}, 500
4242

4343

44-
def email_not_confirmed():
45-
logging.debug('Failures: Email not confirmed')
44+
def email_not_confirmed(email):
45+
logging.debug('Failures: Email %s not confirmed', email)
4646
return {
4747
'success': False,
4848
'message': 'Email not confirmed',
4949
'code': 430
5050
}, 401
5151

5252

53-
def user_blocked():
54-
logging.debug('Failures: User blocked')
53+
def user_blocked(email):
54+
logging.debug('Failures: User %s blocked', email)
5555
return {
5656
'success': False,
5757
'message': 'User is blocked',
@@ -113,8 +113,8 @@ def rate_exceeded(time):
113113
}, 500
114114

115115

116-
def wrong_password():
117-
logging.debug('Failures: Wrong password')
116+
def wrong_password(email):
117+
logging.debug('Failures: Wrong password for %s', email)
118118
return {
119119
'success': False,
120120
'message': 'Wrong password',

app/Authenticate/controllers.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,36 @@
1515
authenticate_app = Blueprint('authenticate', __name__, url_prefix='/authenticate')
1616
api = Api(authenticate_app)
1717

18-
18+
# Authenticate a login attempt using local auth
1919
class AuthenticateLocalUser(Resource):
2020

2121
def post(self):
2222
# Get values
2323
server = request.headers.get('server')
2424
email = request.form.get('email')
2525
password = request.form.get('password')
26-
#browser = request.form.get('browser')
27-
#ip_address = request.form.get('ipAddress')
2826

2927
# Validate required fields
3028
validation = Validation()
3129
validation.add_required_field('server', server)
3230
validation.add_required_field('email', email)
3331
validation.add_required_field('password', password)
34-
#validation.add_required_field('browser', browser)
35-
#validation.add_required_field('ipAddress', ip_address)
32+
3633
if not validation.is_valid():
3734
return validation.get_validation_response()
3835

3936
# Validate user exists, is validated and is not blocked
4037
user = user_services.get_user_by_email(email)
38+
4139
if user is None:
4240
return Failures.unknown_user_email(email)
41+
4342
if not user.confirmed:
44-
return Failures.email_not_confirmed()
43+
return Failures.email_not_confirmed(email)
44+
4545
if user.blocked:
46-
return Failures.user_blocked()
46+
return Failures.user_blocked(email)
47+
4748
if user.auth_source != 'local':
4849
return Failures.wrong_auth_source(user.auth_source)
4950

@@ -53,11 +54,11 @@ def post(self):
5354
if not user_services.check_password(user.id, password):
5455
rate_limiting_services.consume_tokens(user.id, 'failed-password', 1)
5556
db.session.commit()
56-
return Failures.wrong_password()
57+
return Failures.wrong_password(email)
5758

5859
db.session.commit()
5960

60-
logging.info('Authenticate-controller: Authenticate: success: %s', user.id)
61+
logging.info('Authenticate-controller: Authenticate: success: %s', email)
6162

6263
return {'success': True, 'user': {
6364
'id': user.id,

app/Email/services.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ def _convert_email_uri(email):
211211
to create a URI that contains an email address that, when submitted to a
212212
server, will not be replaced with a space character.
213213
"""
214-
if "+" in email:
215-
return email.replace("+", "%2B")
216-
else:
217-
return email
214+
if email is not None:
215+
if "+" in email:
216+
return email.replace("+", "%2B")
217+
218+
return email

app/LocalUser/controllers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def post(self):
6363
if confirm_token is None:
6464
# Unknown token
6565
return {'success': False, 'code': 510}
66+
6667
if confirm_token.id_user != user.id:
6768
# Token is not for this user
6869
return {'success': False, 'code': 510}
@@ -214,6 +215,9 @@ def get(self, email):
214215
if user.auth_source != 'local':
215216
return Failures.wrong_auth_source(user.auth_source)
216217

218+
if not user.confirmed:
219+
return Failures.email_not_confirmed(user.email)
220+
217221
success, code, message = user_service.send_password_reset(user.id, server)
218222

219223
db.session.commit()

app/__init__.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,22 @@
2424
app = Flask(__name__)
2525

2626
# Application version (major,minor,patch-level)
27-
version = "1.1.4"
27+
version = "1.1.8"
2828

2929
"""
3030
Change Log
3131
32+
1.1.8 Fail any attempt to reset an account password is the account
33+
email address has not yet been confirmed.
34+
35+
1.1.7 Update application logging to separate application events from
36+
those logged by the uwsgi servivce
37+
38+
1.1.6 Add email address detail for various authentication failures
39+
40+
1.1.5 Refactor _convert_email_uri(email) to properly handle a null
41+
email address.
42+
3243
1.1.4 Add code to convert plus signs located the the username portion
3344
of an email address to a '%2B'when the email address is embedded
3445
in a URL.
@@ -78,7 +89,15 @@
7889
'bucket.email-confirm.freq': '1800000'
7990
}
8091

81-
logging.basicConfig(level=logging.DEBUG)
92+
93+
# Set up Cloud Session application log details. The user account that
94+
# this application runs under must have create and write permissions to
95+
# the /var/log/supervisor/ folder.
96+
# ----------------------------------------------------------------------
97+
logging.basicConfig(level=logging.DEBUG,
98+
format='%(asctime)s %(levelname)s %(message)s',
99+
filename='/var/log/supervisor/cloud-session-app.log',
100+
filemode='w')
82101
logging.info('Log level set to %s', 'DEBUG')
83102
logging.info('Starting Cloud Session Service v%s', version)
84103

0 commit comments

Comments
 (0)