@@ 378-400 (lines=23) @@ | ||
375 | def send_new_email_ver(request, user, email): |
|
376 | new_ver = Verification(user=user, type_enum=Verification.TypeChoices.confirm_email, email=email) |
|
377 | new_ver.save() |
|
378 | link = "{}://{}/confirm_email?token={}".format(settings.SITE_PROTOCOL, request.get_host(), new_ver.token) |
|
379 | text = ('Hi {}, you have changed email to curren on pychat \nTo verify it, please click on the url: {}') \ |
|
380 | .format(user.username, link) |
|
381 | start_message = mark_safe("You have changed email to current one in <b>Pychat</b>. \n" |
|
382 | "To stay safe please verify it by clicking on the url below.") |
|
383 | context = { |
|
384 | 'username': user.username, |
|
385 | 'magicLink': link, |
|
386 | 'btnText': "CONFIRM THIS EMAIL", |
|
387 | 'greetings': start_message |
|
388 | } |
|
389 | html_message = render_to_string('sign_up_email.html', context, context_instance=RequestContext(request)) |
|
390 | logger.info('Sending verification email to userId %s (email %s)', user.id, email) |
|
391 | try: |
|
392 | send_mail("Confirm this email", text, request.get_host(), [email, ], html_message=html_message, |
|
393 | fail_silently=False) |
|
394 | return new_ver |
|
395 | except Exception as e: |
|
396 | logger.exception("Failed to send email") |
|
397 | raise ValidationError(e.message) |
|
398 | ||
399 | ||
400 | def send_email_change(request, username, old_email, verification, new_email): |
|
401 | link = "{}://{}/change_email?token={}".format(settings.SITE_PROTOCOL, request.get_host(), verification.token) |
|
402 | message = "{},\n" \ |
|
403 | "You requested to change an email from {} to {} on site {}.\n" \ |
|
@@ 417-429 (lines=13) @@ | ||
414 | 'ip': ip_info.ip, |
|
415 | 'btnText': "CHANGE EMAIL", |
|
416 | 'timeCreated': verification.time, |
|
417 | 'greetings': start_message |
|
418 | } |
|
419 | html_message = render_to_string('token_email.html', context, context_instance=RequestContext(request)) |
|
420 | send_mail("Pychat: change email", message, request.get_host(), (old_email,), fail_silently=False, |
|
421 | html_message=html_message) |
|
422 | ||
423 | ||
424 | def send_password_changed(request, email): |
|
425 | message = "Password has been changed for user {}".format(request.user.username) |
|
426 | ip_info = get_or_create_ip(get_client_ip(request), logger) |
|
427 | context = { |
|
428 | 'username': request.user.username, |
|
429 | 'ipInfo': ip_info.info, |
|
430 | 'ip': ip_info.ip, |
|
431 | 'timeCreated': datetime.datetime.now(), |
|
432 | } |