def send_verify_email(): if request.method == 'GET': user_id = int(request.args['user_id']) form = EmailForm(user_id=user_id) user_name = User.get_name_by_id(user_id) return render_template('sign/send_verify_email.html', user_name=user_name, form=form) else: form = EmailForm(request.form) if form.validate(): # email t_addr = form.email.data # user info user_id = int(form.user_id.data) user_name = User.get_name_by_id(user_id) # add this email to user User.add_email(user_id, t_addr) # gene verify url verify_code = hashlib.sha1(user_name).hexdigest() verify_url = config.SITE_DOMAIN + "verify_email/douban/" + str( user_id) + "/" + verify_code # prepare email content msgText = '''<h3>点 <a href='%s'>这里</a>,激活你在西窗烛的帐号。</h3>''' % verify_url msg = MIMEText(msgText, 'html', 'utf-8') msg['From'] = "西窗烛 <" + config.SMTP_FROM + ">" msg['To'] = user_name + "<" + t_addr + ">" msg['Subject'] = "欢迎来到西窗烛!" # send email s = smtplib.SMTP(config.SMTP_SERVER, config.SMTP_PORT) s.login(config.SMTP_USER, config.SMTP_PASSWORD) s.sendmail(config.SMTP_FROM, t_addr, msg.as_string()) return redirect(url_for('verify_email_callback', state='send_succ')) else: user_id = int(form.user_id.data) user_name = User.get_name_by_id(user_id) return render_template('sign/send_verify_email.html', user_name=user_name, form=form)
def send_verify_email(): if request.method == 'GET': user_id = int(request.args['user_id']) form = EmailForm(user_id=user_id) user_name = User.get_name_by_id(user_id) return render_template('sign/send_verify_email.html', user_name=user_name, form=form) else: form = EmailForm(request.form) if form.validate(): # email t_addr = form.email.data # user info user_id = int(form.user_id.data) user_name = User.get_name_by_id(user_id) # add this email to user User.add_email(user_id, t_addr) # gene verify url verify_code = hashlib.sha1(user_name).hexdigest() verify_url = config.SITE_DOMAIN + "verify_email/douban/" + str(user_id) + "/" + verify_code # prepare email content msgText = '''<html> <h1>点击下面的链接,激活你在西窗烛的帐号:</h1> <a href='%s'>%s</a> </html>''' % (verify_url, verify_url) msg = MIMEText(msgText, 'html', 'utf-8') msg['From'] = "西窗烛 <" + config.SMTP_FROM + ">" msg['To'] = user_name + "<" + t_addr + ">" msg['Subject'] = "欢迎来到西窗烛!" # send email s = smtplib.SMTP(config.SMTP_SERVER, config.SMTP_PORT) s.login(config.SMTP_USER, config.SMTP_PASSWORD) s.sendmail(config.SMTP_FROM, t_addr, msg.as_string()) return redirect(url_for('verify_email_callback', state='send_succ')) else: user_id = int(form.user_id.data) user_name = User.get_name_by_id(user_id) return render_template('sign/send_verify_email.html', user_name=user_name, form=form)
def send_verify_email(): if request.method == 'GET': user_id = int(request.args['user_id']) user_name = User.get_name(user_id) return render_template('send_verify_email.html', user_id=user_id, user_name=user_name) elif request.method == 'POST': # email f_addr = "*****@*****.**" t_addr = request.form['email'] # user info user_id = int(request.form['user_id']) user_name = User.get_name(user_id) # add this email to user User.add_email(user_id, t_addr) # gene verify url verify_code = hashlib.sha1(user_name).hexdigest() verify_url = "http://*****:*****@qq.com', 'xiaowang2013qqzi') s.sendmail('*****@*****.**', t_addr, msg.as_string()) return redirect(url_for('verify_email_callback', state='send_succ'))