Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Issue #573 Error message for field 'name' not filled #1160

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export FLASK_ENVIRONMENT_CONFIG=local
export SECRET_KEY='eecs481'
export SECURITY_PASSWORD_SALT='homework6'
export MAIL_DEFAULT_SENDER='[email protected]'
export MAIL_SERVER='smtp.gmail.com'
export APP_MAIL_USERNAME='goliampayne'
export APP_MAIL_PASSWORD='onedirection4ver'
export MOCK_EMAIL=True
export DATABASE_URL = os.environ.get("DATABASE_URL").replace("postgres", "postgresql")
8 changes: 0 additions & 8 deletions .env.template

This file was deleted.

60 changes: 30 additions & 30 deletions app/api/resources/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ class UserRegister(Resource):
f"{messages.USERNAME_INPUT_BY_USER_IS_INVALID}\n"
f"{messages.USER_INPUTS_SPACE_IN_PASSWORD}\n"
f"{messages.USERNAME_HAS_INVALID_LENGTH}\n"
f"{messages.PASSWORD_INPUT_BY_USER_HAS_INVALID_LENGTH}",
f"{messages.PASSWORD_INPUT_BY_USER_HAS_INVALID_LENGTH}\n"
f"{messages.INVALID_LENGTH_OF_USERNAME}"
)
@users_ns.response(
HTTPStatus.CONFLICT.value,
Expand Down Expand Up @@ -421,35 +422,34 @@ def post(cls):

@users_ns.route("refresh")
class RefreshUser(Resource):
@classmethod
@jwt_refresh_token_required
@users_ns.doc("refresh")
@users_ns.response(
HTTPStatus.OK.value,
f"{messages.SUCCESSFUL_REFRESH}",
refresh_response_body_model,
)
@users_ns.response(
HTTPStatus.UNAUTHORIZED.value,
f"{messages.TOKEN_HAS_EXPIRED}\n"
f"{messages.TOKEN_IS_INVALID}\n"
f"{messages.AUTHORISATION_TOKEN_IS_MISSING}",
)
@users_ns.expect(refresh_auth_header_parser)
def post(cls):
"""Refresh user's access

The return value is an access token.
The token is valid for 1 week.
"""
user_id = get_jwt_identity()
access_token = create_access_token(identity=user_id)

return (
{"access_token": access_token},
HTTPStatus.OK,
)

@classmethod
@jwt_refresh_token_required
@users_ns.doc("refresh")
@users_ns.response(
HTTPStatus.OK.value,
f"{messages.SUCCESSFUL_REFRESH}",
refresh_response_body_model,
)
@users_ns.response(
HTTPStatus.UNAUTHORIZED.value,
f"{messages.TOKEN_HAS_EXPIRED}\n"
f"{messages.TOKEN_IS_INVALID}\n"
f"{messages.AUTHORISATION_TOKEN_IS_MISSING}",
)
@users_ns.expect(refresh_auth_header_parser)
def post(cls):
"""Refresh user's access

The return value is an access token.
The token is valid for 1 week.
"""
user_id = get_jwt_identity()
access_token = create_access_token(identity=user_id)

return (
{"access_token": access_token},
HTTPStatus.OK,
)

@users_ns.route("login")
class LoginUser(Resource):
Expand Down
5 changes: 5 additions & 0 deletions app/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
PASSWORD_MIN_LENGTH,
USERNAME_MAX_LENGTH,
USERNAME_MIN_LENGTH,
NAME_MIN_LENGTH,
NAME_MAX_LENGTH
)

# Invalid fields
Expand All @@ -20,6 +22,9 @@
PASSWORD_INPUT_BY_USER_HAS_INVALID_LENGTH = {
"message": f"The password field has to be longer than {PASSWORD_MIN_LENGTH - 1} characters and shorter than {PASSWORD_MAX_LENGTH + 1} characters."
}
INVALID_LENGTH_OF_USERNAME = {
"message": f"The name field has to be longer than {NAME_MIN_LENGTH - 1} characters and shorter than {NAME_MAX_LENGTH + 1} characters."
}

# Not found
MENTORSHIP_RELATION_REQUEST_DOES_NOT_EXIST = {
Expand Down