如果您使用 AWS Cognito 进行用户身份验证和管理,并且在电子邮件确认后用户未自动跳转到您的网站,您可以尝试以下解决方法:
import boto3
client = boto3.client('cognito-idp', region_name='YOUR_REGION')
response = client.describe_user_pool(UserPoolId='YOUR_USER_POOL_ID')
email_verification = response['UserPool']['Policies']['VerificationEmailSubject']
if email_verification == 'CONFIRM_WITH_LINK':
print('Email verification is enabled')
else:
print('Email verification is not enabled')
from urllib.parse import urlparse, parse_qs
# Example URL: http://yourwebsite.com/confirm?code=CONFIRMATION_CODE
url = "http://yourwebsite.com/confirm?code=CONFIRMATION_CODE"
parsed_url = urlparse(url)
confirm_code = parse_qs(parsed_url.query)['code'][0]
client = boto3.client('cognito-idp', region_name='YOUR_REGION')
response = client.confirm_sign_up(
ClientId='YOUR_APP_CLIENT_ID',
Username='USER_EMAIL',
ConfirmationCode=confirm_code
)
print('User confirmed successfully')
from flask import Flask, redirect, url_for
app = Flask(__name__)
@app.route('/confirm', methods=['GET'])
def confirm():
# Handle user confirmation logic here
# ...
# Redirect to a specific page after confirmation
return redirect(url_for('home'))
@app.route('/home', methods=['GET'])
def home():
return 'Welcome to your website!'
if __name__ == '__main__':
app.run()
请根据您的具体情况调整上述示例代码,并确保根据您的应用程序架构和要求进行适当的修改。