Send notification mails when re-authentication is needed
This commit is contained in:
parent
1781eb2875
commit
804a7ec8bb
2 changed files with 25 additions and 2 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
from django.core.mail import send_mail
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
@ -107,7 +109,15 @@ class RedditTokenTask(app.Task):
|
||||||
user.reddit_refresh_token = None
|
user.reddit_refresh_token = None
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
# TODO add notification mail
|
message = _(
|
||||||
|
"Your Reddit account credentials have expired. Re-authenticate in"
|
||||||
|
" the settings page to keep retrieving Reddit specific information"
|
||||||
|
" from your account."
|
||||||
|
)
|
||||||
|
|
||||||
|
send_mail(
|
||||||
|
"Reddit account needs re-authentication", message, None, [user.email]
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,10 @@ from datetime import datetime
|
||||||
from json import JSONDecodeError
|
from json import JSONDecodeError
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.mail import send_mail
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.html import format_html, urlize
|
from django.utils.html import format_html, urlize
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
|
|
@ -240,7 +242,18 @@ class TwitterClient(PostClient):
|
||||||
stream.rule.user.twitter_oauth_token_secret = None
|
stream.rule.user.twitter_oauth_token_secret = None
|
||||||
stream.rule.user.save()
|
stream.rule.user.save()
|
||||||
|
|
||||||
# TODO add notification mail
|
message = _(
|
||||||
|
"Your Twitter account credentials have expired. Re-authenticate in"
|
||||||
|
" the settings page to keep retrieving Twitter specific information"
|
||||||
|
" from your account."
|
||||||
|
)
|
||||||
|
|
||||||
|
send_mail(
|
||||||
|
"Twitter account needs re-authentication",
|
||||||
|
message,
|
||||||
|
None,
|
||||||
|
[stream.rule.user.email],
|
||||||
|
)
|
||||||
|
|
||||||
self.set_rule_error(stream.rule, e)
|
self.set_rule_error(stream.rule, e)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue