Skip to content

Commit 170b9fc

Browse files
memo330179Jesson Soto Ventura
authored andcommitted
set up email
1 parent 853c5fa commit 170b9fc

File tree

4 files changed

+63
-19
lines changed

4 files changed

+63
-19
lines changed

api/API/files.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from parameters import getCurrentParameters
33
from ..everything import *
44
#Flask mail imports
5-
from flask_mail import Mail, Message
5+
from flask_mail import Message
6+
67

78

89

@@ -18,26 +19,21 @@ def removeFiles(username):
1819
currentParameter = getCurrentParameters()
1920
folder_path = os.path.join(base_path, cfg["filepaths"]["projectFiles"], str(currentParameter.year), username)
2021
shutil.rmtree(folder_path)
22+
2123

2224

23-
def send_email(user_email, app=None):
24-
'''this function sends email to the user email
25-
specify port, mail-server, username, password in settings.py
25+
26+
27+
def create_message(username_email):
2628
'''
27-
mail=Mail(app)
28-
msg=Message("Hello",
29-
30-
recipients=[user_email]
31-
)
32-
msg.body="this is a messsage body"
33-
mail.send(msg)
34-
35-
@app.route("/email")
36-
def email():
37-
'''this route is for testing purposes'''
38-
my_email="[email protected]"
39-
send_email(my_email, app)
40-
return "Message is sent."
29+
Parameters:
30+
username_email(s) - Emails of the recipients
31+
'''
32+
msg = Message("Subject",
33+
34+
recipients=[username_email]) #create a message instance
35+
msg.html = '<b>HTML</b> body'
36+
return msg
4137

4238

4339

api/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@
4242
import chair.awardLetters
4343
import chair.setParameters
4444
import chair.manageCommittee
45+
import chair.email_accepted
4546

4647
import flaskLogin

api/chair/email_accepted.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from ..everything import *
2+
from ..API.faculty import getFacultyWithProjects, getFacultyByYear
3+
from ..API.parameters import getCurrentParameters
4+
from ..API.files import removeFiles
5+
from ..API.files import create_message
6+
7+
@app.route("/email/accepted", methods = ["GET"])
8+
@login_required
9+
def emailProjects_GET ():
10+
if not g.user.isChair:
11+
abort(403)
12+
# All of our queries
13+
# we need the current year to get current faculty with projects
14+
currentCycle = getCurrentParameters()
15+
16+
faculty = getFacultyWithProjects(currentCycle.year)
17+
18+
return render_template ( "chair/allProjects.html",
19+
username = g.user.username,
20+
cfg = cfg,
21+
fac = faculty,
22+
)
23+
24+
@app.route("/email")
25+
def email():
26+
'''this route is for testing purposes'''
27+
my_email="[email protected]"
28+
print("I AM SENDING THINGS")
29+
msg = create_message(my_email)
30+
mail.send(msg)
31+
return "Message is sent."
32+
33+
34+
@app.route("/email/<username>")
35+
@login_required
36+
def view_email(username):
37+
currentCycle = getCurrentParameters()
38+
39+
faculty = getFacultyByYear(username, currentCycle.year)
40+
41+
return render_template("snips/email.html",
42+
person = faculty,
43+
cfg = cfg)
44+

api/everything.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
# Import the models
2828
from models import *
29+
from flask_mail import Mail
2930

3031
# For unique values
3132
import uuid
@@ -57,6 +58,8 @@ def authUser(env):
5758
login_manager.login_view = 'login'
5859
login_manager.login_message = None
5960

61+
mail = Mail(app) #mail using configuration values of the application
62+
6063
from api.switch import switch
6164
from api.config import load_config
6265

@@ -81,4 +84,4 @@ def teardown_request(exception):
8184

8285
@login_manager.user_loader
8386
def load_user(fID):
84-
return LDAPFaculty.get(LDAPFaculty.fID == fID)
87+
return LDAPFaculty.get(LDAPFaculty.fID == fID)

0 commit comments

Comments
 (0)