Commit 23c4e97c authored by Sanyam Khurana's avatar Sanyam Khurana

fix(signup): Make user's profile timezone aware

Merge branch 'updating-signup' into 'master'

Allowing different timezones during signup

See merge request new-contributor-wizard-team/new-contributor-wizard!18
parents 1950944b 4a0d6513
......@@ -6,6 +6,10 @@ v0.0.1
- Adding description to all the course ware modules by updating `module_data.json` (Shashank Kumar - realslimshanky)
- Refactored `module_box` module to support description on the UI (Shashank Kumar - realslimshanky)
## August 11 2018
- Updating Sign Up module to allow different timezones from the user (Shashank Kumar - realslimshanky)
## August 7 2018
- Adding `Contribute To Tutorials` documentation (Shashank Kumar - realslimshanky)
......
......@@ -6,7 +6,7 @@ import sqlite3
from settings import get_db_connection, USER_INFOMATION_TABLE
from modules.signup.exceptions import SignUpError
from modules.signup.utils import (
generate_uuid, clean_email, clean_full_name, hash_password
generate_uuid, clean_email, clean_full_name, hash_password, clean_timezone
)
......@@ -28,7 +28,7 @@ def sign_up_user(email, password, full_name, language, timezone):
'password': hash_password(password),
'full_name': clean_full_name(full_name),
'language': language,
'timezone': timezone,
'timezone': clean_timezone(timezone),
}
try:
......
......@@ -11,8 +11,8 @@ from kivy.uix.screenmanager import Screen
from modules.signup.services import sign_up_user
from modules.signup.exceptions import SignUpError
from modules.signup.validations import (
validate_email, validate_first_pass, validate_confirm_pass, validate_full_name
)
validate_email, validate_first_pass, validate_confirm_pass,
validate_full_name, validate_timezone)
Builder.load_file('./ui/signup.kv')
......@@ -53,6 +53,7 @@ class SignUp(BoxLayout, Screen):
email_validation = True
name_validation = True
password_validation = True
timezone_validation = True
user_email = self.ids['user_email'].text
try:
......@@ -94,7 +95,18 @@ class SignUp(BoxLayout, Screen):
)
name_validation = False
return email_validation and name_validation and password_validation
timezone = self.ids['user_timezone'].text
try:
validate_timezone(timezone)
except SignUpError as error:
self.prompt_error_message(
'timezone_label',
error.message,
)
timezone_validation = False
return email_validation and name_validation and password_validation\
and timezone_validation
def sign_up(self, *args):
'''
......
......@@ -32,3 +32,11 @@ def hash_password(password):
hash_password converts plain text password into sha256 hash
'''
return hashlib.sha256(password.encode()).hexdigest()
def clean_timezone(timezone):
'''
clean_timezone removes unnessary spaces from the timezone and return a
lowercase timezone text
'''
return timezone.lower().strip(' ')
......@@ -5,7 +5,7 @@ import re
from modules.signup.exceptions import SignUpError
from modules.signup.utils import (
clean_email, clean_full_name
clean_email, clean_full_name, clean_timezone
)
......@@ -59,3 +59,16 @@ def validate_full_name(full_name):
if not name.isalpha():
raise SignUpError('Incorrect Format')
return True
def validate_timezone(timezone):
'''
Validating timezone to be in format `UTC+00:00`
'''
timezone = clean_timezone(timezone)
if not timezone:
raise SignUpError('Enter Timezone')
else:
if not re.match(r'utc[+-]\d{2}:\d{2}', timezone):
raise SignUpError('Invalid Format')
return True
import pytest
from modules.signup.utils import (
generate_uuid,
clean_email,
clean_full_name,
hash_password
clean_timezone
)
......@@ -30,3 +28,10 @@ def test_clean_full_name():
assert clean_full_name(' Shashank Kumar') == 'Shashank Kumar'
assert clean_full_name('Shashank Kumar ') == 'Shashank Kumar'
assert clean_full_name(' Shashank Kumar ') == 'Shashank Kumar'
def test_clean_timezone():
# testing cleaning of spaces, tabs and lowercasing of timezone
assert clean_timezone('UTC+00:00') == 'utc+00:00'
assert clean_timezone('UtC+00:00 ') == 'utc+00:00'
assert clean_timezone(' Utc-11:11') == 'utc-11:11'
......@@ -5,7 +5,8 @@ from modules.signup.validations import (
validate_email,
validate_first_pass,
validate_confirm_pass,
validate_full_name
validate_full_name,
validate_timezone
)
......@@ -58,3 +59,16 @@ def test_validate_full_name():
# check for invalid name format
with pytest.raises(SignUpError):
validate_full_name('Sanyam ! Khurana')
def test_validate_timezone():
# check for correct timezone
assert validate_timezone('UTC+05:30')
# check for empty timezone
with pytest.raises(SignUpError):
validate_timezone('')
# check for incorrect timezone
with pytest.raises(SignUpError):
validate_timezone('utc+')
......@@ -63,12 +63,12 @@
SignUpLabel
text: 'Timezone'
font_size: 20
id: timezone_label
SignUpBoxLayout
padding: 0, 0, 20, 0
SignUpTextInput
id: user_timezone
readonly: True
text: 'UTC+5:30'
hint_text: 'In format "UTC+00:00"'
BoxLayout
size_hint: 1, 0.16
id: submit_info
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment