Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
6
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LiberaForms
server
Commits
51dee7be
Commit
51dee7be
authored
Mar 12, 2020
by
buttle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added starttls (may work) to smtp config.
Added check for available email
parent
a03e42fc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
20 deletions
+32
-20
email.py
email.py
+17
-9
persistence.py
persistence.py
+3
-0
templates/smtp-config.html
templates/smtp-config.html
+1
-0
views.py
views.py
+11
-11
No files found.
email.py
View file @
51dee7be
...
...
@@ -21,7 +21,7 @@ from flask import g, flash, request
from
flask_babel
import
gettext
from
GNGforms
import
app
from
GNGforms.persistence
import
Site
import
smtplib
,
socket
import
smtplib
,
s
sl
,
s
ocket
from
threading
import
Thread
def
createSmtpObj
():
...
...
@@ -30,10 +30,18 @@ def createSmtpObj():
if
config
[
"encryption"
]
==
"SSL"
:
server
=
smtplib
.
SMTP_SSL
(
config
[
"host"
],
port
=
config
[
"port"
],
timeout
=
2
)
server
.
login
(
config
[
"user"
],
config
[
"password"
])
elif
config
[
"encryption"
]
==
"STARTTLS"
:
server
=
smtplib
.
SMTP_SSL
(
config
[
"host"
],
port
=
config
[
"port"
],
timeout
=
2
)
context
=
ssl
.
create_default_context
()
server
.
starttls
(
context
=
context
)
server
.
login
(
config
[
"user"
],
config
[
"password"
])
else
:
server
=
smtplib
.
SMTP
(
config
[
"host"
],
port
=
config
[
"port"
])
if
config
[
"user"
]
and
config
[
"password"
]:
server
.
login
(
config
[
"user"
],
config
[
"password"
])
return
server
except
socket
.
error
as
e
:
if
g
.
isAdmin
:
...
...
@@ -55,7 +63,7 @@ def sendMail(email, message):
return
False
def
s
mtpS
endConfirmEmail
(
user
,
newEmail
=
None
):
def
sendConfirmEmail
(
user
,
newEmail
=
None
):
link
=
"%suser/validate-email/%s"
%
(
Site
().
host_url
,
user
.
token
[
'token'
])
message
=
gettext
(
"Hello %s
\n\n
Please confirm your email
\n\n
%s"
)
%
(
user
.
username
,
link
)
message
=
'Subject: {}
\n\n
{}'
.
format
(
gettext
(
"GNGforms. Confirm email"
),
message
)
...
...
@@ -65,7 +73,7 @@ def smtpSendConfirmEmail(user, newEmail=None):
return
sendMail
(
user
.
email
,
message
)
def
s
mtpS
endInvite
(
invite
):
def
sendInvite
(
invite
):
site
=
Site
(
hostname
=
invite
.
data
[
'hostname'
])
link
=
"%suser/new/%s"
%
(
site
.
host_url
,
invite
.
data
[
'token'
][
'token'
])
message
=
"%s
\n\n
%s"
%
(
invite
.
data
[
'message'
],
link
)
...
...
@@ -74,7 +82,7 @@ def smtpSendInvite(invite):
return
sendMail
(
invite
.
data
[
'email'
],
message
)
def
s
mtpS
endRecoverPassword
(
user
):
def
sendRecoverPassword
(
user
):
link
=
"%ssite/recover-password/%s"
%
(
Site
().
host_url
,
user
.
token
[
'token'
])
message
=
gettext
(
"Please use this link to recover your password"
)
message
=
"%s
\n\n
%s"
%
(
message
,
link
)
...
...
@@ -83,7 +91,7 @@ def smtpSendRecoverPassword(user):
return
sendMail
(
user
.
email
,
message
)
def
s
mtpS
endNewFormEntryNotification
(
emails
,
entry
,
slug
):
def
sendNewFormEntryNotification
(
emails
,
entry
,
slug
):
message
=
gettext
(
"New form entry in %s at %s
\n
"
%
(
slug
,
Site
().
hostname
))
for
data
in
entry
:
message
=
"%s
\n
%s: %s"
%
(
message
,
data
[
0
],
data
[
1
])
...
...
@@ -93,21 +101,21 @@ def smtpSendNewFormEntryNotification(emails, entry, slug):
for
email
in
emails
:
sendMail
(
email
,
message
)
def
s
mtpS
endExpiredFormNotification
(
editorEmails
,
form
):
def
sendExpiredFormNotification
(
editorEmails
,
form
):
message
=
gettext
(
"The form '%s' has expired at %s"
%
(
form
.
slug
,
Site
().
hostname
))
message
=
'Subject: {}
\n\n
{}'
.
format
(
gettext
(
"GNGforms. A form has expired"
),
message
)
for
email
in
editorEmails
:
sendMail
(
email
,
message
)
def
s
mtpS
endNewFormNotification
(
adminEmails
,
form
):
def
sendNewFormNotification
(
adminEmails
,
form
):
message
=
gettext
(
"New form '%s' created at %s"
%
(
form
.
slug
,
Site
().
hostname
))
message
=
'Subject: {}
\n\n
{}'
.
format
(
gettext
(
"GNGforms. New form notification"
),
message
)
for
email
in
adminEmails
:
sendMail
(
email
,
message
)
def
s
mtpS
endNewUserNotification
(
adminEmails
,
username
):
def
sendNewUserNotification
(
adminEmails
,
username
):
message
=
gettext
(
"New user '%s' created at %s"
%
(
username
,
Site
().
hostname
))
message
=
'Subject: {}
\n\n
{}'
.
format
(
gettext
(
"GNGforms. New user notification"
),
message
)
...
...
@@ -115,7 +123,7 @@ def smtpSendNewUserNotification(adminEmails, username):
sendMail
(
email
,
message
)
def
s
mtpS
endTestEmail
(
email
):
def
sendTestEmail
(
email
):
message
=
gettext
(
"Congratulations!"
)
message
=
'Subject: {}
\n\n
{}'
.
format
(
gettext
(
"SMTP test"
),
message
)
...
...
persistence.py
View file @
51dee7be
...
...
@@ -139,6 +139,9 @@ class User(object):
if
User
(
email
=
email
):
flash
(
gettext
(
"Email address is not available"
),
'warning'
)
return
False
if
email
in
app
.
config
[
'ROOT_USERS'
]
and
Installation
.
isUser
(
email
):
flash
(
gettext
(
"Email address is not available"
),
'warning'
)
return
False
return
True
...
...
templates/smtp-config.html
View file @
51dee7be
...
...
@@ -31,6 +31,7 @@ label { margin-top:0.25em }
<select
type=
"number"
name=
"encryption"
class=
"form-control"
value=
"{{encryption}}"
>
<option
class=
"form-control"
name=
"hello"
{%
if
not
encryption =
=
"
SSL
"
%}
selected=
True{%
endif
%}
>
{%trans%}None{%endtrans%}
</option>
<option
class=
"form-control"
name=
"SSL"
{%
if
encryption =
=
"
SSL
"
%}
selected=
True{%
endif
%}
>
SSL
</option>
<option
class=
"form-control"
name=
"STARTTLS"
{%
if
encryption =
=
"
STARTTLS
"
%}
selected=
True{%
endif
%}
>
STARTTLS (may work)
</option>
</select>
<label>
{%trans%}User{%endtrans%}
</label>
...
...
views.py
View file @
51dee7be
...
...
@@ -26,7 +26,7 @@ from flask_babel import gettext, refresh
from
GNGforms.persistence
import
*
from
GNGforms.session
import
*
from
GNGforms.utils
import
*
from
GNGforms.email
import
*
import
GNGforms.email
as
smtp
from
form_templates
import
formTemplates
import
pprint
...
...
@@ -129,7 +129,7 @@ def view_form(slug):
emails
.
append
(
user
.
email
)
if
emails
:
def
sendExpiredFormNotification
():
smtp
S
endExpiredFormNotification
(
emails
,
queriedForm
)
smtp
.
s
endExpiredFormNotification
(
emails
,
queriedForm
)
thread
=
Thread
(
target
=
sendExpiredFormNotification
())
thread
.
start
()
queriedForm
.
save
()
...
...
@@ -146,7 +146,7 @@ def view_form(slug):
for
field
in
queriedForm
.
fieldIndex
:
if
field
[
'name'
]
in
entry
:
data
.
append
(
(
stripHTMLTagsForLabel
(
field
[
'label'
]),
entry
[
field
[
'name'
]])
)
smtp
S
endNewFormEntryNotification
(
emails
,
data
,
queriedForm
.
slug
)
smtp
.
s
endNewFormEntryNotification
(
emails
,
data
,
queriedForm
.
slug
)
thread
=
Thread
(
target
=
sendEntryNotification
())
thread
.
start
()
return
render_template
(
'thankyou.html'
,
form
=
queriedForm
)
...
...
@@ -536,7 +536,7 @@ def save_form(_id=None):
newForm
.
addLog
(
gettext
(
"Form created"
))
flash
(
gettext
(
"Saved form OK"
),
'success'
)
# notify Admins
smtp
S
endNewFormNotification
(
User
().
getNotifyNewFormEmails
(),
newForm
)
smtp
.
s
endNewFormNotification
(
User
().
getNotifyNewFormEmails
(),
newForm
)
return
redirect
(
make_url_for
(
'inspect_form'
,
_id
=
newForm
.
_id
))
clearSessionFormData
()
...
...
@@ -811,7 +811,7 @@ def change_email():
if
'email'
in
request
.
form
and
isValidEmail
(
request
.
form
[
'email'
]):
g
.
current_user
.
setToken
(
email
=
request
.
form
[
'email'
])
smtp
S
endConfirmEmail
(
g
.
current_user
,
request
.
form
[
'email'
])
smtp
.
s
endConfirmEmail
(
g
.
current_user
,
request
.
form
[
'email'
])
flash
(
gettext
(
"We've sent an email to %s"
)
%
request
.
form
[
'email'
],
'info'
)
return
redirect
(
make_url_for
(
'user_settings'
,
username
=
g
.
current_user
.
username
))
...
...
@@ -822,7 +822,7 @@ def change_email():
@
login_required
def
send_validation_email
():
g
.
current_user
.
setToken
(
email
=
g
.
current_user
.
email
)
smtp
S
endConfirmEmail
(
g
.
current_user
,
g
.
current_user
.
email
)
smtp
.
s
endConfirmEmail
(
g
.
current_user
,
g
.
current_user
.
email
)
flash
(
gettext
(
"We've sent an email to %s"
)
%
g
.
current_user
.
email
,
'info'
)
return
redirect
(
make_url_for
(
'user_settings'
,
username
=
g
.
current_user
.
username
))
...
...
@@ -902,7 +902,7 @@ def new_user(token=None):
if
invite
:
invite
.
delete
()
thread
=
Thread
(
target
=
smtp
S
endNewUserNotification
(
User
().
getNotifyNewUserEmails
(),
user
.
username
))
thread
=
Thread
(
target
=
smtp
.
s
endNewUserNotification
(
User
().
getNotifyNewUserEmails
(),
user
.
username
))
thread
.
start
()
if
validatedEmail
==
True
:
...
...
@@ -912,7 +912,7 @@ def new_user(token=None):
return
redirect
(
make_url_for
(
'my_forms'
))
else
:
user
.
setToken
()
smtp
S
endConfirmEmail
(
user
)
smtp
.
s
endConfirmEmail
(
user
)
return
render_template
(
'new-user.html'
,
site
=
g
.
site
,
created
=
True
)
session
[
"user_id"
]
=
None
...
...
@@ -960,7 +960,7 @@ def recover_password(token=None):
user
=
User
(
email
=
request
.
form
[
'email'
],
blocked
=
False
)
if
user
:
user
.
setToken
()
smtp
S
endRecoverPassword
(
user
)
smtp
.
s
endRecoverPassword
(
user
)
flash
(
gettext
(
"We may have sent you an email"
),
'info'
)
if
not
user
and
request
.
form
[
'email'
]
in
app
.
config
[
'ROOT_USERS'
]:
...
...
@@ -1096,7 +1096,7 @@ def smtp_config():
@
admin_required
def
test_smtp
(
email
):
if
isValidEmail
(
email
):
if
smtp
S
endTestEmail
(
email
):
if
smtp
.
s
endTestEmail
(
email
):
flash
(
gettext
(
"SMTP config works!"
),
'success'
)
else
:
flash
(
"Email not valid"
,
'warning'
)
...
...
@@ -1258,7 +1258,7 @@ def new_invite():
else
:
message
=
request
.
form
[
'message'
]
invite
=
Invite
().
create
(
hostname
,
request
.
form
[
'email'
],
message
,
admin
)
smtp
S
endInvite
(
invite
)
smtp
.
s
endInvite
(
invite
)
flash
(
gettext
(
"We've sent an invitation to %s"
)
%
invite
.
data
[
'email'
],
'success'
)
return
redirect
(
make_url_for
(
'user_settings'
,
username
=
g
.
current_user
.
username
))
sites
=
[]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment