Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest email changes #30

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fd161c5
resistration page changes
Nupur582 Nov 8, 2021
601ab74
password reset link added correctly and user status changed to regist…
Nupur582 Nov 9, 2021
a6e8d87
login validation for when user is active done
Nupur582 Nov 10, 2021
127f863
userstatus validation with object ID
Nupur582 Nov 10, 2021
dbae0cb
confirmationcode being sent out to the user and the db schema structu…
Nupur582 Nov 12, 2021
0554f58
API to activate the user and set the status to active has been created
Nupur582 Nov 12, 2021
6be4270
Request email and confirm email for the users are done and in place.
Nupur582 Nov 12, 2021
40471bc
validations added if user is already active
Nupur582 Nov 12, 2021
a78a09e
modified the confirmation code send to the user and once active the c…
Nupur582 Nov 16, 2021
e0b4515
hide the variables
Nupur582 Nov 17, 2021
a31e02f
changes
Nupur582 Nov 17, 2021
9d48270
hiding changes
Nupur582 Nov 17, 2021
64aa34b
hiding files
Nupur582 Nov 17, 2021
95dcd0c
c
Nupur582 Nov 17, 2021
110b47a
c
Nupur582 Nov 17, 2021
a12c4d0
c
Nupur582 Nov 17, 2021
da4f18d
c
Nupur582 Nov 17, 2021
2d9782a
Merge branch 'latest_email_changes' of https://github.com/dxc-technol…
Nupur582 Nov 17, 2021
98a7940
c
Nupur582 Nov 17, 2021
6c3ef44
New Activate page and PW route
smaddinieni Nov 18, 2021
9cf8496
Merge pull request #29 from dxc-technology/activation_page
Nupur582 Nov 19, 2021
8bfca72
confirm user all changes done from Backend and the UI. ready to merge.
Nupur582 Nov 19, 2021
eb46b58
Update backend_variable.env
Nupur582 Nov 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Backend/activate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import re
from bson.objectid import ObjectId
from argon2 import PasswordHasher
from argon2.exceptions import HashingError, VerificationError, VerifyMismatchError, InvalidHash
import database
import login

VALID = r"valid"
INVALID = r"invalid"
EMAIL_NOT_EXIST = r'email does not exist'

def activateuser(email , confirmationCode):
if email == "":
return "email is empty"
if validate_email_address(email) == INVALID:
return "email is not correct"
user_doc = database.get_user_details(email)
if len(user_doc) > 0:
if(user_doc['userStatus'] == ObjectId('5f776e5d6289f17659874f27')):
return "User is already active. Please proceed to login."
else:
if(user_doc['confirmation_code'] == confirmationCode):
database.modify_user_status(email)
return "You have now been activated. Please go ahead and login"
else:
return "Confirmation code do not match. Please check your email."
return "user does not exist"


def validate_email_address(email_address):
regex = r'^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'
if re.search(regex, email_address) and email_address.strip() != "" and email_address is not None:
return VALID
return INVALID
15 changes: 15 additions & 0 deletions Backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pymongo import database
import login
import registration
import activate
import view_badge
import create_badge
import view_users
Expand Down Expand Up @@ -72,6 +73,20 @@ def register_user():
organization_name)


@app.route("/activate", methods=['POST'])
def activate_user():
req_body = request.get_json()
if req_body['email'] == "None":
email_id_list = ""
else:
email_id_list = req_body['email']
if req_body['confirmationCode'] == "None":
confirmationCode_list = ""
else:
confirmationCode_list = req_body['confirmationCode']
return activate.activateuser(email_id_list,confirmationCode_list)


@app.route("/updateuser", methods=['POST'])
def update_user_details():
req_body = request.get_json()
Expand Down
5 changes: 2 additions & 3 deletions Backend/backend_variable.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
DEBUG = True
MAIL_SERVER = 'smtp.office365.com'
MAIL_PORT = 587
MAIL_USERNAME = No-replyBadge@cscportal.onmicrosoft.com
MAIL_PASSWORD = P@noply@123
MAIL_USERNAME =
MAIL_PASSWORD =
MAIL_USE_TLS = True
MAIL_USE_SSL = True


# DATABASE VARIABLES
DB_NAME = Panoply
DB_CONNECTION_STRING = 'mongodb+srv://dbuser:admin123@panoplycluster0.ssmov.mongodb.net/Panoply?retryWrites=true&w=majority'

27 changes: 25 additions & 2 deletions Backend/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,21 @@ def update_user_password(email, hashed_password):


def add_new_user(email, password, user_type, created_time_utc, modified_time_utc, first_name, second_name, middle_name,
organization_name):
organization_name,confirmation_code):
user_collection = myDB["Users"]
user_type_doc = get_user_type(user_type)
user_status_doc = get_user_status("active")
user_status_doc = get_user_status("registered")
new_user = {"email": email, "password": password,
"userType": user_type_doc["_id"], "userStatus": user_status_doc["_id"], "created": created_time_utc,
"modified": modified_time_utc, "firstName": first_name, "secondName": second_name,
"middleName": middle_name, "organizationName": organization_name}
new_user_doc = user_collection.insert_one(new_user)
user_collection.update(
{"email": email},
{
"$set": {"confirmation_code": confirmation_code}
}, upsert=False
)
return str(new_user_doc.inserted_id)

