2017-01-07 21:46:03 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import absolute_import
|
2017-07-17 06:44:59 +02:00
|
|
|
from typing import Any, List, Dict, Mapping, Optional, Text
|
2017-01-07 21:46:03 +01:00
|
|
|
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from django.conf import settings
|
2017-08-25 01:11:30 +02:00
|
|
|
from django.contrib.auth import authenticate, get_backends
|
2017-01-07 21:46:03 +01:00
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.http import HttpResponseRedirect, HttpResponseForbidden, HttpResponse, HttpRequest
|
2017-03-16 14:28:08 +01:00
|
|
|
from django.shortcuts import redirect, render
|
2017-01-07 21:46:03 +01:00
|
|
|
from django.template import RequestContext, loader
|
|
|
|
from django.utils.timezone import now
|
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from django.core import validators
|
|
|
|
from zerver.models import UserProfile, Realm, PreregistrationUser, \
|
|
|
|
name_changes_disabled, email_to_username, \
|
|
|
|
completely_open, get_unique_open_realm, email_allowed_for_realm, \
|
2017-08-25 07:22:39 +02:00
|
|
|
get_realm, get_realm_by_email_domain, get_user_profile_by_email
|
2017-07-11 05:01:32 +02:00
|
|
|
from zerver.lib.send_email import send_email, FromAddress
|
2017-02-10 23:04:46 +01:00
|
|
|
from zerver.lib.events import do_events_register
|
2017-01-07 21:46:03 +01:00
|
|
|
from zerver.lib.actions import do_change_password, do_change_full_name, do_change_is_admin, \
|
2017-08-02 05:20:50 +02:00
|
|
|
do_activate_user, do_create_user, do_create_realm, \
|
2017-08-25 07:05:27 +02:00
|
|
|
user_email_is_unique, compute_mit_user_fullname, validate_email_for_realm, \
|
|
|
|
do_set_user_display_setting
|
2017-01-07 21:46:03 +01:00
|
|
|
from zerver.forms import RegistrationForm, HomepageForm, RealmCreationForm, \
|
|
|
|
CreateUserForm, FindMyTeamForm
|
|
|
|
from django_auth_ldap.backend import LDAPBackend, _LDAPUser
|
|
|
|
from zerver.decorator import require_post, has_request_variables, \
|
2017-08-25 07:22:39 +02:00
|
|
|
JsonableError, REQ, do_login
|
2017-08-02 05:20:50 +02:00
|
|
|
from zerver.lib.onboarding import send_initial_pms, setup_initial_streams, \
|
|
|
|
setup_initial_private_stream, send_initial_realm_messages
|
2017-01-07 21:46:03 +01:00
|
|
|
from zerver.lib.response import json_success
|
|
|
|
from zerver.lib.utils import get_subdomain
|
2017-05-04 15:19:50 +02:00
|
|
|
from zerver.lib.timezone import get_all_timezones
|
2017-01-07 21:46:03 +01:00
|
|
|
from zproject.backends import password_auth_enabled
|
|
|
|
|
2017-07-08 04:38:13 +02:00
|
|
|
from confirmation.models import Confirmation, RealmCreationKey, check_key_is_valid, \
|
|
|
|
create_confirmation_link
|
2017-01-07 21:46:03 +01:00
|
|
|
|
|
|
|
import logging
|
|
|
|
import requests
|
2017-08-17 18:28:21 +02:00
|
|
|
import smtplib
|
2017-01-07 21:46:03 +01:00
|
|
|
import ujson
|
|
|
|
|
|
|
|
from six.moves import urllib
|
|
|
|
|
2017-04-20 08:30:50 +02:00
|
|
|
def redirect_and_log_into_subdomain(realm, full_name, email_address,
|
|
|
|
is_signup=False):
|
|
|
|
# type: (Realm, Text, Text, bool) -> HttpResponse
|
2017-01-07 21:46:03 +01:00
|
|
|
subdomain_login_uri = ''.join([
|
|
|
|
realm.uri,
|
|
|
|
reverse('zerver.views.auth.log_into_subdomain')
|
|
|
|
])
|
|
|
|
|
|
|
|
domain = '.' + settings.EXTERNAL_HOST.split(':')[0]
|
|
|
|
response = redirect(subdomain_login_uri)
|
|
|
|
|
2017-04-20 08:30:50 +02:00
|
|
|
data = {'name': full_name, 'email': email_address, 'subdomain': realm.subdomain,
|
|
|
|
'is_signup': is_signup}
|
2017-01-07 21:46:03 +01:00
|
|
|
# Creating a singed cookie so that it cannot be tampered with.
|
|
|
|
# Cookie and the signature expire in 15 seconds.
|
|
|
|
response.set_signed_cookie('subdomain.signature',
|
|
|
|
ujson.dumps(data),
|
|
|
|
expires=15,
|
|
|
|
domain=domain,
|
|
|
|
salt='zerver.views.auth')
|
|
|
|
return response
|
|
|
|
|
|
|
|
@require_post
|
|
|
|
def accounts_register(request):
|
|
|
|
# type: (HttpRequest) -> HttpResponse
|
|
|
|
key = request.POST['key']
|
|
|
|
confirmation = Confirmation.objects.get(confirmation_key=key)
|
|
|
|
prereg_user = confirmation.content_object
|
|
|
|
email = prereg_user.email
|
|
|
|
realm_creation = prereg_user.realm_creation
|
2017-08-04 08:09:25 +02:00
|
|
|
password_required = prereg_user.password_required
|
2017-01-07 21:46:03 +01:00
|
|
|
|
|
|
|
validators.validate_email(email)
|
|
|
|
# If OPEN_REALM_CREATION is enabled all user sign ups should go through the
|
|
|
|
# special URL with domain name so that REALM can be identified if multiple realms exist
|
|
|
|
unique_open_realm = get_unique_open_realm()
|
|
|
|
if unique_open_realm is not None:
|
2017-05-25 18:22:28 +02:00
|
|
|
realm = unique_open_realm # type: Optional[Realm]
|
2017-01-07 21:46:03 +01:00
|
|
|
elif prereg_user.referred_by:
|
|
|
|
# If someone invited you, you are joining their realm regardless
|
|
|
|
# of your e-mail address.
|
|
|
|
realm = prereg_user.referred_by.realm
|
|
|
|
elif realm_creation:
|
|
|
|
# For creating a new realm, there is no existing realm or domain
|
|
|
|
realm = None
|
|
|
|
elif settings.REALMS_HAVE_SUBDOMAINS:
|
|
|
|
realm = get_realm(get_subdomain(request))
|
|
|
|
else:
|
|
|
|
realm = get_realm_by_email_domain(email)
|
|
|
|
|
|
|
|
if realm and not email_allowed_for_realm(email, realm):
|
2017-03-16 14:28:08 +01:00
|
|
|
return render(request, "zerver/closed_realm.html",
|
|
|
|
context={"closed_domain_name": realm.name})
|
2017-01-07 21:46:03 +01:00
|
|
|
|
|
|
|
if realm and realm.deactivated:
|
|
|
|
# The user is trying to register for a deactivated realm. Advise them to
|
|
|
|
# contact support.
|
2017-08-25 08:16:36 +02:00
|
|
|
return redirect_to_deactivation_notice()
|
2017-01-07 21:46:03 +01:00
|
|
|
|
|
|
|
try:
|
2017-08-25 07:05:27 +02:00
|
|
|
validate_email_for_realm(realm, email)
|
2017-01-07 21:46:03 +01:00
|
|
|
except ValidationError:
|
|
|
|
return HttpResponseRedirect(reverse('django.contrib.auth.views.login') + '?email=' +
|
|
|
|
urllib.parse.quote_plus(email))
|
|
|
|
|
|
|
|
name_validated = False
|
|
|
|
full_name = None
|
|
|
|
|
|
|
|
if request.POST.get('from_confirmation'):
|
|
|
|
try:
|
|
|
|
del request.session['authenticated_full_name']
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
if realm is not None and realm.is_zephyr_mirror_realm:
|
|
|
|
# For MIT users, we can get an authoritative name from Hesiod.
|
|
|
|
# Technically we should check that this is actually an MIT
|
|
|
|
# realm, but we can cross that bridge if we ever get a non-MIT
|
|
|
|
# zephyr mirroring realm.
|
|
|
|
hesiod_name = compute_mit_user_fullname(email)
|
|
|
|
form = RegistrationForm(
|
2017-06-15 19:24:38 +02:00
|
|
|
initial={'full_name': hesiod_name if "@" not in hesiod_name else ""},
|
|
|
|
realm_creation=realm_creation)
|
2017-01-07 21:46:03 +01:00
|
|
|
name_validated = True
|
|
|
|
elif settings.POPULATE_PROFILE_VIA_LDAP:
|
|
|
|
for backend in get_backends():
|
|
|
|
if isinstance(backend, LDAPBackend):
|
|
|
|
ldap_attrs = _LDAPUser(backend, backend.django_to_ldap_username(email)).attrs
|
|
|
|
try:
|
|
|
|
ldap_full_name = ldap_attrs[settings.AUTH_LDAP_USER_ATTR_MAP['full_name']][0]
|
|
|
|
request.session['authenticated_full_name'] = ldap_full_name
|
|
|
|
name_validated = True
|
|
|
|
# We don't use initial= here, because if the form is
|
|
|
|
# complete (that is, no additional fields need to be
|
|
|
|
# filled out by the user) we want the form to validate,
|
|
|
|
# so they can be directly registered without having to
|
|
|
|
# go through this interstitial.
|
2017-06-15 19:24:38 +02:00
|
|
|
form = RegistrationForm({'full_name': ldap_full_name},
|
|
|
|
realm_creation=realm_creation)
|
2017-01-07 21:46:03 +01:00
|
|
|
# FIXME: This will result in the user getting
|
|
|
|
# validation errors if they have to enter a password.
|
|
|
|
# Not relevant for ONLY_SSO, though.
|
|
|
|
break
|
|
|
|
except TypeError:
|
|
|
|
# Let the user fill out a name and/or try another backend
|
2017-06-15 19:24:38 +02:00
|
|
|
form = RegistrationForm(realm_creation=realm_creation)
|
2017-01-07 21:46:03 +01:00
|
|
|
elif 'full_name' in request.POST:
|
|
|
|
form = RegistrationForm(
|
2017-06-15 19:24:38 +02:00
|
|
|
initial={'full_name': request.POST.get('full_name')},
|
|
|
|
realm_creation=realm_creation
|
2017-01-07 21:46:03 +01:00
|
|
|
)
|
|
|
|
else:
|
2017-06-15 19:24:38 +02:00
|
|
|
form = RegistrationForm(realm_creation=realm_creation)
|
2017-01-07 21:46:03 +01:00
|
|
|
else:
|
|
|
|
postdata = request.POST.copy()
|
|
|
|
if name_changes_disabled(realm):
|
|
|
|
# If we populate profile information via LDAP and we have a
|
|
|
|
# verified name from you on file, use that. Otherwise, fall
|
|
|
|
# back to the full name in the request.
|
|
|
|
try:
|
|
|
|
postdata.update({'full_name': request.session['authenticated_full_name']})
|
|
|
|
name_validated = True
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2017-06-15 19:24:38 +02:00
|
|
|
form = RegistrationForm(postdata, realm_creation=realm_creation)
|
2017-08-04 08:09:25 +02:00
|
|
|
if not (password_auth_enabled(realm) and password_required):
|
2017-01-07 21:46:03 +01:00
|
|
|
form['password'].field.required = False
|
|
|
|
|
|
|
|
if form.is_valid():
|
|
|
|
if password_auth_enabled(realm):
|
|
|
|
password = form.cleaned_data['password']
|
|
|
|
else:
|
|
|
|
# SSO users don't need no passwords
|
|
|
|
password = None
|
|
|
|
|
|
|
|
if realm_creation:
|
|
|
|
string_id = form.cleaned_data['realm_subdomain']
|
|
|
|
realm_name = form.cleaned_data['realm_name']
|
2017-08-24 04:52:34 +02:00
|
|
|
realm = do_create_realm(string_id, realm_name)
|
2017-07-17 06:44:59 +02:00
|
|
|
setup_initial_streams(realm)
|
2017-05-25 18:22:28 +02:00
|
|
|
assert(realm is not None)
|
2017-01-07 21:46:03 +01:00
|
|
|
|
|
|
|
full_name = form.cleaned_data['full_name']
|
|
|
|
short_name = email_to_username(email)
|
|
|
|
|
2017-05-04 15:19:50 +02:00
|
|
|
timezone = u""
|
|
|
|
if 'timezone' in request.POST and request.POST['timezone'] in get_all_timezones():
|
|
|
|
timezone = request.POST['timezone']
|
|
|
|
|
2017-08-25 07:05:27 +02:00
|
|
|
try:
|
|
|
|
existing_user_profile = get_user_profile_by_email(email)
|
|
|
|
except UserProfile.DoesNotExist:
|
|
|
|
existing_user_profile = None
|
|
|
|
|
2017-01-07 21:46:03 +01:00
|
|
|
if existing_user_profile is not None and existing_user_profile.is_mirror_dummy:
|
2017-03-19 01:42:40 +01:00
|
|
|
user_profile = existing_user_profile
|
|
|
|
do_activate_user(user_profile)
|
|
|
|
do_change_password(user_profile, password)
|
2017-04-07 07:28:28 +02:00
|
|
|
do_change_full_name(user_profile, full_name, user_profile)
|
2017-05-04 15:19:50 +02:00
|
|
|
do_set_user_display_setting(user_profile, 'timezone', timezone)
|
2017-01-07 21:46:03 +01:00
|
|
|
else:
|
|
|
|
user_profile = do_create_user(email, password, realm, full_name, short_name,
|
2017-08-18 07:12:22 +02:00
|
|
|
prereg_user=prereg_user, is_realm_admin=realm_creation,
|
2017-01-07 21:46:03 +01:00
|
|
|
tos_version=settings.TOS_VERSION,
|
2017-05-04 15:19:50 +02:00
|
|
|
timezone=timezone,
|
2017-01-07 21:46:03 +01:00
|
|
|
newsletter_data={"IP": request.META['REMOTE_ADDR']})
|
|
|
|
|
2017-07-17 06:21:53 +02:00
|
|
|
send_initial_pms(user_profile)
|
|
|
|
|
2017-08-05 08:48:20 +02:00
|
|
|
if realm_creation:
|
2017-07-17 06:21:53 +02:00
|
|
|
setup_initial_private_stream(user_profile)
|
|
|
|
send_initial_realm_messages(realm)
|
2017-06-14 19:55:07 +02:00
|
|
|
|
2017-01-07 21:46:03 +01:00
|
|
|
if realm_creation and settings.REALMS_HAVE_SUBDOMAINS:
|
|
|
|
# Because for realm creation, registration happens on the
|
|
|
|
# root domain, we need to log them into the subdomain for
|
|
|
|
# their new realm.
|
|
|
|
return redirect_and_log_into_subdomain(realm, full_name, email)
|
|
|
|
|
|
|
|
# This dummy_backend check below confirms the user is
|
|
|
|
# authenticating to the correct subdomain.
|
2017-05-17 22:13:34 +02:00
|
|
|
return_data = {} # type: Dict[str, bool]
|
2017-01-07 21:46:03 +01:00
|
|
|
auth_result = authenticate(username=user_profile.email,
|
|
|
|
realm_subdomain=realm.subdomain,
|
|
|
|
return_data=return_data,
|
|
|
|
use_dummy_backend=True)
|
|
|
|
if return_data.get('invalid_subdomain'):
|
|
|
|
# By construction, this should never happen.
|
|
|
|
logging.error("Subdomain mismatch in registration %s: %s" % (
|
|
|
|
realm.subdomain, user_profile.email,))
|
|
|
|
return redirect('/')
|
2017-08-23 01:14:45 +02:00
|
|
|
|
|
|
|
# Mark the user as having been just created, so no login email is sent
|
|
|
|
auth_result.just_registered = True
|
2017-08-25 01:11:30 +02:00
|
|
|
do_login(request, auth_result)
|
2017-01-07 21:46:03 +01:00
|
|
|
return HttpResponseRedirect(realm.uri + reverse('zerver.views.home.home'))
|
|
|
|
|
2017-03-16 14:28:08 +01:00
|
|
|
return render(
|
|
|
|
request,
|
2017-01-07 21:46:03 +01:00
|
|
|
'zerver/register.html',
|
2017-03-16 14:28:08 +01:00
|
|
|
context={'form': form,
|
|
|
|
'email': email,
|
|
|
|
'key': key,
|
|
|
|
'full_name': request.session.get('authenticated_full_name', None),
|
|
|
|
'lock_name': name_validated and name_changes_disabled(realm),
|
|
|
|
# password_auth_enabled is normally set via our context processor,
|
|
|
|
# but for the registration form, there is no logged in user yet, so
|
|
|
|
# we have to set it here.
|
|
|
|
'creating_new_team': realm_creation,
|
|
|
|
'realms_have_subdomains': settings.REALMS_HAVE_SUBDOMAINS,
|
2017-08-09 22:09:38 +02:00
|
|
|
'password_required': password_auth_enabled(realm) and password_required,
|
2017-03-16 14:28:08 +01:00
|
|
|
'password_auth_enabled': password_auth_enabled(realm),
|
2017-03-23 00:15:06 +01:00
|
|
|
'MAX_REALM_NAME_LENGTH': str(Realm.MAX_REALM_NAME_LENGTH),
|
|
|
|
'MAX_NAME_LENGTH': str(UserProfile.MAX_NAME_LENGTH),
|
|
|
|
'MAX_PASSWORD_LENGTH': str(form.MAX_PASSWORD_LENGTH),
|
|
|
|
'MAX_REALM_SUBDOMAIN_LENGTH': str(Realm.MAX_REALM_SUBDOMAIN_LENGTH)
|
2017-03-16 14:28:08 +01:00
|
|
|
}
|
|
|
|
)
|
2017-01-07 21:46:03 +01:00
|
|
|
|
2017-08-04 08:09:25 +02:00
|
|
|
def create_preregistration_user(email, request, realm_creation=False,
|
|
|
|
password_required=True):
|
|
|
|
# type: (Text, HttpRequest, bool, bool) -> HttpResponse
|
|
|
|
return PreregistrationUser.objects.create(email=email,
|
|
|
|
realm_creation=realm_creation,
|
|
|
|
password_required=password_required)
|
2017-01-07 21:46:03 +01:00
|
|
|
|
|
|
|
def send_registration_completion_email(email, request, realm_creation=False):
|
2017-06-11 00:58:00 +02:00
|
|
|
# type: (str, HttpRequest, bool) -> None
|
2017-01-07 21:46:03 +01:00
|
|
|
"""
|
|
|
|
Send an email with a confirmation link to the provided e-mail so the user
|
|
|
|
can complete their registration.
|
|
|
|
"""
|
|
|
|
prereg_user = create_preregistration_user(email, request, realm_creation)
|
2017-07-08 04:38:13 +02:00
|
|
|
activation_url = create_confirmation_link(prereg_user, request.get_host(), Confirmation.USER_REGISTRATION)
|
2017-07-11 05:01:32 +02:00
|
|
|
send_email('zerver/emails/confirm_registration', to_email=email, from_address=FromAddress.NOREPLY,
|
2017-06-11 00:39:58 +02:00
|
|
|
context={'activate_url': activation_url})
|
2017-06-11 00:58:00 +02:00
|
|
|
if settings.DEVELOPMENT and realm_creation:
|
2017-06-11 00:39:58 +02:00
|
|
|
request.session['confirmation_key'] = {'confirmation_key': activation_url.split('/')[-1]}
|
2017-01-07 21:46:03 +01:00
|
|
|
|
|
|
|
def redirect_to_email_login_url(email):
|
|
|
|
# type: (str) -> HttpResponseRedirect
|
|
|
|
login_url = reverse('django.contrib.auth.views.login')
|
|
|
|
redirect_url = login_url + '?email=' + urllib.parse.quote_plus(email)
|
|
|
|
return HttpResponseRedirect(redirect_url)
|
|
|
|
|
|
|
|
def create_realm(request, creation_key=None):
|
|
|
|
# type: (HttpRequest, Optional[Text]) -> HttpResponse
|
|
|
|
if not settings.OPEN_REALM_CREATION:
|
|
|
|
if creation_key is None:
|
2017-03-16 14:28:08 +01:00
|
|
|
return render(request, "zerver/realm_creation_failed.html",
|
|
|
|
context={'message': _('New organization creation disabled.')})
|
2017-01-07 21:46:03 +01:00
|
|
|
elif not check_key_is_valid(creation_key):
|
2017-03-16 14:28:08 +01:00
|
|
|
return render(request, "zerver/realm_creation_failed.html",
|
|
|
|
context={'message': _('The organization creation link has expired'
|
|
|
|
' or is not valid.')})
|
2017-01-07 21:46:03 +01:00
|
|
|
|
|
|
|
# When settings.OPEN_REALM_CREATION is enabled, anyone can create a new realm,
|
|
|
|
# subject to a few restrictions on their email address.
|
|
|
|
if request.method == 'POST':
|
|
|
|
form = RealmCreationForm(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
email = form.cleaned_data['email']
|
2017-08-17 19:59:17 +02:00
|
|
|
try:
|
|
|
|
send_registration_completion_email(email, request, realm_creation=True)
|
|
|
|
except smtplib.SMTPException as e:
|
|
|
|
logging.error('Error in create_realm: %s' % (str(e),))
|
|
|
|
return HttpResponseRedirect("/config-error/smtp")
|
|
|
|
|
2017-01-07 21:46:03 +01:00
|
|
|
if (creation_key is not None and check_key_is_valid(creation_key)):
|
|
|
|
RealmCreationKey.objects.get(creation_key=creation_key).delete()
|
|
|
|
return HttpResponseRedirect(reverse('send_confirm', kwargs={'email': email}))
|
|
|
|
try:
|
|
|
|
email = request.POST['email']
|
|
|
|
user_email_is_unique(email)
|
|
|
|
except ValidationError:
|
|
|
|
# Maybe the user is trying to log in
|
|
|
|
return redirect_to_email_login_url(email)
|
|
|
|
else:
|
|
|
|
form = RealmCreationForm()
|
2017-03-16 14:28:08 +01:00
|
|
|
return render(request,
|
|
|
|
'zerver/create_realm.html',
|
|
|
|
context={'form': form, 'current_url': request.get_full_path},
|
|
|
|
)
|
2017-01-07 21:46:03 +01:00
|
|
|
|
|
|
|
def confirmation_key(request):
|
|
|
|
# type: (HttpRequest) -> HttpResponse
|
|
|
|
return json_success(request.session.get('confirmation_key'))
|
|
|
|
|
|
|
|
def get_realm_from_request(request):
|
|
|
|
# type: (HttpRequest) -> Realm
|
|
|
|
if settings.REALMS_HAVE_SUBDOMAINS:
|
|
|
|
realm_str = get_subdomain(request)
|
|
|
|
else:
|
2017-08-24 04:33:51 +02:00
|
|
|
realm_str = None
|
2017-01-07 21:46:03 +01:00
|
|
|
return get_realm(realm_str)
|
|
|
|
|
2017-08-24 09:58:44 +02:00
|
|
|
def show_deactivation_notice(request):
|
|
|
|
# type: (HttpRequest) -> HttpResponse
|
|
|
|
realm = get_realm_from_request(request)
|
|
|
|
if realm and realm.deactivated:
|
|
|
|
return render(request, "zerver/deactivated.html",
|
|
|
|
context={"deactivated_domain_name": realm.name})
|
|
|
|
|
|
|
|
return HttpResponseRedirect(reverse('zerver.views.auth.login_page'))
|
|
|
|
|
|
|
|
def redirect_to_deactivation_notice():
|
|
|
|
# type: () -> HttpResponse
|
|
|
|
return HttpResponseRedirect(reverse('zerver.views.registration.show_deactivation_notice'))
|
|
|
|
|
2017-01-07 21:46:03 +01:00
|
|
|
def accounts_home(request):
|
|
|
|
# type: (HttpRequest) -> HttpResponse
|
|
|
|
realm = get_realm_from_request(request)
|
2017-08-24 09:58:44 +02:00
|
|
|
if realm and realm.deactivated:
|
|
|
|
return redirect_to_deactivation_notice()
|
|
|
|
|
2017-01-07 21:46:03 +01:00
|
|
|
if request.method == 'POST':
|
|
|
|
form = HomepageForm(request.POST, realm=realm)
|
|
|
|
if form.is_valid():
|
|
|
|
email = form.cleaned_data['email']
|
2017-08-17 18:28:21 +02:00
|
|
|
try:
|
|
|
|
send_registration_completion_email(email, request)
|
|
|
|
except smtplib.SMTPException as e:
|
|
|
|
logging.error('Error in accounts_home: %s' % (str(e),))
|
|
|
|
return HttpResponseRedirect("/config-error/smtp")
|
|
|
|
|
2017-01-07 21:46:03 +01:00
|
|
|
return HttpResponseRedirect(reverse('send_confirm', kwargs={'email': email}))
|
2017-08-25 07:05:27 +02:00
|
|
|
|
|
|
|
email = request.POST['email']
|
2017-01-07 21:46:03 +01:00
|
|
|
try:
|
2017-08-25 07:05:27 +02:00
|
|
|
validate_email_for_realm(realm, email)
|
2017-01-07 21:46:03 +01:00
|
|
|
except ValidationError:
|
|
|
|
return redirect_to_email_login_url(email)
|
|
|
|
else:
|
|
|
|
form = HomepageForm(realm=realm)
|
2017-03-16 14:28:08 +01:00
|
|
|
return render(request,
|
|
|
|
'zerver/accounts_home.html',
|
|
|
|
context={'form': form, 'current_url': request.get_full_path},
|
|
|
|
)
|
2017-01-07 21:46:03 +01:00
|
|
|
|
|
|
|
def generate_204(request):
|
|
|
|
# type: (HttpRequest) -> HttpResponse
|
|
|
|
return HttpResponse(content=None, status=204)
|
|
|
|
|
|
|
|
def find_my_team(request):
|
|
|
|
# type: (HttpRequest) -> HttpResponse
|
|
|
|
url = reverse('zerver.views.registration.find_my_team')
|
|
|
|
|
|
|
|
emails = [] # type: List[Text]
|
|
|
|
if request.method == 'POST':
|
|
|
|
form = FindMyTeamForm(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
emails = form.cleaned_data['emails']
|
2017-08-25 08:14:55 +02:00
|
|
|
for user_profile in UserProfile.objects.filter(
|
|
|
|
email__in=emails, is_active=True, is_bot=False, realm__deactivated=False):
|
2017-07-11 05:01:32 +02:00
|
|
|
send_email('zerver/emails/find_team', to_user_id=user_profile.id,
|
|
|
|
context={'user_profile': user_profile})
|
2017-01-07 21:46:03 +01:00
|
|
|
|
|
|
|
# Note: Show all the emails in the result otherwise this
|
|
|
|
# feature can be used to ascertain which email addresses
|
|
|
|
# are associated with Zulip.
|
|
|
|
data = urllib.parse.urlencode({'emails': ','.join(emails)})
|
|
|
|
return redirect(url + "?" + data)
|
|
|
|
else:
|
|
|
|
form = FindMyTeamForm()
|
|
|
|
result = request.GET.get('emails')
|
2017-08-25 08:30:33 +02:00
|
|
|
# The below validation is perhaps unnecessary, in that we
|
|
|
|
# shouldn't get able to get here with an invalid email unless
|
|
|
|
# the user hand-edits the URLs.
|
2017-01-07 21:46:03 +01:00
|
|
|
if result:
|
|
|
|
for email in result.split(','):
|
|
|
|
try:
|
|
|
|
validators.validate_email(email)
|
|
|
|
emails.append(email)
|
|
|
|
except ValidationError:
|
|
|
|
pass
|
|
|
|
|
2017-03-16 14:28:08 +01:00
|
|
|
return render(request,
|
|
|
|
'zerver/find_my_team.html',
|
|
|
|
context={'form': form, 'current_url': lambda: url,
|
|
|
|
'emails': emails},)
|