def post():
     try:
         email = request.get_json()["data"]["email"]
         otp, expire_time = generate_otp()
         mail_otp(email, str(otp), "User")
         ValidateCode.insert_code(email, otp, expire_time)
         return resp.http_201(data="OTP is sent to register email")
     except Exception as ex:
         logger.exception(ex)
         return resp.http_500()
 def post():
     try:
         email = request.get_json()['data']['email']
         user = User.user_exists(email)["data"]
         if user and user[0][0]:
             code = hashlib.md5(str.encode(email)).hexdigest()
             salt1 = "c2h56a7n3d25a1n9"
             salt2 = "c94h6a78i42n91a73n58i"
             final_code = salt1 + code + salt2
             ResetHash.insert_hash(email, final_code)
             url = "http://127.0.0.1:5000/forgot-password/" + final_code
             mail_otp(email, url, user[0][1])
             return resp.http_200(data="Mail sent to the user")
         else:
             return resp.http_404(data="User not found")
     except Exception as ex:
         logger.exception(ex)
         return resp.http_500()
Example #3
0
 def post():
     data = ResetPassword.parser.parse_args()
     code = generat_otp.generate(data['email'])
     username = UserModel.find_by_email(data['email']).username
     mail_otp(data['email'], str(code), username)
     validate_value = ValidateUser.find_by_email(data['email'])
     validate_value.code = code
     validate_value.expiretime = current_time.now() + datetime.timedelta(
         minutes=15)
     validate_value.save_to_db()
     return {
         "status": {
             "code": 201,
             "value": "201 created"
         },
         "data": {
             "message": "OTP is sent to register email"
         }
     }
 def post():
     data = request.get_json()['data']
     past_user = User.user_exists(data['email'])["data"]
     logger.info(past_user)
     if past_user and past_user[0][0] and past_user[0][1]:
         return resp.http_409(data="A user with this email already exists")
     try:
         hash_password = generate_password_hash(data['password'],
                                                method='sha256')
         out = User.create_user(data['username'], hash_password,
                                data['email'], str(uuid.uuid4()))
         logger.info(out)
         otp, expire_time = generate_otp()
         """send mail to user for otp"""
         mail_otp(data['email'], str(otp), data['username'])
         logger.info(f"OTP: {otp}, Expire Time: {expire_time}")
         ValidateCode.insert_code(data['email'], otp, expire_time)
         return resp.http_201(data="User created successfully.")
     except Exception as ex:
         logger.exception(ex)
         return resp.http_500()
Example #5
0
    def post():
        data = UserRegister.parser.parse_args()
        past_user = UserModel.find_by_email(data['email'])
        if past_user:
            if past_user.isactive:
                return {
                    "status": {
                        "code": 409,
                        "value": "409 conflict"
                    },
                    "data": {
                        "message": "A user with this email already exists"
                    }
                }
            else:
                past_user.email = data['email']
                past_user.username = data['username']
                past_user.password = data['password']
                past_user.save_to_db()
                code = generat_otp.generate(data['email'])
                valid_passcode = ValidateUser.find_by_email(data['email'])
                valid_passcode.code = code
                valid_passcode.save_to_db()
                mail_otp(data['email'], str(code), data['username'])
                return {
                    "status": {
                        "code": 201,
                        "value": "201 created"
                    },
                    "data": {
                        "message": "User created successfully."
                    }
                }

        try:
            hash_password = generate_password_hash(data['password'],
                                                   method='sha256')
            user = UserModel(data['username'], hash_password, data['email'],
                             str(uuid.uuid4()), False, False)
            user.save_to_db()
            code = generat_otp.generate(data['email'])
            """send mail to user for otp"""
            mail_otp(data['email'], str(code), data['username'])
            return {
                "status": {
                    "code": 201,
                    "value": "201 created"
                },
                "data": {
                    "message": "User created successfully."
                }
            }
        except Exception as e:
            return {
                "status": {
                    "code": 500,
                    "value": f"500 server error, {e}"
                },
                "data": {
                    "message": "can't able to create user, please try again"
                }
            }