def send_active_email(self, username): token = made_uuid() self.redis_db.set('account:active:%s' % (username,), token) active_url = self.full_host + '/active?username={username}&token={token}'.format(username = username, token = token) send_email('*****@*****.**', subject = "请激活您被锁定的账号", html = "<a href='{url}' target='_blank'>{url}</a>".format(url = active_url))
def resend_confirmation(): token = current_user.generate_confirmation_token() send_email(current_user.email, 'Confirm Your Account', 'auth/email/confirm', user=current_user, token=token) flash('A new confirmation email has been sent to you by email.') return redirect(url_for('home.index'))
def send_active_email(self, username): token = made_uuid() self.redis_db.set('account:active:%s' % (username, ), token) active_url = self.full_host + '/active?username={username}&token={token}'.format( username=username, token=token) send_email('*****@*****.**', subject="请激活您被锁定的账号", html="<a href='{url}' target='_blank'>{url}</a>".format( url=active_url))
def signup(): form = EmailPasswordForm() form2 = UsernamePasswordForm() if request.method == 'POST': if form.validate_on_submit(): user = User(username=form.username.data, email=form.username.data, password=form.password.data) db.session.add(user) db.session.commit() uid = user.id defaultuser = User.query.filter_by(email='default').first_or_404() books = Book.query.filter_by(user_id=defaultuser.id).all() for b in books: bc = Book(b.title, b.synopsis, uid) db.session.add(bc) db.session.commit() for c in b.chapters: cc = Chapter(c.title, c.synopsis, uid, bc.id) db.session.add(cc) db.session.commit() for e in c.events: ec = Event(uid, e.title, e.description, '-1', '-1', cc.id, e.event_occurs_percent) db.session.add(ec) db.session.commit() # SEND CONFIRMATION EMAIL subject = "Account created at {}.".format("Timelines") # Here we use the URLSafeTimedSerializer we created in `util` at the # beginning of the chapter token = ts.dumps(user.email, salt='recover-key') recover_url = url_for('reset_with_token', token=token, _external=True) html = render_template('email/create_account.html') # Let's assume that send_email was defined in myapp/util.py send_email(user.email, subject, html) flash('Email sent to: {}'.format(user.email)) login_user(user, force=True) return redirect(url_for('index')) return render_template('signup.html', form=form, form2=form2)
def change_email_request(): form = ChangeEmailForm() if form.validate_on_submit(): if current_user.verify_password(form.password.data): new_email = form.email.data token = current_user.generate_email_change_token(new_email) send_email(new_email, 'Confirm your email address', 'auth/email/change_email', user=current_user, token=token) flash('An email with instructions to confirm your new email ' 'address has been sent to you.') return redirect(url_for('home.index')) else: flash('Invalid email or password.') return render_template("auth/change_email.html", form=form)
def password_reset_request(): if not current_user.is_anonymous(): return redirect(url_for('home.index')) form = PasswordResetRequestForm() if form.validate_on_submit(): user = User.from_email(email=form.email.data) if user: token = user.generate_reset_token() send_email(user.email, 'Reset Your Password', 'auth/email/reset_password', user=user, token=token, next=request.args.get('next')) flash('An email with instructions to reset your password has been ' 'sent to you.') return redirect(url_for('auth.login')) return render_template('auth/reset_password.html', form=form)
def floodlight_email(day, alerts): for email, table in alerts.items(): # build email template t = EmailTemplate(); # when floodlight alerts exist if table: subject = '%d Floodlight Alerts For %s' % (len(table), day) t.header(subject) t.paragraph('For the following floodlights, there are suspiciously low impressions. Please check their configurations.') t.table( [ { "name":"Date", "type":"STRING" }, { "name":"Floodlight", "type":"STRING" }, { "name":"Activity Id", "type":"STRING" }, { "name":"Activity", "type":"STRING" }, { "name":"Impressions", "type":"INTEGER" }, ], table ) # when everything is OK else: subject = 'All Floodlights Normal For %s' % day t.header(subject) t.paragraph('Impressions all look within statistically expected range.') # either way link to the configuration sheet t.button('Floodlight Monitoring Sheet', project.task['sheet']['url'], big=True) if project.verbose: print "FLOODLIGHT MONITOR EMAIL ALERTS", email, len(table) # send email template send_email( project.task['auth'], email, None, None, subject, t.get_text(), t.get_html() )
def create_account(): form = EmailPasswordForm() if form.validate_on_submit(): user = User(username=form.email.data, password=form.password.data, email=form.email.data) db.session.add(user) db.session.commit() uid = user.id defaultuser = User.query.filter_by(email='default').first_or_404() books = Book.query.filter_all(user_id=defaultuser.id).all() for b in books: bc = Book(b.title, b.synopsis, uid) db.session.add(bc) db.session.commit() for c in b.chapters: cc = Chapter(c.title, c.synopsis, uid, bc.id) db.session.add(cc) db.session.commit() for e in c.events: ec = Event(uid, e.title, e.description, '-1', '-1', cc.id, e.event_occurs_percent) db.session.add(ec) db.session.commit() # Now we'll send the email confirmation link subject = "Confirm your email" token = ts.dumps(self.email, salt='email-confirm-key') confirm_url = url_for('confirm_email', token=token, _external=True) html = render_template('email/activate.html', confirm_url=confirm_url) # We'll assume that send_email has been defined in myapp/util.py send_email(user.email, subject, html) return redirect(url_for("index")) return render_template("accounts/create.html", form=form)
def reset(): form = EmailForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first_or_404() subject = "Password reset requested" # Here we use the URLSafeTimedSerializer we created in `util` at the # beginning of the chapter token = ts.dumps(user.email, salt='recover-key') recover_url = url_for('reset_with_token', token=token, _external=True) html = render_template('email/recover.html', recover_url=recover_url) # Let's assume that send_email was defined in myapp/util.py send_email(user.email, subject, html) return redirect(url_for('index')) return render_template('reset.html', form=form)
def create_account(): form = EmailPasswordForm() if form.validate_on_submit(): user = User(username=form.email.data, password=form.password.data, email=form.email.data) db.session.add(user) db.session.commit() # Now we'll send the email confirmation link subject = "Confirm your email" token = ts.dumps(self.email, salt='email-confirm-key') confirm_url = url_for('confirm_email', token=token, _external=True) html = render_template('email/activate.html', confirm_url=confirm_url) # We'll assume that send_email has been defined in myapp/util.py send_email(user.email, subject, html) return redirect(url_for("index")) return render_template("accounts/create.html", form=form)
def compose_email_solution_centric(owner): if project.verbose: print 'COMPOSING: ', owner['Account Email'] # start an email template email = EmailTemplate() email.segment_next() email.greeting(owner['Account Owner']) email.paragraph(project.task['email']['introduction']) # loop through solutions rows = [] for solution in owner['Solutions']: email.segment_next() email.header('Your %d Biggest %s Impact Opportunities This Week' % (project.task['offers'], solution['Solution']['name'])) # create offer matrix for each solution email.table(OFFER_SCHEMA, [( offer['Variant'], '%d%%' % int(offer['Score'] * 100), compose_link( solution['Solution']['link'], { 'solution':solution['Solution']['name'], 'requester':owner['Account Email'], 'name':offer['Variant'], 'dbm':'%s:%s' % (offer['Account_ID'], offer['Variant_ID']) if solution['Solution']['key'] == 'DBM Partner ID' else '', # comma seperated list 'dcm':'%s:%s' % (offer['Account_ID'], offer['Variant_ID']) if solution['Solution']['key'] == 'DCM Network ID' else '', # comma seperated list 'ds':'%s:%s' % (offer['Account_ID'], offer['Variant_ID']) if solution['Solution']['key'] == 'DS Account ID' else '', # comma seperated list 'sa':'%s:%s' % (offer['Account_ID'], offer['Variant_ID']) if solution['Solution']['key'] == 'Studio Account ID' else '', # comma seperated list } ) ) for offer in solution['Offers']]) email.paragraph("Click the request link to schedule a solution for that client. This does not deploy a solution to the client, it only contacts a specialist indicating you'd like to evaluate this solution for this client.") email.header('About ' + solution['Solution']['name']) email.image(solution['Solution']['image'], solution['Solution']['sample']) email.paragraph(solution['Solution']['description']) email.paragraph('Product Gap', bold=True) email.paragraph(solution['Solution']['gap']) # solution pitch email.paragraph('Benefits', bold=True) email.list(solution['Solution']['pitches']) # solution impact email.table(IMPACT_SCHEMA, [(i[0], '%d%%' % i[1]) for i in solution['Solution']['impacts'].items()]) email.button('Learn More', project.task['link'], big=True) #print email.get_html() send_email( 'user', owner['Account Email'], project.task['email']['from'], project.task['email']['cc'], project.task['email']['subject'], email.get_text(), email.get_html() )