<filename>forgot_password.py<gh_stars>1-10
from .. import resource as res
from .. import app
from .. import mail
from .. import token_required


# my code


@app.route("user/forgot-password", methods=['POST'])
@res.cross_origin()
def forgot_password():
    try:
        data = res.request.get_json()
        user_email = res.config.users_account.find_one({'email':data['email']})
        email = data['email']
        password_pin = res.randint(100000,999999)
        print("Please check your email for random generated pin for verification")
        res.session['otp'] = password_pin
        if user_email is not None:
            mail.sendmail.forgotPassword(email,password_pin)
    except Exception as e:
        print("Error has occured!")
        print(e)
        return res.jsonify({'status': 502, 'message': "Something went wrong", 'error': e})





# json keys name : {email:string}
# admin forgot password

# @app.route("/user/forgot-password", methods=['POST'])
# @res.cross_origin()
# def user_forgot_password():
#     try:
#         data = res.request.get_json()
#
#         email_existed = res.config.users_account.find_one({'email':data['email'].lower()})
#         print(email_existed)
#         user_id= str(email_existed['_id'])
#         name = str(email_existed['name'])
#         email = data['email']
#         random_pin_generate = res.randint(100000, 999999)
#         print("random: ", random_pin_generate)
#         res.session['otp'] = random_pin_generate
#         # send otp on email
#         if email_existed:
#             mail.sendmailtest.forgotPasswordtest(email, name, random_pin_generate).forgot_Password_mail_test()
#             # temp_id=41
#             # mail.sendmail.forgotPassword(email, name,temp_id, random_pin_generate).forgot_Password_mail()
#             return res.jsonify({'status': 200,'message': "one time password send on email id", 'data':{'_id':str(email_existed['_id']),'one_time_password':<PASSWORD>},'error':False})
#         else:
#             return res.jsonify({'status': 200,'message': "one time password send on email id", 'data':{'one_time_password':<PASSWORD>},'error':False})
#     except Exception as e:
#         print('Error occured in forgot Password api')
#         print(e)
#         return res.jsonify({'status': 502, 'message': "Something went wrong", 'error': e})
                 

<filename>forgot_password.py<gh_stars>1-10
from .. import resource as res
from .. import app
from .. import mail
from .. import token_required


# my code


@app.route("user/forgot-password", methods=['POST'])
@res.cross_origin()
def forgot_password():
    try:
        data = res.request.get_json()
        user_email = res.config.users_account.find_one({'email':data['email']})
        email = data['email']
        password_pin = res.randint(100000,999999)
        print("Please check your email for random generated pin for verification")
        res.session['otp'] = password_pin
        if user_email is not None:
            mail.sendmail.forgotPassword(email,password_pin)
    except Exception as e:
        print("Error has occured!")
        print(e)
        return res.jsonify({'status': 502, 'message': "Something went wrong", 'error': e})





# json keys name : {email:string}
# admin forgot password

# @app.route("/user/forgot-password", methods=['POST'])
# @res.cross_origin()
# def user_forgot_password():
#     try:
#         data = res.request.get_json()
#
#         email_existed = res.config.users_account.find_one({'email':data['email'].lower()})
#         print(email_existed)
#         user_id= str(email_existed['_id'])
#         name = str(email_existed['name'])
#         email = data['email']
#         random_pin_generate = res.randint(100000, 999999)
#         print("random: ", random_pin_generate)
#         res.session['otp'] = random_pin_generate
#         # send otp on email
#         if email_existed:
#             mail.sendmailtest.forgotPasswordtest(email, name, random_pin_generate).forgot_Password_mail_test()
#             # temp_id=41
#             # mail.sendmail.forgotPassword(email, name,temp_id, random_pin_generate).forgot_Password_mail()
#             return res.jsonify({'status': 200,'message': "one time password send on email id", 'data':{'_id':str(email_existed['_id']),'one_time_password':<PASSWORD>},'error':False})
#         else:
#             return res.jsonify({'status': 200,'message': "one time password send on email id", 'data':{'one_time_password':<PASSWORD>},'error':False})
#     except Exception as e:
#         print('Error occured in forgot Password api')
#         print(e)
#         return res.jsonify({'status': 502, 'message': "Something went wrong", 'error': e})
                 

# my code # json keys name : {email:string} # admin forgot password # @app.route("/user/forgot-password", methods=['POST']) # @res.cross_origin() # def user_forgot_password(): #     try: #         data = res.request.get_json() # #         email_existed = res.config.users_account.find_one({'email':data['email'].lower()}) #         print(email_existed) #         user_id= str(email_existed['_id']) #         name = str(email_existed['name']) #         email = data['email'] #         random_pin_generate = res.randint(100000, 999999) #         print("random: ", random_pin_generate) #         res.session['otp'] = random_pin_generate #         # send otp on email #         if email_existed: #             mail.sendmailtest.forgotPasswordtest(email, name, random_pin_generate).forgot_Password_mail_test() #             # temp_id=41 #             # mail.sendmail.forgotPassword(email, name,temp_id, random_pin_generate).forgot_Password_mail() #             return res.jsonify({'status': 200,'message': "one time password send on email id", 'data':{'_id':str(email_existed['_id']),'one_time_password':<PASSWORD>},'error':False}) #         else: #             return res.jsonify({'status': 200,'message': "one time password send on email id", 'data':{'one_time_password':<PASSWORD>},'error':False}) #     except Exception as e: #         print('Error occured in forgot Password api') #         print(e) #         return res.jsonify({'status': 502, 'message': "Something went wrong", 'error': e})