diff --git a/djangoapps/student/views.py b/djangoapps/student/views.py index 017e1b3bb5..298df617e4 100644 --- a/djangoapps/student/views.py +++ b/djangoapps/student/views.py @@ -188,8 +188,7 @@ def create_account(request, post_override=None): up.save() d={'name':post_vars['name'], - 'key':r.activation_key, - 'site':settings.SITE_NAME} + 'key':r.activation_key} subject = render_to_string('emails/activation_email_subject.txt',d) # Email subject *must not* contain newlines @@ -282,8 +281,7 @@ def reactivation_email(request): reg.register(user) d={'name':UserProfile.get(user = user).name, - 'key':r.activation_key, - 'site':settings.SITE_NAME} + 'key':r.activation_key} subject = render_to_string('reactivation_email_subject.txt',d) subject = ''.join(subject.splitlines()) @@ -336,8 +334,7 @@ def change_email_request(request): return HttpResponse(json.dumps({'success':False, 'error':'Old email is the same as the new email.'})) - d = {'site':settings.SITE_NAME, - 'key':pec.activation_key, + d = {'key':pec.activation_key, 'old_email' : user.email, 'new_email' : pec.new_email} @@ -360,9 +357,8 @@ def confirm_email_change(request, key): return render_to_response("invalid_email_key.html", {}) user = pec.user - d = {'site':settings.SITE_NAME, - 'old_email' : user.email, - 'new_email' : pec.new_email} + d = {'old_email' : user.email, + 'new_email' : pec.new_email} if len(User.objects.filter(email = pec.new_email)) != 0: return render_to_response("email_exists.html", d) diff --git a/lib/mitxmako/middleware.py b/lib/mitxmako/middleware.py index 857ae29541..1d175abbf7 100644 --- a/lib/mitxmako/middleware.py +++ b/lib/mitxmako/middleware.py @@ -7,7 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, +# distribuetd under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. @@ -15,6 +15,7 @@ from mako.lookup import TemplateLookup import tempfile from django.template import RequestContext +from django.conf import settings requestcontext = None lookup = {} @@ -44,4 +45,5 @@ class MakoMiddleware(object): def process_request (self, request): global requestcontext requestcontext = RequestContext(request) - + requestcontext['is_secure'] = request.is_secure() + requestcontext['site'] = settings.SITE_NAME diff --git a/lib/mitxmako/shortcuts.py b/lib/mitxmako/shortcuts.py index 862f8b96bb..ca626b5c85 100644 --- a/lib/mitxmako/shortcuts.py +++ b/lib/mitxmako/shortcuts.py @@ -18,18 +18,21 @@ from django.http import HttpResponse import mitxmako.middleware as middleware from django.conf import settings -from mitxmako.middleware import requestcontext +import mitxmako.middleware -def render_to_string(template_name, dictionary, context_instance=None, namespace='main'): - context_instance = context_instance or Context(dictionary) +def render_to_string(template_name, dictionary, context=None, namespace='main'): + context_instance = Context(dictionary) # add dictionary to context_instance context_instance.update(dictionary or {}) # collapse context_instance to a single dictionary for mako context_dictionary = {} context_instance['settings'] = settings - context_instance['request_context'] = requestcontext + for d in mitxmako.middleware.requestcontext: + context_dictionary.update(d) for d in context_instance: context_dictionary.update(d) + if context: + context_dictionary.update(context) # fetch and render template template = middleware.lookup[namespace].get_template(template_name) return template.render(**context_dictionary) diff --git a/templates/emails/activation_email.txt b/templates/emails/activation_email.txt index d53fa05022..7f042995ed 100644 --- a/templates/emails/activation_email.txt +++ b/templates/emails/activation_email.txt @@ -3,7 +3,11 @@ offering of 6.002 using this email address. If it was you, and you'd like to activate and use your account, copy and paste this address into your web browser's address bar: -https://${ site }/activate/${ key } +% if is_secure: + https://${ site }/activate/${ key } +% else: + http://${ site }/activate/${ key } +% endif If you didn't request this, you don't need to do anything; you won't receive any more email from us. Please do not reply to this e-mail; if diff --git a/templates/emails/confirm_email_change.txt b/templates/emails/confirm_email_change.txt index b213847f98..f6c3609295 100644 --- a/templates/emails/confirm_email_change.txt +++ b/templates/emails/confirm_email_change.txt @@ -3,7 +3,11 @@ from ${old_email} to ${new_email}. If you did not make this request, please contact the course staff immediately. Contact information is listed at: +% if is_secure: https://${ site }/t/mitx_help.html +% else: + http://${ site }/t/mitx_help.html +% endif We keep a log of old e-mails, so if this request was unintentional, we can investigate. diff --git a/templates/emails/email_change.txt b/templates/emails/email_change.txt index 086b758135..51be82f564 100644 --- a/templates/emails/email_change.txt +++ b/templates/emails/email_change.txt @@ -2,7 +2,11 @@ We received a request to change the e-mail associated with your MITx account from ${old_email} to ${new_email}. If this is correct, please confirm your new e-mail address by visiting: -https://${ site }/email_confirm/${ key } +% if is_secure: + https://${ site }/email_confirm/${ key } +% else: + http://${ site }/email_confirm/${ key } +% endif If you didn't request this, you don't need to do anything; you won't receive any more email from us. Please do not reply to this e-mail; if diff --git a/templates/emails/welcome_body.txt b/templates/emails/welcome_body.txt index bc859c88cf..b08326f6fd 100644 --- a/templates/emails/welcome_body.txt +++ b/templates/emails/welcome_body.txt @@ -1,6 +1,10 @@ MITx's prototype offering, 6.002x, is now open. To log in, visit +% if is_secure: https://6002x.mitx.mit.edu +% else: + http://6002x.mitx.mit.edu +% endif where you will find a login button at the top right-hand corner of the window.