fix: 个人中心邮箱显示逻辑优化
- 显示用户注册邮箱作为通知邮箱 - 支持更换通知邮箱(一次只能通知一个) - 添加更换邮箱模态框 - API接口检查邮箱是否已被其他用户使用
This commit is contained in:
10
app.py
10
app.py
@@ -861,6 +861,16 @@ def update_settings():
|
||||
user.phone = phone
|
||||
user.phone_verified = False
|
||||
|
||||
# 通知邮箱(更换后邮件通知发送到此邮箱)
|
||||
if 'email' in data:
|
||||
email = data.get('email', '')
|
||||
if email and '@' in email:
|
||||
# 检查邮箱是否已被其他用户使用
|
||||
existing = User.query.filter(User.email == email, User.id != user.id).first()
|
||||
if existing:
|
||||
return jsonify({'error': '该邮箱已被其他用户使用'}), 400
|
||||
user.email = email
|
||||
|
||||
# 通知设置
|
||||
if 'notify_on_complete' in data:
|
||||
user.notify_on_complete = data.get('notify_on_complete', True)
|
||||
|
||||
@@ -186,20 +186,32 @@
|
||||
<!-- 邮件通知设置 -->
|
||||
<div class="col-md-6 mb-3">
|
||||
<div class="border rounded p-3">
|
||||
<h6 class="mb-3">📧 邮件通知</h6>
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="checkbox" id="notifyComplete"
|
||||
{% if user.notify_on_complete %}checked{% endif %}
|
||||
onchange="updateNotifySettings()">
|
||||
<label class="form-check-label">翻译完成通知(含附件)</label>
|
||||
<h6 class="mb-3">📧 通知邮箱</h6>
|
||||
<div id="emailStatus">
|
||||
{% if user.email %}
|
||||
<p class="mb-2">当前通知邮箱:<strong>{{ user.email }}</strong></p>
|
||||
<button class="btn btn-outline-secondary btn-sm mb-3" onclick="showEmailModal()">更换通知邮箱</button>
|
||||
{% else %}
|
||||
<p class="text-muted">未设置通知邮箱</p>
|
||||
<button class="btn btn-primary btn-sm" onclick="showEmailModal()">绑定邮箱</button>
|
||||
{% endif %}
|
||||
|
||||
<hr class="my-2">
|
||||
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="checkbox" id="notifyComplete"
|
||||
{% if user.notify_on_complete %}checked{% endif %}
|
||||
onchange="updateNotifySettings()">
|
||||
<label class="form-check-label">翻译完成通知(含附件)</label>
|
||||
</div>
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="checkbox" id="notifyExpire"
|
||||
{% if user.notify_on_expire %}checked{% endif %}
|
||||
onchange="updateNotifySettings()">
|
||||
<label class="form-check-label">会员到期提醒</label>
|
||||
</div>
|
||||
<small class="text-muted">通知将发送至上述邮箱</small>
|
||||
</div>
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="checkbox" id="notifyExpire"
|
||||
{% if user.notify_on_expire %}checked{% endif %}
|
||||
onchange="updateNotifySettings()">
|
||||
<label class="form-check-label">会员到期提醒</label>
|
||||
</div>
|
||||
<small class="text-muted">通知发送至:{{ user.email }}</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -334,6 +346,33 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 更换邮箱模态框 -->
|
||||
<div class="modal fade" id="emailModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">更换通知邮箱</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="emailForm">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">新邮箱地址</label>
|
||||
<input type="email" class="form-control" id="newEmail" placeholder="example@email.com" required>
|
||||
</div>
|
||||
<div class="alert alert-info">
|
||||
<small>💡 更换后,通知邮件将发送至新邮箱</small>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
|
||||
<button type="button" class="btn btn-primary" onclick="submitEmail()">确认更换</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
// 加载账户流水
|
||||
@@ -527,6 +566,35 @@
|
||||
alert('手机号格式不正确');
|
||||
}
|
||||
}
|
||||
|
||||
// 更换邮箱
|
||||
function showEmailModal() {
|
||||
new bootstrap.Modal(document.getElementById('emailModal')).show();
|
||||
}
|
||||
|
||||
function submitEmail() {
|
||||
const newEmail = document.getElementById('newEmail').value;
|
||||
|
||||
if (!newEmail || !newEmail.includes('@')) {
|
||||
alert('请输入有效的邮箱地址');
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('/api/profile/settings', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email: newEmail })
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
alert('通知邮箱已更新为:' + newEmail);
|
||||
location.reload();
|
||||
} else {
|
||||
alert('更新失败:' + data.error);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user