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