Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Salamander - API
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Herman Andersen Dyrkorn
Salamander - API
Commits
b8e13184
Commit
b8e13184
authored
4 years ago
by
eirikmda
Browse files
Options
Downloads
Patches
Plain Diff
trying to send email
parent
105196e4
Branches
36-email-verification
No related tags found
1 merge request
!39
Draft: Resolve "Email verification"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/__init__.py
+2
-1
2 additions, 1 deletion
api/__init__.py
api/endpoints/emailconfirmation.py
+31
-0
31 additions, 0 deletions
api/endpoints/emailconfirmation.py
api/endpoints/user.py
+49
-2
49 additions, 2 deletions
api/endpoints/user.py
with
82 additions
and
3 deletions
api/__init__.py
+
2
−
1
View file @
b8e13184
from
flask
import
Flask
from
flask_mail
import
Mail
from
flask_restful
import
Api
from
flask_bcrypt
import
Bcrypt
from
flask_jwt_extended
import
JWTManager
...
...
@@ -6,12 +7,12 @@ from flask_sqlalchemy import SQLAlchemy
from
flask_limiter
import
Limiter
from
flask_limiter.util
import
get_remote_address
app
=
Flask
(
__name__
)
app
.
config
[
'
SECRET_KEY
'
]
=
'
randomchangethisshit
'
app
.
config
[
'
SQLALCHEMY_DATABASE_URI
'
]
=
'
sqlite:///database/database.db
'
app
.
config
[
'
JWT_AUTH_USERNAME_KEY
'
]
=
'
email
'
app
.
config
[
'
JWT_ACCESS_TOKEN_EXPIRES
'
]
=
5
*
3600
mail
=
Mail
(
app
)
db
=
SQLAlchemy
(
app
)
jwt
=
JWTManager
(
app
)
bcrypt
=
Bcrypt
(
app
)
...
...
This diff is collapsed.
Click to expand it.
api/endpoints/emailconfirmation.py
+
31
−
0
View file @
b8e13184
# from flask import redirect, render_template, url_for
# from api import db, limiter
# from itsdangerous import URLSafeTimedSerializer
#
# email = 'haha'
#
# ts = URLSafeTimedSerializer(app.config["SECRET_KEY"])
#
# @app.route('/accounts/create', methods=["GET", "POST"])
# def create_account():
#
# # Now we'll send the email confirmation link
# subject = "Confirm your email for salamander app."
#
# token = ts.dumps(email, salt='email-confirm-key')
#
# confirm_url = url_for(
# 'confirm_email',
# token=token,
# _external=True)
#
# html = render_template(
# 'email/activate.html',
# confirm_url=confirm_url)
#
# # We'll assume that send_email has been defined in myapp/util.py
# send_email(user.email, subject, html)
#
# return redirect(url_for("index"))
#
# return render_template("accounts/create.html", form=form)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
api/endpoints/user.py
+
49
−
2
View file @
b8e13184
...
...
@@ -6,8 +6,13 @@ import re
from
flask_jwt_extended
import
get_jwt_identity
,
jwt_required
from
api.forms.userforms
import
RegistrationForm
,
DeleteUserForm
from
validate_email
import
validate_email
from
itsdangerous
import
URLSafeTimedSerializer
from
api
import
app
,
mail
from
flask
import
redirect
,
render_template
,
url_for
from
flask_mail
import
Message
EMAIL_REGEX
=
"
^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$
"
ts
=
URLSafeTimedSerializer
(
app
.
config
[
"
SECRET_KEY
"
])
class
UserEndpoint
(
Resource
):
...
...
@@ -20,12 +25,48 @@ class UserEndpoint(Resource):
if
data
.
password
.
data
==
data
.
confirmPassword
.
data
:
user
=
db
.
session
.
query
(
User
).
filter_by
(
email
=
data
.
email
.
data
.
lower
()).
first
()
if
not
user
and
re
.
search
(
EMAIL_REGEX
,
data
.
email
.
data
.
lower
()):
valid
=
validate_email
(
data
.
email
.
data
.
lower
(),
verify
=
True
,
check_mx
=
True
)
if
valid
:
if
validate_email
(
data
.
email
.
data
.
lower
(),
verify
=
True
,
check_mx
=
True
):
password_hash
=
bcrypt
.
generate_password_hash
(
data
.
password
.
data
)
new_user
=
User
(
name
=
data
.
name
.
data
,
email
=
data
.
email
.
data
.
lower
(),
pwd
=
password_hash
)
db
.
session
.
add
(
new_user
)
db
.
session
.
commit
()
# Now we'll send the email confirmation link
subject
=
"
Confirm your email for salamander app.
"
# w c(..)o (
# \__(-) __)
# /\ (
# /(_)___)
# w /|
# | \
# m m
#
# .="=.
# _/.-.-.\_ _
# ( ( o o ) ) ))
# |/ " \| //
# \'---'/ //
# /`"""`\\ ((
# / /_,_\ \\ \\
# \_\\_'__/ \ ))
# /` /`~\ |//
# / / \ /
# ,--`,--'\/\ /
#
#
token
=
ts
.
dumps
(
data
.
email
.
data
.
lower
(),
salt
=
'
email-confirm-key
'
)
# confirm_url = url_for(
# 'confirm_email',
# token=token,
# _external=True)
#
# html = render_template(
# 'email/activate.html',
# confirm_url=confirm_url)
# We'll assume that send_email has been defined in myapp/util.py
send_email
(
data
.
email
.
data
.
lower
(),
"
hei
"
)
#, html)
return
jsonify
({
"
message
"
:
"
new user created
"
,
'
status
'
:
200
})
else
:
return
jsonify
({
"
message
"
:
"
email doesn
'
t exist
"
,
'
status
'
:
400
})
...
...
@@ -93,3 +134,9 @@ class UserEndpoint(Resource):
else
:
return
jsonify
({
"
message
"
:
"
this user does not exist
"
,
"
status
"
:
400
})
def
send_email
(
email
,
text
):
msg
=
Message
(
text
,
sender
=
"
salamanderteam@noreply.com
"
,
recipients
=
[
email
])
mail
.
send
(
msg
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment