API & Client - remove password confirmation
This commit is contained in:
parent
8988a0266a
commit
d8c4106fcf
@ -25,7 +25,6 @@ class TestUserRegistration(ApiTestCaseMixin):
|
|||||||
username='justatest',
|
username='justatest',
|
||||||
email='test@test.com',
|
email='test@test.com',
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -53,7 +52,6 @@ class TestUserRegistration(ApiTestCaseMixin):
|
|||||||
username=input_username,
|
username=input_username,
|
||||||
email='another_email@test.com',
|
email='another_email@test.com',
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -76,7 +74,6 @@ class TestUserRegistration(ApiTestCaseMixin):
|
|||||||
username='test',
|
username='test',
|
||||||
email='test@test.com',
|
email='test@test.com',
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -96,7 +93,6 @@ class TestUserRegistration(ApiTestCaseMixin):
|
|||||||
username='',
|
username='',
|
||||||
email='test@test.com',
|
email='test@test.com',
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -123,7 +119,6 @@ class TestUserRegistration(ApiTestCaseMixin):
|
|||||||
username='a' * 31,
|
username='a' * 31,
|
||||||
email='test@test.com',
|
email='test@test.com',
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -150,7 +145,6 @@ class TestUserRegistration(ApiTestCaseMixin):
|
|||||||
username=input_username,
|
username=input_username,
|
||||||
email='test@test.com',
|
email='test@test.com',
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -172,7 +166,6 @@ class TestUserRegistration(ApiTestCaseMixin):
|
|||||||
username='test',
|
username='test',
|
||||||
email='test@test',
|
email='test@test',
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -192,7 +185,6 @@ class TestUserRegistration(ApiTestCaseMixin):
|
|||||||
username='test',
|
username='test',
|
||||||
email='test@test.com',
|
email='test@test.com',
|
||||||
password='1234567',
|
password='1234567',
|
||||||
password_conf='1234567',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -200,27 +192,6 @@ class TestUserRegistration(ApiTestCaseMixin):
|
|||||||
|
|
||||||
self.assert_400(response, "password: 8 characters required\n")
|
self.assert_400(response, "password: 8 characters required\n")
|
||||||
|
|
||||||
def test_it_returns_error_if_passwords_mismatch(self, app: Flask) -> None:
|
|
||||||
client = app.test_client()
|
|
||||||
|
|
||||||
response = client.post(
|
|
||||||
'/api/auth/register',
|
|
||||||
data=json.dumps(
|
|
||||||
dict(
|
|
||||||
username='test',
|
|
||||||
email='test@test.com',
|
|
||||||
password='12345678',
|
|
||||||
password_conf='87654321',
|
|
||||||
)
|
|
||||||
),
|
|
||||||
content_type='application/json',
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assert_400(
|
|
||||||
response,
|
|
||||||
"password: password and password confirmation do not match\n",
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_it_returns_error_if_payload_is_invalid(self, app: Flask) -> None:
|
def test_it_returns_error_if_payload_is_invalid(self, app: Flask) -> None:
|
||||||
client = app.test_client()
|
client = app.test_client()
|
||||||
response = client.post(
|
response = client.post(
|
||||||
@ -242,7 +213,6 @@ class TestUserRegistration(ApiTestCaseMixin):
|
|||||||
dict(
|
dict(
|
||||||
email='test@test.com',
|
email='test@test.com',
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -259,7 +229,6 @@ class TestUserRegistration(ApiTestCaseMixin):
|
|||||||
dict(
|
dict(
|
||||||
username='test',
|
username='test',
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -276,23 +245,6 @@ class TestUserRegistration(ApiTestCaseMixin):
|
|||||||
dict(
|
dict(
|
||||||
username='test',
|
username='test',
|
||||||
email='test@test.com',
|
email='test@test.com',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
|
||||||
),
|
|
||||||
content_type='application/json',
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assert_400(response)
|
|
||||||
|
|
||||||
def test_it_returns_error_if_password_confirmation_is_missing(
|
|
||||||
self, app: Flask
|
|
||||||
) -> None:
|
|
||||||
client = app.test_client()
|
|
||||||
response = client.post(
|
|
||||||
'/api/auth/register',
|
|
||||||
data=json.dumps(
|
|
||||||
dict(
|
|
||||||
username='test', email='test@test.com', password='12345678'
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -564,7 +516,6 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
|
|||||||
bio='Nothing to tell',
|
bio='Nothing to tell',
|
||||||
birth_date='1980-01-01',
|
birth_date='1980-01-01',
|
||||||
password='87654321',
|
password='87654321',
|
||||||
password_conf='87654321',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||||
@ -672,63 +623,6 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
|
|||||||
|
|
||||||
self.assert_400(response)
|
self.assert_400(response)
|
||||||
|
|
||||||
def test_it_returns_error_if_passwords_mismatch(
|
|
||||||
self, app: Flask, user_1: User
|
|
||||||
) -> None:
|
|
||||||
client, auth_token = self.get_test_client_and_auth_token(
|
|
||||||
app, user_1.email
|
|
||||||
)
|
|
||||||
|
|
||||||
response = client.post(
|
|
||||||
'/api/auth/profile/edit',
|
|
||||||
content_type='application/json',
|
|
||||||
data=json.dumps(
|
|
||||||
dict(
|
|
||||||
first_name='John',
|
|
||||||
last_name='Doe',
|
|
||||||
location='Somewhere',
|
|
||||||
bio='just a random guy',
|
|
||||||
birth_date='1980-01-01',
|
|
||||||
password='87654321',
|
|
||||||
password_conf='876543210',
|
|
||||||
)
|
|
||||||
),
|
|
||||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assert_400(
|
|
||||||
response,
|
|
||||||
'password: password and password confirmation do not match\n',
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_it_returns_error_if_password_confirmation_is_missing(
|
|
||||||
self, app: Flask, user_1: User
|
|
||||||
) -> None:
|
|
||||||
client, auth_token = self.get_test_client_and_auth_token(
|
|
||||||
app, user_1.email
|
|
||||||
)
|
|
||||||
|
|
||||||
response = client.post(
|
|
||||||
'/api/auth/profile/edit',
|
|
||||||
content_type='application/json',
|
|
||||||
data=json.dumps(
|
|
||||||
dict(
|
|
||||||
first_name='John',
|
|
||||||
last_name='Doe',
|
|
||||||
location='Somewhere',
|
|
||||||
bio='just a random guy',
|
|
||||||
birth_date='1980-01-01',
|
|
||||||
password='87654321',
|
|
||||||
)
|
|
||||||
),
|
|
||||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assert_400(
|
|
||||||
response,
|
|
||||||
'password: password and password confirmation do not match\n',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TestUserPreferencesUpdate(ApiTestCaseMixin):
|
class TestUserPreferencesUpdate(ApiTestCaseMixin):
|
||||||
def test_it_updates_user_preferences(
|
def test_it_updates_user_preferences(
|
||||||
@ -1192,7 +1086,6 @@ class TestRegistrationConfiguration(ApiTestCaseMixin):
|
|||||||
username='user4',
|
username='user4',
|
||||||
email='user4@test.com',
|
email='user4@test.com',
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -1214,7 +1107,6 @@ class TestRegistrationConfiguration(ApiTestCaseMixin):
|
|||||||
username='sam',
|
username='sam',
|
||||||
email='sam@test.com',
|
email='sam@test.com',
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -1227,7 +1119,6 @@ class TestRegistrationConfiguration(ApiTestCaseMixin):
|
|||||||
username='new',
|
username='new',
|
||||||
email='new@test.com',
|
email='new@test.com',
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -1248,7 +1139,6 @@ class TestRegistrationConfiguration(ApiTestCaseMixin):
|
|||||||
username='sam',
|
username='sam',
|
||||||
email='sam@test.com',
|
email='sam@test.com',
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -1260,7 +1150,6 @@ class TestRegistrationConfiguration(ApiTestCaseMixin):
|
|||||||
username='new',
|
username='new',
|
||||||
email='new@test.com',
|
email='new@test.com',
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -1331,12 +1220,7 @@ class TestPasswordUpdate(ApiTestCaseMixin):
|
|||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
'/api/auth/password/update',
|
'/api/auth/password/update',
|
||||||
data=json.dumps(
|
data=json.dumps(dict()),
|
||||||
dict(
|
|
||||||
token='xxx',
|
|
||||||
password='1234567',
|
|
||||||
)
|
|
||||||
),
|
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1350,7 +1234,6 @@ class TestPasswordUpdate(ApiTestCaseMixin):
|
|||||||
data=json.dumps(
|
data=json.dumps(
|
||||||
dict(
|
dict(
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -1366,25 +1249,6 @@ class TestPasswordUpdate(ApiTestCaseMixin):
|
|||||||
data=json.dumps(
|
data=json.dumps(
|
||||||
dict(
|
dict(
|
||||||
token='xxx',
|
token='xxx',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
|
||||||
),
|
|
||||||
content_type='application/json',
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assert_400(response)
|
|
||||||
|
|
||||||
def test_it_returns_error_if_password_confirmation_is_missing(
|
|
||||||
self, app: Flask
|
|
||||||
) -> None:
|
|
||||||
client = app.test_client()
|
|
||||||
|
|
||||||
response = client.post(
|
|
||||||
'/api/auth/password/update',
|
|
||||||
data=json.dumps(
|
|
||||||
dict(
|
|
||||||
token='xxx',
|
|
||||||
password='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -1424,7 +1288,6 @@ class TestPasswordUpdate(ApiTestCaseMixin):
|
|||||||
dict(
|
dict(
|
||||||
token=token,
|
token=token,
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -1446,7 +1309,6 @@ class TestPasswordUpdate(ApiTestCaseMixin):
|
|||||||
dict(
|
dict(
|
||||||
token=token,
|
token=token,
|
||||||
password='1234567',
|
password='1234567',
|
||||||
password_conf='1234567',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
@ -1454,7 +1316,7 @@ class TestPasswordUpdate(ApiTestCaseMixin):
|
|||||||
|
|
||||||
self.assert_400(response, 'password: 8 characters required\n')
|
self.assert_400(response, 'password: 8 characters required\n')
|
||||||
|
|
||||||
def test_it_update_password(self, app: Flask, user_1: User) -> None:
|
def test_it_updates_password(self, app: Flask, user_1: User) -> None:
|
||||||
token = get_user_token(user_1.id, password_reset=True)
|
token = get_user_token(user_1.id, password_reset=True)
|
||||||
client = app.test_client()
|
client = app.test_client()
|
||||||
|
|
||||||
@ -1464,7 +1326,6 @@ class TestPasswordUpdate(ApiTestCaseMixin):
|
|||||||
dict(
|
dict(
|
||||||
token=token,
|
token=token,
|
||||||
password='12345678',
|
password='12345678',
|
||||||
password_conf='12345678',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
content_type='application/json',
|
content_type='application/json',
|
||||||
|
@ -7,7 +7,7 @@ from fittrackee.users.exceptions import UserNotFoundException
|
|||||||
from fittrackee.users.models import User
|
from fittrackee.users.models import User
|
||||||
from fittrackee.users.utils.admin import set_admin_rights
|
from fittrackee.users.utils.admin import set_admin_rights
|
||||||
from fittrackee.users.utils.controls import (
|
from fittrackee.users.utils.controls import (
|
||||||
check_passwords,
|
check_password,
|
||||||
check_username,
|
check_username,
|
||||||
is_valid_email,
|
is_valid_email,
|
||||||
register_controls,
|
register_controls,
|
||||||
@ -70,13 +70,6 @@ class TestIsValidEmail:
|
|||||||
|
|
||||||
|
|
||||||
class TestCheckPasswords:
|
class TestCheckPasswords:
|
||||||
def test_it_returns_error_message_string_if_passwords_do_not_match(
|
|
||||||
self,
|
|
||||||
) -> None:
|
|
||||||
assert check_passwords('password', 'pasword') == (
|
|
||||||
'password: password and password confirmation do not match\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
('input_password_length',),
|
('input_password_length',),
|
||||||
[
|
[
|
||||||
@ -89,7 +82,7 @@ class TestCheckPasswords:
|
|||||||
self, input_password_length: int
|
self, input_password_length: int
|
||||||
) -> None:
|
) -> None:
|
||||||
password = random_string(input_password_length)
|
password = random_string(input_password_length)
|
||||||
assert check_passwords(password, password) == (
|
assert check_password(password) == (
|
||||||
'password: 8 characters required\n'
|
'password: 8 characters required\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -104,15 +97,7 @@ class TestCheckPasswords:
|
|||||||
self, input_password_length: int
|
self, input_password_length: int
|
||||||
) -> None:
|
) -> None:
|
||||||
password = random_string(input_password_length)
|
password = random_string(input_password_length)
|
||||||
assert check_passwords(password, password) == ''
|
assert check_password(password) == ''
|
||||||
|
|
||||||
def test_it_returns_multiple_errors(self) -> None:
|
|
||||||
password = random_string(3)
|
|
||||||
password_conf = random_string(8)
|
|
||||||
assert check_passwords(password, password_conf) == (
|
|
||||||
'password: password and password confirmation do not match\n'
|
|
||||||
'password: 8 characters required\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TestIsUsernameValid:
|
class TestIsUsernameValid:
|
||||||
@ -170,7 +155,7 @@ class TestRegisterControls:
|
|||||||
|
|
||||||
def test_it_calls_all_validators(self) -> None:
|
def test_it_calls_all_validators(self) -> None:
|
||||||
with patch(
|
with patch(
|
||||||
self.module_path + 'check_passwords'
|
self.module_path + 'check_password'
|
||||||
) as check_passwords_mock, patch(
|
) as check_passwords_mock, patch(
|
||||||
self.module_path + 'check_username'
|
self.module_path + 'check_username'
|
||||||
) as check_username_mock, patch(
|
) as check_username_mock, patch(
|
||||||
@ -180,12 +165,9 @@ class TestRegisterControls:
|
|||||||
self.valid_username,
|
self.valid_username,
|
||||||
self.valid_email,
|
self.valid_email,
|
||||||
self.valid_password,
|
self.valid_password,
|
||||||
self.valid_password,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
check_passwords_mock.assert_called_once_with(
|
check_passwords_mock.assert_called_once_with(self.valid_password)
|
||||||
self.valid_password, self.valid_password
|
|
||||||
)
|
|
||||||
check_username_mock.assert_called_once_with(self.valid_username)
|
check_username_mock.assert_called_once_with(self.valid_username)
|
||||||
is_valid_email_mock.assert_called_once_with(self.valid_email)
|
is_valid_email_mock.assert_called_once_with(self.valid_email)
|
||||||
|
|
||||||
@ -195,7 +177,6 @@ class TestRegisterControls:
|
|||||||
self.valid_username,
|
self.valid_username,
|
||||||
self.valid_email,
|
self.valid_email,
|
||||||
self.valid_password,
|
self.valid_password,
|
||||||
self.valid_password,
|
|
||||||
)
|
)
|
||||||
== ''
|
== ''
|
||||||
)
|
)
|
||||||
@ -206,9 +187,7 @@ class TestRegisterControls:
|
|||||||
username=invalid_username,
|
username=invalid_username,
|
||||||
email=invalid_username,
|
email=invalid_username,
|
||||||
password=random_string(8),
|
password=random_string(8),
|
||||||
password_conf=random_string(8),
|
|
||||||
) == (
|
) == (
|
||||||
'username: 3 to 30 characters required\n'
|
'username: 3 to 30 characters required\n'
|
||||||
'email: valid email must be provided\n'
|
'email: valid email must be provided\n'
|
||||||
'password: password and password confirmation do not match\n'
|
|
||||||
)
|
)
|
||||||
|
@ -27,7 +27,7 @@ from fittrackee.workouts.models import Sport
|
|||||||
|
|
||||||
from .decorators import authenticate
|
from .decorators import authenticate
|
||||||
from .models import User, UserSportPreference
|
from .models import User, UserSportPreference
|
||||||
from .utils.controls import check_passwords, register_controls
|
from .utils.controls import check_password, register_controls
|
||||||
from .utils.token import decode_user_token
|
from .utils.token import decode_user_token
|
||||||
|
|
||||||
auth_blueprint = Blueprint('auth', __name__)
|
auth_blueprint = Blueprint('auth', __name__)
|
||||||
@ -77,7 +77,6 @@ def register_user() -> Union[Tuple[Dict, int], HttpResponse]:
|
|||||||
:<json string username: user name (3 to 30 characters required)
|
:<json string username: user name (3 to 30 characters required)
|
||||||
:<json string email: user email
|
:<json string email: user email
|
||||||
:<json string password: password (8 characters required)
|
:<json string password: password (8 characters required)
|
||||||
:<json string password_conf: password confirmation
|
|
||||||
|
|
||||||
:statuscode 201: successfully registered
|
:statuscode 201: successfully registered
|
||||||
:statuscode 400:
|
:statuscode 400:
|
||||||
@ -88,7 +87,6 @@ def register_user() -> Union[Tuple[Dict, int], HttpResponse]:
|
|||||||
- username: only alphanumeric characters and the underscore
|
- username: only alphanumeric characters and the underscore
|
||||||
character "_" allowed
|
character "_" allowed
|
||||||
- email: valid email must be provided
|
- email: valid email must be provided
|
||||||
- password: password and password confirmation don't match
|
|
||||||
- password: 8 characters required
|
- password: 8 characters required
|
||||||
:statuscode 403:
|
:statuscode 403:
|
||||||
error, registration is disabled
|
error, registration is disabled
|
||||||
@ -106,16 +104,14 @@ def register_user() -> Union[Tuple[Dict, int], HttpResponse]:
|
|||||||
or post_data.get('username') is None
|
or post_data.get('username') is None
|
||||||
or post_data.get('email') is None
|
or post_data.get('email') is None
|
||||||
or post_data.get('password') is None
|
or post_data.get('password') is None
|
||||||
or post_data.get('password_conf') is None
|
|
||||||
):
|
):
|
||||||
return InvalidPayloadErrorResponse()
|
return InvalidPayloadErrorResponse()
|
||||||
username = post_data.get('username')
|
username = post_data.get('username')
|
||||||
email = post_data.get('email')
|
email = post_data.get('email')
|
||||||
password = post_data.get('password')
|
password = post_data.get('password')
|
||||||
password_conf = post_data.get('password_conf')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ret = register_controls(username, email, password, password_conf)
|
ret = register_controls(username, email, password)
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
return handle_error_and_return_response(e, db=db)
|
return handle_error_and_return_response(e, db=db)
|
||||||
|
|
||||||
@ -192,7 +188,7 @@ def login_user() -> Union[Dict, HttpResponse]:
|
|||||||
}
|
}
|
||||||
|
|
||||||
:<json string email: user email
|
:<json string email: user email
|
||||||
:<json string password_conf: password confirmation
|
:<json string password: password
|
||||||
|
|
||||||
:statuscode 200: successfully logged in
|
:statuscode 200: successfully logged in
|
||||||
:statuscode 400: invalid payload
|
:statuscode 400: invalid payload
|
||||||
@ -481,14 +477,12 @@ def edit_user(auth_user: User) -> Union[Dict, HttpResponse]:
|
|||||||
:<json string bio: user biography
|
:<json string bio: user biography
|
||||||
:<json string birth_date: user birth date (format: ``%Y-%m-%d``)
|
:<json string birth_date: user birth date (format: ``%Y-%m-%d``)
|
||||||
:<json string password: user password
|
:<json string password: user password
|
||||||
:<json string password_conf: user password confirmation
|
|
||||||
|
|
||||||
:reqheader Authorization: OAuth 2.0 Bearer Token
|
:reqheader Authorization: OAuth 2.0 Bearer Token
|
||||||
|
|
||||||
:statuscode 200: user profile updated
|
:statuscode 200: user profile updated
|
||||||
:statuscode 400:
|
:statuscode 400:
|
||||||
- invalid payload
|
- invalid payload
|
||||||
- password: password and password confirmation don't match
|
|
||||||
:statuscode 401:
|
:statuscode 401:
|
||||||
- provide a valid auth token
|
- provide a valid auth token
|
||||||
- signature expired, please log in again
|
- signature expired, please log in again
|
||||||
@ -514,10 +508,9 @@ def edit_user(auth_user: User) -> Union[Dict, HttpResponse]:
|
|||||||
birth_date = post_data.get('birth_date')
|
birth_date = post_data.get('birth_date')
|
||||||
location = post_data.get('location')
|
location = post_data.get('location')
|
||||||
password = post_data.get('password')
|
password = post_data.get('password')
|
||||||
password_conf = post_data.get('password_conf')
|
|
||||||
|
|
||||||
if password is not None and password != '':
|
if password is not None and password != '':
|
||||||
message = check_passwords(password, password_conf)
|
message = check_password(password)
|
||||||
if message != '':
|
if message != '':
|
||||||
return InvalidPayloadErrorResponse(message)
|
return InvalidPayloadErrorResponse(message)
|
||||||
password = bcrypt.generate_password_hash(
|
password = bcrypt.generate_password_hash(
|
||||||
@ -1068,7 +1061,6 @@ def update_password() -> Union[Dict, HttpResponse]:
|
|||||||
}
|
}
|
||||||
|
|
||||||
:<json string password: password (8 characters required)
|
:<json string password: password (8 characters required)
|
||||||
:<json string password_conf: password confirmation
|
|
||||||
:<json string token: password reset token
|
:<json string token: password reset token
|
||||||
|
|
||||||
:statuscode 200: password updated
|
:statuscode 200: password updated
|
||||||
@ -1081,12 +1073,10 @@ def update_password() -> Union[Dict, HttpResponse]:
|
|||||||
if (
|
if (
|
||||||
not post_data
|
not post_data
|
||||||
or post_data.get('password') is None
|
or post_data.get('password') is None
|
||||||
or post_data.get('password_conf') is None
|
|
||||||
or post_data.get('token') is None
|
or post_data.get('token') is None
|
||||||
):
|
):
|
||||||
return InvalidPayloadErrorResponse()
|
return InvalidPayloadErrorResponse()
|
||||||
password = post_data.get('password')
|
password = post_data.get('password')
|
||||||
password_conf = post_data.get('password_conf')
|
|
||||||
token = post_data.get('token')
|
token = post_data.get('token')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -1094,7 +1084,7 @@ def update_password() -> Union[Dict, HttpResponse]:
|
|||||||
except (jwt.ExpiredSignatureError, jwt.InvalidTokenError):
|
except (jwt.ExpiredSignatureError, jwt.InvalidTokenError):
|
||||||
return UnauthorizedErrorResponse()
|
return UnauthorizedErrorResponse()
|
||||||
|
|
||||||
message = check_passwords(password, password_conf)
|
message = check_password(password)
|
||||||
if message != '':
|
if message != '':
|
||||||
return InvalidPayloadErrorResponse(message)
|
return InvalidPayloadErrorResponse(message)
|
||||||
|
|
||||||
|
@ -20,24 +20,20 @@ def is_valid_email(email: str) -> bool:
|
|||||||
return re.match(mail_pattern, email) is not None
|
return re.match(mail_pattern, email) is not None
|
||||||
|
|
||||||
|
|
||||||
def check_passwords(password: str, password_conf: str) -> str:
|
def check_password(password: str) -> str:
|
||||||
"""
|
"""
|
||||||
Verify if password and password confirmation are the same and have
|
Verify if password have more than 8 characters
|
||||||
more than 8 characters
|
If not, it returns error message
|
||||||
|
|
||||||
If not, it returns not empty string
|
|
||||||
"""
|
"""
|
||||||
ret = ''
|
|
||||||
if password_conf != password:
|
|
||||||
ret = 'password: password and password confirmation do not match\n'
|
|
||||||
if len(password) < 8:
|
if len(password) < 8:
|
||||||
ret += 'password: 8 characters required\n'
|
return 'password: 8 characters required\n'
|
||||||
return ret
|
return ''
|
||||||
|
|
||||||
|
|
||||||
def check_username(username: str) -> str:
|
def check_username(username: str) -> str:
|
||||||
"""
|
"""
|
||||||
Return if username is valid
|
Return if username is valid
|
||||||
|
If not, it returns error messages
|
||||||
"""
|
"""
|
||||||
ret = ''
|
ret = ''
|
||||||
if not (2 < len(username) < 31):
|
if not (2 < len(username) < 31):
|
||||||
@ -50,18 +46,15 @@ def check_username(username: str) -> str:
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def register_controls(
|
def register_controls(username: str, email: str, password: str) -> str:
|
||||||
username: str, email: str, password: str, password_conf: str
|
|
||||||
) -> str:
|
|
||||||
"""
|
"""
|
||||||
Verify if username, email and passwords are valid
|
Verify if username, email and passwords are valid
|
||||||
|
If not, it returns error messages
|
||||||
If not, it returns not empty string
|
|
||||||
"""
|
"""
|
||||||
ret = check_username(username)
|
ret = check_username(username)
|
||||||
if not is_valid_email(email):
|
if not is_valid_email(email):
|
||||||
ret += 'email: valid email must be provided\n'
|
ret += 'email: valid email must be provided\n'
|
||||||
ret += check_passwords(password, password_conf)
|
ret += check_password(password)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,15 +27,6 @@
|
|||||||
:disabled="loading"
|
:disabled="loading"
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<label class="form-items" for="passwordConfirmation">
|
|
||||||
{{ $t('user.PASSWORD_CONFIRMATION') }}
|
|
||||||
<input
|
|
||||||
id="passwordConfirmation"
|
|
||||||
type="password"
|
|
||||||
v-model="userForm.password_conf"
|
|
||||||
:disabled="loading"
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
<hr />
|
<hr />
|
||||||
<label class="form-items" for="first_name">
|
<label class="form-items" for="first_name">
|
||||||
{{ $t('user.PROFILE.FIRST_NAME') }}
|
{{ $t('user.PROFILE.FIRST_NAME') }}
|
||||||
@ -119,7 +110,6 @@
|
|||||||
const { user } = toRefs(props)
|
const { user } = toRefs(props)
|
||||||
const userForm: IUserPayload = reactive({
|
const userForm: IUserPayload = reactive({
|
||||||
password: '',
|
password: '',
|
||||||
password_conf: '',
|
|
||||||
first_name: '',
|
first_name: '',
|
||||||
last_name: '',
|
last_name: '',
|
||||||
birth_date: '',
|
birth_date: '',
|
||||||
|
@ -57,21 +57,6 @@
|
|||||||
: $t('user.PASSWORD')
|
: $t('user.PASSWORD')
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
<input
|
|
||||||
v-if="['register', 'reset'].includes(action)"
|
|
||||||
id="confirm-password"
|
|
||||||
:disabled="registration_disabled"
|
|
||||||
type="password"
|
|
||||||
minlength="8"
|
|
||||||
required
|
|
||||||
@invalid="invalidateForm"
|
|
||||||
v-model="formData.password_conf"
|
|
||||||
:placeholder="
|
|
||||||
action === 'reset'
|
|
||||||
? $t('user.ENTER_PASSWORD_CONFIRMATION')
|
|
||||||
: $t('user.PASSWORD_CONFIRM')
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" :disabled="registration_disabled">
|
<button type="submit" :disabled="registration_disabled">
|
||||||
{{ $t(buttonText) }}
|
{{ $t(buttonText) }}
|
||||||
@ -131,7 +116,6 @@
|
|||||||
username: '',
|
username: '',
|
||||||
email: '',
|
email: '',
|
||||||
password: '',
|
password: '',
|
||||||
password_conf: '',
|
|
||||||
})
|
})
|
||||||
const buttonText: ComputedRef<string> = computed(() =>
|
const buttonText: ComputedRef<string> = computed(() =>
|
||||||
getButtonText(props.action)
|
getButtonText(props.action)
|
||||||
@ -171,7 +155,6 @@
|
|||||||
}
|
}
|
||||||
return store.dispatch(AUTH_USER_STORE.ACTIONS.RESET_USER_PASSWORD, {
|
return store.dispatch(AUTH_USER_STORE.ACTIONS.RESET_USER_PASSWORD, {
|
||||||
password: formData.password,
|
password: formData.password,
|
||||||
password_conf: formData.password_conf,
|
|
||||||
token: props.token,
|
token: props.token,
|
||||||
})
|
})
|
||||||
case 'reset-request':
|
case 'reset-request':
|
||||||
@ -193,7 +176,6 @@
|
|||||||
formData.username = ''
|
formData.username = ''
|
||||||
formData.email = ''
|
formData.email = ''
|
||||||
formData.password = ''
|
formData.password = ''
|
||||||
formData.password_conf = ''
|
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
@ -5,14 +5,11 @@
|
|||||||
"EMAIL": "Email",
|
"EMAIL": "Email",
|
||||||
"ENTER_EMAIL": "Enter an email address",
|
"ENTER_EMAIL": "Enter an email address",
|
||||||
"ENTER_PASSWORD": "Enter a password",
|
"ENTER_PASSWORD": "Enter a password",
|
||||||
"ENTER_PASSWORD_CONFIRMATION": "Confirm the password",
|
|
||||||
"INVALID_TOKEN": "Invalid token, please request a new password reset.",
|
"INVALID_TOKEN": "Invalid token, please request a new password reset.",
|
||||||
"LANGUAGE": "Language",
|
"LANGUAGE": "Language",
|
||||||
"LOGIN": "Login",
|
"LOGIN": "Login",
|
||||||
"LOGOUT": "Logout",
|
"LOGOUT": "Logout",
|
||||||
"PASSWORD": "Password",
|
"PASSWORD": "Password",
|
||||||
"PASSWORD_CONFIRM": "Confirm Password",
|
|
||||||
"PASSWORD_CONFIRMATION": "Password confirmation",
|
|
||||||
"PASSWORD_FORGOTTEN": "Forgot password?",
|
"PASSWORD_FORGOTTEN": "Forgot password?",
|
||||||
"PASSWORD_RESET": "Password reset",
|
"PASSWORD_RESET": "Password reset",
|
||||||
"PASSWORD_SENT_EMAIL_TEXT": "Check your email. If your address is in our database, you'll received an email with a link to reset your password.",
|
"PASSWORD_SENT_EMAIL_TEXT": "Check your email. If your address is in our database, you'll received an email with a link to reset your password.",
|
||||||
|
@ -5,14 +5,11 @@
|
|||||||
"EMAIL": "Email",
|
"EMAIL": "Email",
|
||||||
"ENTER_EMAIL": "Saisir une adresse email",
|
"ENTER_EMAIL": "Saisir une adresse email",
|
||||||
"ENTER_PASSWORD": "Saisir un mot de passe",
|
"ENTER_PASSWORD": "Saisir un mot de passe",
|
||||||
"ENTER_PASSWORD_CONFIRMATION": "Confirmer le mot de passe",
|
|
||||||
"INVALID_TOKEN": "Jeton invalide, veullez demander une nouvelle réinitialisation de mot de passe.",
|
"INVALID_TOKEN": "Jeton invalide, veullez demander une nouvelle réinitialisation de mot de passe.",
|
||||||
"LANGUAGE": "Langue",
|
"LANGUAGE": "Langue",
|
||||||
"LOGIN": "Se connecter",
|
"LOGIN": "Se connecter",
|
||||||
"LOGOUT": "Se déconnecter",
|
"LOGOUT": "Se déconnecter",
|
||||||
"PASSWORD": "Mot de passe",
|
"PASSWORD": "Mot de passe",
|
||||||
"PASSWORD_CONFIRM": "Confirmation du mot de passe",
|
|
||||||
"PASSWORD_CONFIRMATION": "Confirmation du mot de passe",
|
|
||||||
"PASSWORD_FORGOTTEN": "Mot de passe oublié ?",
|
"PASSWORD_FORGOTTEN": "Mot de passe oublié ?",
|
||||||
"PASSWORD_RESET": "Réinitialisation du mot de passe",
|
"PASSWORD_RESET": "Réinitialisation du mot de passe",
|
||||||
"PASSWORD_SENT_EMAIL_TEXT": "Vérifiez votre boite mail. Si vote adresse est dans notre base de données, vous recevrez un email avec un lien pour réinitialiser votre mot de passe.",
|
"PASSWORD_SENT_EMAIL_TEXT": "Vérifiez votre boite mail. Si vote adresse est dans notre base de données, vous recevrez un email avec un lien pour réinitialiser votre mot de passe.",
|
||||||
|
@ -32,7 +32,6 @@ export interface IUserPayload {
|
|||||||
last_name: string
|
last_name: string
|
||||||
location: string
|
location: string
|
||||||
password: string
|
password: string
|
||||||
password_conf: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IAdminUserPayload {
|
export interface IAdminUserPayload {
|
||||||
@ -64,7 +63,6 @@ export interface IUserPasswordPayload {
|
|||||||
|
|
||||||
export interface IUserPasswordResetPayload {
|
export interface IUserPasswordResetPayload {
|
||||||
password: string
|
password: string
|
||||||
password_conf: string
|
|
||||||
token: string
|
token: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +75,6 @@ export interface ILoginRegisterFormData {
|
|||||||
username: string
|
username: string
|
||||||
email: string
|
email: string
|
||||||
password: string
|
password: string
|
||||||
password_conf: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ILoginOrRegisterData {
|
export interface ILoginOrRegisterData {
|
||||||
|
Loading…
Reference in New Issue
Block a user