import datetime from flask import Flask, jsonify from flask_cors import CORS import resend from flask import request from supabase import create_client, Client app = Flask(__name__) CORS(app, resources={ r"/*": { "origins": ["*"], "methods": ["GET", "POST", "OPTIONS"], "allow_headers": ["Content-Type"] } }) SUPABASE_URL = "https://supabase-core.dev3vds1.link/" SUPABASE_KEY = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBhYmFzZSIsImlhdCI6MTc0NTk0MzYwMCwiZXhwIjo0OTAxNjE3MjAwLCJyb2xlIjoiYW5vbiJ9.28hFArcAFQ3mYTYL2n7nno4nHu5ZszkOO0dkAURR6Yg" supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY) resend.api_key = "re_XvLrRZMH_3mumWA531UugMk1X7A67fhH7" @app.route('/send_email', methods=['POST']) def send_email(): try: data = request.get_json() email = data.get('email', 'with.reihan@gmail.com') if not email: return jsonify({'status': 'error', 'message': 'Email is required'}), 400 # Check if the email is valid if not isinstance(email, str) or '@' not in email: return jsonify({'status': 'error', 'message': 'Invalid email format'}), 400 username = email.split('@')[0] date = str(datetime.datetime.now().date()) product = data.get('product', 'NVIDIA-686') price_hour = data.get('price_hour', '2.00') price = data.get('price', '147.00') html = f""" VertexGPU Invoice
VertexGPU
Date Issued: {date} Client ID: VX-CLIENT-686
User: {username}
Description Amount
{product}
1 Month ${price_hour}/hour
${price}
Priority Support Package
1 Month Free
$00.00
Subtotal: ${price}
Network Fee: $0.00
Total Due: ${price}

GPU Status Update

Your GPU instance is being initialized and will be ready for access within the next 2 hours. Once configuration is complete, we'll send your authentication credentials to your registered email address.

For any assistance, our support team is available 24/7. Thank you for choosing our service.

""" # Send email using Resend params: resend.Emails.SendParams = { "from": "Vertex (no-reply) ", "to": [email], "subject": "Thanks for purchasing our product!", "html": html, } resend.Emails.send(params) # Fetch user details from the database cred = supabase.table('vertexgpu-cred').select('username, password').eq('taken', False).order('id').execute() if cred.data: usernamedb = cred.data[0]['username'] password = cred.data[0]['password'] # Update the credential as taken supabase.table('vertexgpu-cred').update({'taken': True}).eq('username', usernamedb).execute() else: return jsonify({'status': 'error', 'message': 'No available credentials'}), 404 htmltwo = f""" VertexGPU Invoice
VertexGPU
User: {username} Client ID: VX-CLIENT-686
Server URL: https://gpu.vertexgpu.com
Username: {usernamedb}
Password: {password}

Quick start

  1. Connect to your GPU instance using the provided credentials.
  2. Go to Settings -> Connections (pop-up menu at the top right).
  3. Change your password.
  4. Go back to Home and run your GPU instance!

Your GPU instance is ready to use. You can access it via your browser.

Sincerely,

The VertexGPU Team

For any assistance, our support team is available 24/7. Thank you for choosing our service.

""" params: resend.Emails.SendParams = { "from": "Vertex Console (no-reply) ", "to": [email], "subject": "Your new GPU instance is ready!!", "html": htmltwo, } resend.Emails.send(params) return jsonify({'status': 'success', 'message': 'email sent'}) except: return jsonify({'status': 'error', 'message': 'Failed to send email'}), 500 @app.route('/health') def health(): return jsonify({'status': 'success', 'message': 'ok'}) if __name__ == '__main__': app.run(host='0.0.0.0', port=5000)