Skip to content

Commit

Permalink
fix/use enviroment variable for sensetive information
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-benyamin committed Jun 12, 2023
1 parent 86e7fc7 commit 8289270
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
melipayamak_token=""
email_password=""
2 changes: 1 addition & 1 deletion TODOs.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### version 4

- [ ] add link to your github
- [ ] save variables in os.environt
- [X] save variables in os.environt
- [ ] wirte good cv
- [ ] intro video
- [ ] send notifications (e.g. errors, contact me, etc...) in
Expand Down
9 changes: 6 additions & 3 deletions app/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

from pathlib import Path
import os
from pathlib import Path

from dotenv import load_dotenv

from config.settings.local import email_password

# load enviroment variables from .env file
load_dotenv()

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent.parent
Expand Down Expand Up @@ -142,4 +145,4 @@
EMAIL_PORT = 25
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'admin@iambenyamin.com'
EMAIL_HOST_PASSWORD = email_password
EMAIL_HOST_PASSWORD = os.getenv("melipayamak_token")
3 changes: 0 additions & 3 deletions app/config/settings/local.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@

melipayamak_token = 'meli payamak token'
email_password = 'email password'
8 changes: 5 additions & 3 deletions app/home/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import requests
import requests, os

from blog.models import Article as ArticleModel
from config.settings.local import melipayamak_token
from django.contrib import messages
from django.shortcuts import redirect, render
from django.urls import reverse_lazy
Expand Down Expand Up @@ -55,7 +54,10 @@ def connect_me_form_view(request):
'to': '09109667550',
'text': f'A person named "{name}" is working with you about the "{subject}"\n\n https://b2n.ir/g57087',
}
response = requests.post(melipayamak_token, json=data)
response = requests.post(
f"https://console.melipayamak.com/api/send/simple/{os.getenv('melipayamak_token')}",
json=data
)
messages.success(
request,
"Hi! I received your message!"
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Pillow==9.1
django-ckeditor==6.4.2
djangorestframework==3.13.1
requests==2.28.1
psycopg2-binary==2.9.5
psycopg2-binary==2.9.5
python-dotenv==1.0.0

0 comments on commit 8289270

Please sign in to comment.