def modify_existing_user(userid, first_name, second_name, middle_name, organization_name):
Expand Down Expand Up @@ -1321,3 +1327,20 @@ def get_badge_type_options():
json = dumps(badge_type_doc, indent=2)
return json


def modify_user_status(email):
user_collection = myDB["Users"]
user_collection.find_one_and_update(
{"email": email},
{
"$set": {"userStatus": ObjectId('5f776e5d6289f17659874f27') , "modified": datetime.now(timezone.utc)
}
}, upsert=True
)
user_collection.update(
{"email": email},
{
"$unset": {"confirmation_code": ""}
}, upsert=False
)
return "updated"
14 changes: 9 additions & 5 deletions Backend/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ def login(email, password):
return "email is not correct"
user_doc = database.get_user_details(email.lower())
if len(user_doc) > 0:
try:
if password_hash.verify(user_doc['password'], password):
return str(ObjectId(user_doc['userType']))
if (user_doc['userStatus'] == ObjectId('5f776e5d6289f17659874f27')):
try:
if password_hash.verify(user_doc['password'], password):
return str(ObjectId(user_doc['userType']))

except (InvalidHash, HashingError, VerificationError, VerifyMismatchError):
return "password is wrong"
else:
return "please confirm and activate your account"

except (InvalidHash, HashingError, VerificationError, VerifyMismatchError):
return "password is wrong"
return "user does not exist"


Expand Down
55 changes: 47 additions & 8 deletions Backend/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from dotenv import load_dotenv
from argon2 import PasswordHasher
from argon2.exceptions import HashingError, VerificationError, VerifyMismatchError, InvalidHash
from pymongo import message
import database
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import random
import array
import math
from bson.objectid import ObjectId

VALID = r"valid"
Expand Down Expand Up @@ -100,6 +102,34 @@ def generate_strong_password():
return password


def email_confirmation(email_address,body):
env_path = 'backend_variable.env'
load_dotenv(dotenv_path=env_path)
sender_email = "No-replyBadge@cscportal.onmicrosoft.com"
receiver_email = email_address

msg = MIMEMultipart()
msg['Subject'] = 'Industrial Badger - Confirm and activate email'
msg['From'] = sender_email
msg['To'] = receiver_email

message = """\
<p> Please click on the link below to activate your email </p>
<a href="https://industrialized-ai-starter.azurewebsites.net/Activate">Click here to activate your email</a>
"""
msg_text = MIMEText('<b>%s</b>' % (body+ message), 'html')
msg.attach(msg_text)

try:
with smtplib.SMTP('smtp.office365.com', 587) as smtpObj:
smtpObj.ehlo()
smtpObj.starttls()
smtpObj.login(os.getenv("MAIL_USERNAME"), os.getenv("MAIL_PASSWORD"))
smtpObj.sendmail(sender_email, receiver_email, msg.as_string())
except Exception as e:
print(e)


def register(email, password, user_type, first_name, second_name, middle_name, organization_name):
if validate_email_exist(email.lower()) == "email already exists":
return "user already exists"
Expand All @@ -117,13 +147,16 @@ def register(email, password, user_type, first_name, second_name, middle_name, o
new_user_type = user_type_validation(user_type)
if new_user_type == INVALID_USER_TYPE_MESSAGE:
return INVALID_USER_TYPE_MESSAGE

confirmation_code = generate_strong_password()
hashed_password = hash_password(password)

new_user_id = database.add_new_user(
email, hashed_password, new_user_type, created_time_utc, modified_time_utc, first_name, second_name,
middle_name, organization_name)
middle_name, organization_name, confirmation_code)
if len(new_user_id) > 0:
return "registered"
email_confirmation(email, "This is your activation code: " + confirmation_code)
return "registered"
return None


Expand Down Expand Up @@ -187,11 +220,13 @@ def email_content(email_address, body):
msg['Subject'] = 'Industrial Badger - Password Reset'
msg['From'] = sender_email
msg['To'] = receiver_email
msg_text = MIMEText('<b>%s</b>' % body, 'html')
text = 'Go ahead and reset the password using the given link: http://localhost:3000/passwordchange'
msg_text1 = MIMEText(text, "plain")

message = """\
<p> \n </p>
<a href="https://industrialized-ai-starter.azurewebsites.net/passwordchange">Click here to reset password</a>
"""
msg_text = MIMEText('<b>%s</b>' % (body + message), 'html')
msg.attach(msg_text)
msg.attach(msg_text1)

try:
with smtplib.SMTP('smtp.office365.com', 587) as smtpObj:
Expand All @@ -211,7 +246,11 @@ def password_reset_email(email):
user_doc = database.get_user_details(email)
if len(user_doc) > 0:
password = generate_strong_password()
email_content(email, "This is your new password: " + password)
email_content(email, "This is your new temporary password: " + password)
password_reset(email, password)
return "Email sent successfully"
return "user does not exist"




1 change: 1 addition & 0 deletions UI/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/.pnp
.pnp.js


# testing
/coverage

Expand Down
Loading