Set user timezone automatically during signup.

This commit is contained in:
hackerkid 2017-05-04 18:49:50 +05:30 committed by Tim Abbott
parent 34dae708d6
commit 83eb161249
3 changed files with 14 additions and 3 deletions

View File

@ -28,6 +28,7 @@ Form is validated both client-side using jquery-validate (see signup.js) and ser
{{ csrf_input }}
<div class="input-box no-validation">
<input type='hidden' name='key' value='{{ key }}' />
<input type='hidden' name='timezone' id='timezone'/>
<input id="id_email" type='text' disabled="true" placeholder="{{ email }}" required />
<label for="id_email" class="inline-block label-title">{{ _('Email') }}</label>
<div class="required"></div>
@ -223,6 +224,8 @@ $("[name=realm_org_type]").on("change", function () {
$(".blob").hide();
$("#org_type_blob_" + this.value).show();
});
$("#timezone").val(moment.tz.guess());
</script>
{% endblock %}

View File

@ -234,8 +234,8 @@ class ZulipTestCase(TestCase):
def submit_reg_form_for_user(self, email, password, realm_name="Zulip Test",
realm_subdomain="zuliptest", realm_org_type=Realm.COMMUNITY,
from_confirmation='', full_name=None, **kwargs):
# type: (Text, Text, Optional[Text], Optional[Text], int, Optional[Text], Optional[Text], **Any) -> HttpResponse
from_confirmation='', full_name=None, timezone=u'', **kwargs):
# type: (Text, Text, Optional[Text], Optional[Text], int, Optional[Text], Optional[Text], Optional[Text], **Any) -> HttpResponse
"""
Stage two of the two-step registration process.
@ -253,6 +253,7 @@ class ZulipTestCase(TestCase):
'realm_subdomain': realm_subdomain,
'key': find_key_by_email(email),
'realm_org_type': realm_org_type,
'timezone': timezone,
'terms': True,
'from_confirmation': from_confirmation},
**kwargs)

View File

@ -24,12 +24,13 @@ from zerver.lib.actions import do_change_password, do_change_full_name, do_chang
compute_mit_user_fullname
from zerver.forms import RegistrationForm, HomepageForm, RealmCreationForm, \
CreateUserForm, FindMyTeamForm
from zerver.lib.actions import is_inactive
from zerver.lib.actions import is_inactive, do_set_user_display_setting
from django_auth_ldap.backend import LDAPBackend, _LDAPUser
from zerver.decorator import require_post, has_request_variables, \
JsonableError, get_user_profile_by_email, REQ
from zerver.lib.response import json_success
from zerver.lib.utils import get_subdomain
from zerver.lib.timezone import get_all_timezones
from zproject.backends import password_auth_enabled
from confirmation.models import Confirmation, RealmCreationKey, check_key_is_valid
@ -197,16 +198,22 @@ def accounts_register(request):
short_name = email_to_username(email)
first_in_realm = len(UserProfile.objects.filter(realm=realm, is_bot=False)) == 0
timezone = u""
if 'timezone' in request.POST and request.POST['timezone'] in get_all_timezones():
timezone = request.POST['timezone']
# FIXME: sanitize email addresses and fullname
if existing_user_profile is not None and existing_user_profile.is_mirror_dummy:
user_profile = existing_user_profile
do_activate_user(user_profile)
do_change_password(user_profile, password)
do_change_full_name(user_profile, full_name)
do_set_user_display_setting(user_profile, 'timezone', timezone)
else:
user_profile = do_create_user(email, password, realm, full_name, short_name,
prereg_user=prereg_user,
tos_version=settings.TOS_VERSION,
timezone=timezone,
newsletter_data={"IP": request.META['REMOTE_ADDR']})
if first_in_realm: