def welcome(request): """ Respond to the "/" URL. We display the welcome page for the application, or redirect the user to to /web/home if they are logged in. """ return render(request, "disabled.html") if webHelpers.is_logged_in(request): return redirect("/web/home/") if request.is_secure(): base_url = "https://" + request.get_host() else: base_url = "http://" + request.get_host() eventRecorder.record_event(eventRecorder.EVENT_TYPE_HOME_PAGE_HIT) return render(request, "welcome.html", {"hideBrand" : True, "base_url" : base_url, "help_div_class" : "messageme-international-help " + "modal mm-hidden well"})
def home(request): """ Respond to the "/web/home" URL. We display the home page for a logged in user. If the current user is not logged in, we redirect the user back to the welcome page. """ if not webHelpers.is_logged_in(request): return redirect("/") # Calculate the environment we're running in. We use this to load the # appropriate version of the widget javascript for the environment. if ("127.0.0.1" in request.get_host()) or ("local" in request.get_host()): environment = "dev" elif "stage" in request.get_host(): environment = "stage" else: environment = "prod" # Get the name of the widget javascript to use for this environment. if environment == "dev": widget_script = "widget-dev.js" elif environment == "stage": widget_script = "widget-stage.js" elif environment == "prod": widget_script = "widget.js" # Get the base URL to use to access this server. if request.is_secure(): base_url = "https://" + request.get_host() else: base_url = "http://" + request.get_host() # Get the details of the current user. session = request.COOKIES['mm_session'] user = users.get(session) # If the user doesn't have a username, something is wrong -- we can't # proceed. In this case, delete the session cookie and redirect the user # back to the "welcome" page. if "username" not in user: response = redirect("/") response.delete_cookie("mm_session") return response # Ask the 3taps Identity API for the user's profile. profile = profiles.get(session) # Get a list of the user's topics. topic_list = [] for topic in topics.list(session): if not topic['active']: continue topic_info = {} topic_info['id'] = topic['id'] topic_info['hide_username'] = topic['hide_username'] if topic.get("name") in [None, ""]: # Default topic. topic_info['url'] = base_url + "/" + user['username'] topic_info['hidden_url'] = base_url + "/!" + topic['hidden_url'] topic_info['default'] = True else: # A named topic. topic_info['url'] = base_url + "/" + user['username'] \ + "/" + topic['name'] topic_info['hidden_url'] = base_url + "/!" + topic['hidden_url'] \ + "/" + topic['name'] topic_info['default'] = False topic_info['num_views'] = topic['num_views'] topic_info['num_conversations'] = topic['num_conversations'] topic_info['num_messages'] = topic['num_messages'] topic_info['num_via_sms'] = topic['num_via_sms'] topic_info['embed_code'] = linkGenerator.generate_link_html( request, topic) topic_list.append(topic_info) # Get the user's account details. phone_number = user['phone_number'] rate_limit = rateLimiter.get_phone_number_limit(phone_number) period = settings.SMS_RATE_LIMIT_PERIOD_SIZE num_sms_in_period = rateLimiter.get_phone_number_usage(phone_number) account = {} account['rate_limited'] = True # Hardwired for now. account['rate_limit'] = rate_limit account['period'] = period.lower() account['num_sms_in_period'] = num_sms_in_period # Finally, show the home page. if "n=t" in request.get_full_path(): # We're showing the home page for the first time -> display the # "welcome" message. show_welcome = True else: show_welcome = False return render(request, "home.html", {'user' : user, 'profile' : profile, 'topics' : topic_list, 'account' : account, 'show_welcome' : show_welcome, 'base_url' : base_url})