-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : add account creation, change password, and email unsuscribptio…
…n email
- Loading branch information
Showing
7 changed files
with
94 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/python3 | ||
""" Create for account confirmation and changing password """ | ||
from models.user import User | ||
from models import storage | ||
from message.views import notification, mail | ||
from flask import jsonify, abort, request | ||
from flask_mail import Message | ||
|
||
|
||
|
||
@notification.route('/register', methods=['POST']) | ||
def create_accout(): | ||
"""Mail for creation of a new account""" | ||
if not request.get_json(): | ||
abort(400, description="Not a JSON") | ||
if 'first_name' not in request.get_json(): | ||
abort(400, description='No first_name') | ||
if 'email' not in request.get_json(): | ||
abort(400, description='No email') | ||
if 'last_name' not in request.get_json(): | ||
abort(400, description='No last_name') | ||
data = request.get_json() | ||
name = data.get('first_name') | ||
email = data.get('email') | ||
l_name = data.get('last_name') | ||
msg = Message('Time Master', sender='[email protected]', recipients=[email]) | ||
msg.body = '''Hello {name} {l_name},\nYou have take a new step in the mangement of your \ | ||
life. I cant't wait to see you flourish'''.format(name, l_name) | ||
try: | ||
mail.send(msg) | ||
return jsonify({'status': 'sent', 'description': 'Email sent'}), 201 | ||
except: | ||
pass | ||
return jsonify({'status': 'error', 'description': 'Email not sent'}), 200 | ||
|
||
@notification.route('/password', methods=['POST']) | ||
def change_password(): | ||
"""Mail for changing of passsword""" | ||
if not request.get_json(): | ||
abort(400, description="Not a JSON") | ||
if 'first_name' not in request.get_json(): | ||
abort(400, description='No first_name') | ||
if 'email' not in request.get_json(): | ||
abort(400, description='No email') | ||
if 'password' not in request.get_json(): | ||
abort(400, description='No password') | ||
if 'user_id' not in request.get_json(): | ||
abort(400, description='No user_id') | ||
data = request.get_json() | ||
user_id = data.get('user_id') | ||
user = storage.get(User, user_id) | ||
if user is None: | ||
abort(400, description='This user does not exist') | ||
password = data.get('password') | ||
user.password = password | ||
user.save() | ||
name = data.get('first_name') | ||
email = data.get('email') | ||
msg = Message('Time Master', sender='[email protected]', recipients=[email]) | ||
msg.body = "Hello {},\nThis is to inform you that your password has been changed sucessfully\ | ||
if you are not the one contact the admin email [email protected]".format(name) | ||
try: | ||
mail.send(msg) | ||
return jsonify({'status': 'sent', 'user_id': user_id, 'description': 'Email sent'}), 201 | ||
except: | ||
pass | ||
return jsonify({'status': 'error', 'description': 'Email not sent'}), 200 | ||
|
||
@notification.route('/unsub', methods=['POST']) | ||
def change_email_subscription(): | ||
"""Mail for changing subscription to false""" | ||
if not request.get_json(): | ||
abort(400, description="Not a JSON") | ||
if 'user_id' not in request.get_json(): | ||
abort(400, description='No user_id') | ||
data = request.get_json() | ||
user_id = data.get('user_id') | ||
user = storage.get(User, user_id) | ||
if user is None: | ||
abort(400, description='This user does not exist') | ||
user.is_suscribe = False | ||
user.save() | ||
return jsonify({'status': 'success'}), 201 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
#!/usr/bin/python3 | ||
""" Index """ | ||
from models.project import Project | ||
from models.task import Task | ||
from models.user import User | ||
from models import storage | ||
""" Index: Projet and Task creatio mail""" | ||
from message.views import notification,mail | ||
from flask import jsonify, abort, request, current_app | ||
from flask_mail import Message | ||
|
@@ -26,14 +22,14 @@ def create_project(): | |
email = data.get('email') | ||
expiry = data.get('expiry_date') | ||
msg = Message('Time Master', sender='[email protected]', recipients=[email]) | ||
msg.body = '''Hello Great Time Master,\n You have created a new project with the name {}. | ||
The project will expire {}'''.format(name, expiry) | ||
msg.body = '''Hello Great Time Master,\n You have created a new project \ | ||
with the name {}.The project will expire {}'''.format(name, expiry) | ||
try: | ||
mail.send(msg) | ||
return jsonify({'status': 'sent'}), 201 | ||
return jsonify({'status': 'sent', 'description': 'Email sent'}), 201 | ||
except: | ||
pass | ||
return jsonify({'status': 'error'}), 200 | ||
return jsonify({'status': 'error', 'description': 'Email not sent'}), 200 | ||
|
||
@notification.route('/task', methods=['POST']) | ||
def create_task(): | ||
|
@@ -54,11 +50,11 @@ def create_task(): | |
project = data.get('project_name') | ||
expiry = data.get('expiry_date') | ||
msg = Message('Time Master', sender='[email protected]', recipients=[email]) | ||
msg.body = '''Hello Great Time Master,\n You have created a new task {} under the project {}. | ||
The project will expire {}'''.format(name, project, expiry) | ||
msg.body = "Hello Great Time Master,\n You have created a new task {}\ | ||
under the project {}.The project will expire {}".format(name, project, expiry) | ||
try: | ||
mail.send(msg) | ||
return jsonify({'status': 'sent'}), 201 | ||
return jsonify({'status': 'sent', 'description': 'Email sent'}), 201 | ||
except: | ||
pass | ||
return jsonify({'status': 'error'}), 200 | ||
return jsonify({'status': 'error', 'description': 'Email not sent'}), 200 |