def reset_stuff_email(): #reset email stuff form = EmailForm() #none if form.validate_on_submit(): #pass_res_email.html email = form.email.data #sends the user with the input eail an email that provides a secure link where they can reset their email user = User.query.filter_by(email=email).first() print(user) if user == None: flash("A user with your data cannot be found") flash("Please remember that this is case sensitive.") return redirect(url_for("reset_stuff_email")) hash = hashlib.sha1() hash.update(str(datetime.now()).encode('utf-8')) print(hash.hexdigest()) msg = MIMEText( u'''<a href="http://*****:*****@gmail.com" msg['To'] = form.email.data print(msg, msg.as_string()) Config.server.sendmail("*****@*****.**", form.email.data, msg.as_string()) flash("An email has been sent to the input email") #TODO email shit ) return render_template("pass_res_email.html", quest_answ=quest_answ, title="Email needed", form=form)
def home(): """ This function is used to send an email using Gmail API using logged in user's account """ userid = session['user_id'] user = User.query.get(int(userid)) form = EmailForm() if request.method == 'POST': if form.validate_on_submit(): email = Email() email.recipient = form.recipient.data email.subject = form.subject.data email.message = form.message.data email.sender = user.id db.session.add(email) db.session.commit() msg_content = form.message.data emailid = email.id msg_body = render_template('email_msg_body.html', msg_content=msg_content, emailid=emailid) service = create_service(userid) msg = create_message(user.email, form.recipient.data, form.subject.data, msg_body) me = 'me' send_message(service, me, msg) # emails = Email.query.filter_by(sender=userid) return redirect(url_for('views.reports')) return render_template('home.html', user=user, form=form) return render_template('home.html', user=user, form=form)
def send_email(): @threaded def send_async_email(msg): with app.app_context(): mail.send(msg) email_form = EmailForm() if email_form.validate_on_submit(): _id = hashids.encode(current_user.id) data = f"{_id}:{request.args.get('data')}" qr_file = get_qr_file(encode_data(data), 'JPEG') target_email = email_form.email.data message = Message('Электронный пропуск', sender=Config.MAIL_ADMIN, recipients=[target_email]) message.body = 'Ваш электронный пропуск во вложении' with app.open_resource(qr_file.name) as fp: message.attach(qr_file.name, "image/jpeg", fp.read()) with app.app_context(): send_async_email(message) return flask.redirect(url_for('get_qr_code')) return flask.render_template('email_send.html', email_form=email_form, id=id)
def sendEmail(request): if request.method == 'POST': form = EmailForm(request.POST) if form.is_valid(): name = form.cleaned_data.get('name') email = form.cleaned_data.get('email') phone = form.cleaned_data.get('phone') mensagem = form.cleaned_data.get('message') if phone != None: send_mail(subject='Contacto de ' + name, message=mensagem + "\nEste email foi enviado por: " + email + "\nContacto telefónico: " + str(phone), from_email=os.getenv('EMAIL'), recipient_list=[ os.getenv('EMAIL_TO'), os.getenv('EMAIL'), email ]) else: send_mail(subject='Contacto de ' + name, message=mensagem + "\nEste email foi enviado por: " + email, from_email=os.getenv('EMAIL'), recipient_list=[ os.getenv('EMAIL_TO'), os.getenv('EMAIL'), email ]) messages.success(request, 'Email sent') return redirect('contact')
def home(): form = EmailForm() if current_user.is_authenticated: if form.validate_on_submit(): return redirect(url_for('logout')) else: if form.validate_on_submit(): return redirect(url_for('signup')) return render_template('home.html',form=form)
def change_email(): form = EmailForm() if form.validate_on_submit(): newemail = form.email.data infoDict = {'user_id': current_user.id, 'newemail': newemail} token = User.generate_token(infoDict) send_mail([newemail], _trans('修改邮箱邮件'), 'email/change_email', username=current_user.username, token=token) flash(_trans('邮件已发送,注意查收')) return render_template('users/change_email.html', form=form)
def email(): email_form = EmailForm() if email_form.validate_on_submit(): msg = Email(title=email_form.title.data, content=email_form.content.data) # 邮件内容会以文本和html两种格式呈现,而你能看到哪种格式取决于你的邮件客户端。 db.session.add(msg) db.session.commit() return '<h1>邮件发送成功</h1><a href="http://127.0.0.1:5000/dashboard">点此回主页</a>' return render_template('email.html', form=email_form)
def submit_email(): form = EmailForm() if form.validate_on_submit(): init_list_analysis.delay(request.form['listId'], request.form['listName'], request.form['totalCount'], request.form['openRate'], session['key'], session['data_center'], form.key.data) return jsonify(True) else: return jsonify(form.errors), 400
def confirm_email(): form = EmailForm() # the email has been properly submitted if form.validate_on_submit(): # retrieve user and check if they exist user = User.query.filter_by(email=form.email.data).first() # user does not exist if user is None: response = jsonify( { "error": "You're not in our pool of users!" }) response.status_code = 404 return response # user exists, make a token from the secret key and # a dictionary of the users email s = Serializer(app.config['SECRET_KEY'], expires_in=600) tok = s.dumps({'email': form.email.data}) # create a url and send it in the email password_reset_url = \ "https://andela-react-client.herokuapp.com/" \ "password-reset/" + str(tok.decode("utf-8")) email_body = \ "Please follow this link to reset your " \ "password\n\n" + password_reset_url + "\n\n If you're " \ "not the one who requested this, please ignore " \ "this and contact the administrator about this." send_email( 'Password Reset Requested', [form.email.data], email_body) # return a success message response = jsonify( { "success": "An email has been sent to you with a link you " "can use to reset your password" }) response.status_code = 200 return response # the form was not properly submitted, return error messages else: response = jsonify({"error": form.errors}) response.status_code = 422 return response
def reset_password(): if current_user.is_authenticated: return redirect(url_for('index')) form = EmailForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if not user: flash('Такого аккаунта не существует!') else: send_change_password_email(user) flash('Вам на почту отправленны дальнейшие инструкции') return render_template('resetPassword.html', form=form)
def reset(): form = EmailForm() if form.validate_on_submit(): user = models.User.query\ .filter_by(email=form.email.data).first_or_404() subject = "Password reset requested" token = generate_confirmation_token(user.email.lower()) print(token) recover_url = url_for('reset_with_token', token=token, _external=True) html = render_template('recover.html', recover_url=recover_url) send_email(user.email, subject, html) flash('A reset link been sent via email.', 'success') return redirect(url_for('index')) return render_template('reset.html', form=form)
def sendEmail(username): # user_profile ( receiver user_profile.email) # current_user ( sender : current_user.email) user_porfile = User.query.filter_by(username=username).first_or_404() # the first ( = exist 'username' ) or email_form = EmailForm() print(user_porfile.email) print('current user', current_user.email) if email_form.validate_on_submit(): subject = email_form.subject.data body = email_form.mail.data send_email(str(subject), sender=current_user.email, recipients=[user_porfile.email], text_body='', html_body=body + '''<br><h2> To reply go to <a href="https://ahmed-nouira-blog4.herokuapp.com"> The BLOG ^^ </a></h2> ''') flash('Your Have send an Email to {}'.format(user_porfile.username)) return redirect(url_for('sendEmail', username=user_porfile.username)) return render_template('send_email.html', title="sendEmail", form=email_form)
def change_em(): flash('请谨慎填写邮箱修改地址,如果邮箱地址不正确,将导致账号无法登陆') form = EmailForm() if form.validate_on_submit(): current_user.email = form.newemail.data current_user.confirmed = False db.session.add(current_user) s = Serializer(current_app.config['SECRET_KEY'], expires_in=3600) token = s.dumps({'id': current_user.id}) # 发送用户激活邮件 send_mail('账户激活', form.newemail.data, 'email/activate.html', username=current_user, token=token) # 弹出消息提示用户下一步操作 flash('注册成功,请点击邮件中的链接完成激活') return render_template('user/change_em.html', form=form)
def send_email(): form = EmailForm() if form.validate_on_submit(): msg = Message( subject="Portfolio - " + form.subject.data, sender=f'{form.subject.data} {MAIL_DEFAULT_SENDER}', recipients=[RECIPIENTS], html=f""" <h3>Nome: {form.name.data}</h3> <h3>Email: {form.email.data}</h3> <p>{form.message.data}</p> """, ) mail.send(msg) flash("Email enviado com sucesso!", "success") return redirect("") return render_template("email.html", form=form)
def email_edit(): form = EmailForm() if request.method == 'POST' and form.validate(): if User.objects(email=form.email.data).first() is None: user = User.objects(email=current_user.email).first() user.email = form.email.data user.confirmed = False user.save() send_confirmation_email(user) flash( "Your email has been updated, please confirm the new email address" ) return redirect(url_for('user_unconfirmed')) else: flash('Email already registered "{}"'.format(form.email.data)) flash_form_errors(form) return redirect(url_for('index'))
def export_mail(): form = EmailForm() if form.validate_on_submit(): recipient = form.email.data text_body = form.msg.data tasks = current_user.tasks.all() send_todo_list_email(recipient, text_body, tasks) flash('Mailed Successfully!') return redirect(url_for('export_mail')) form2 = EmailForm2() if form2.validate_on_submit(): recipient = current_user.email text_body = form2.msg.data tasks = current_user.tasks.all() send_todo_list_email(recipient, text_body, tasks) flash('Mailed Successfully!') return redirect(url_for('export_mail')) return render_template('export_mail.html', form=form, form2=form2)
def index(): referring_uuid = request.args.get('user') form = EmailForm() if request.method == 'POST': if form.validate(): email = utils.normalize_email(form.email.data) user = logic.get_user_by_email(email) if user is None: user = logic.create_user(email) myemail.send_verification_email(user.id, user.email, referring_uuid=referring_uuid) return redirect(url_for('main.waitlist', user=user.waitlist.uuid)) elif request.method == 'GET': return render_template('index.html', form=form, referring_uuid=referring_uuid)
def reset(): if current_user.is_authenticated: return redirect(url_for('dashboard')) form = EmailForm() if form.validate_on_submit(): try: user = User.query.filter_by(email=form.email.data).first_or_404() except: flash('Invalid email address!', 'error') return render_template('password_reset_email.html', form=form) if user.email_confirmed: send_password_reset_email(user.email) flash('Please check your email for a password reset link.', 'success') else: flash( 'Your email address must be confirmed before attempting a password reset.', 'error') return redirect(url_for('login')) return render_template('password_reset_email.html', form=form)
def email_register(): form = EmailForm() if request.method == 'POST': form.email.data = form.email_name.data + current_app.config[ 'REGISTRATION_EMAIL_DOMAIN'] if form.validate_on_submit(): email = User.query.filter_by(email=form.email.data).first() if not email: token = generate_confirmation_token(form.email.data) flash( '{}으로 이메일이 전송되었습니다. 전송된 URL을 통하여 회원가입을 진행해주십시오.'.format( form.email.data), 'info') confirm_url = url_for('auth.confirm_email', token=token, _external=True) contents = render_template('/constant/email.html', confirm_url=confirm_url) send_email(form.email.data, '[CVIP] email verification', contents) return redirect('/') else: flash('email already exist.', 'danger') return render_template('/main/auth/register.html', form=form)
def change_email(): form = EmailForm() if form.validate_on_submit(): if current_user.email == form.old_email.data: current_user.confirmed = False db.session.add(current_user) db.session.commit() token = current_user.generate_activate_token() send_mail(current_user.email, '账号重置', 'email/account_activate', token=token, username=current_user.username) current_user.email = form.new_email.data # current_user.confirmed = True # db.session.add(current_user) flash('邮箱发送成功') return redirect(url_for('main.index')) else: flash('原始邮箱不存在') return redirect(url_for('user.change_email.html')) return render_template('user/change_email.html', form=form)
def email_form(): form = EmailForm() if form.validate_on_submit(): # include a subject!!!!! draft, draft_html = Pitch(form.your_name.data, form.company_name.data, form.contact_person_name.data, form.where_find.data, form.impressed_by.data, form.vertical.data).compose_email() meta = 'Send final draft to {} at {}\n'.format( form.contact_person_name.data, form.contact_person_email.data) text_body = meta + draft text_html = '<p>' + meta + '<p>' + draft_html print(text_body) print(text_html) send_email( '{} Sourcing Email Draft'.format(form.company_name.data), sender=app.config['ADMINS'][0], recipients=[form.your_email.data], #get from form, text_body=text_body, html_body=text_html) return redirect(url_for('email_sent')) return render_template('email_form.html', title='Compose Your Email', form=form)
def contact(): form = EmailForm() return render_template('contact.html', title='Contact Me:', form=form)
def splash(request,show=''): is_splash = "splash" client_sub_domain = CLIENT_SUB_DOMAIN if not request.user.is_authenticated(): form = AuthenticationForm() registerForm = UserCreationForm() if request.method=="POST": register(request) return HttpResponseRedirect("/") else: recent_ideas = Idea.objects.exclude(private=True).order_by('?')[:6] return render_to_response("main/splash.html", locals(), context_instance=RequestContext(request)) # # else there is a user and we can just show the general page # else: user = request.user #if user.has_perm(app.idea.can_add): # post_idea = True #else: # post_idea = False if request.method == 'POST': #If something has been submitted if 'vote' in request.POST: voteForm = VoteForm(request.POST) if voteForm.is_valid(): helpers.vote(voteForm,request.user) if 'submit_email' in request.POST: emailForm = EmailForm(request.POST) if emailForm.is_valid(): clean = emailForm.cleaned_data exists = User.objects.filter(email=clean['email']) if len(exists) > 0: messages.error(request, ( "That e-mail address is " "already in use, have you signed up before " "using a different username?")) return HttpResponseRedirect("/") user.email = clean['email'] helpers.send_verify_email(clean['email'],user,request) user.save() if 'submit_idea' in request.POST: idea = helpers.add_idea(request) if 'submit_idea_elaborate' in request.POST: idea = helpers.add_idea(request) if idea: return HttpResponseRedirect(reverse('edit-idea', args=[idea.id])) voteUpForm = VoteForm({'vote':'+'}) voteDownForm = VoteForm({'vote':'-'}) ideaForm = IdeaForm() searchForm = SearchForm() emailForm = EmailForm({'email':user.email}) all_ideas = Idea.objects.exclude(private=True).annotate(votes=Count('vote_on')) if show == 'started': all_ideas = Idea.objects.filter(started=True).exclude(private=True).annotate(votes=Count('vote_on')) elif show == 'not-started': all_ideas = Idea.objects.exclude(started=True).exclude(private=True).annotate(votes=Count('vote_on')) if show == 'top': all_ideas = all_ideas.order_by('-votes') else: all_ideas = all_ideas.order_by('-date') all_ideas = helpers.process_ideas(user, all_ideas) return render_to_response("main/home.html",locals(), context_instance=RequestContext(request))
def index(): keyForm = ApiKeyForm() emailForm = EmailForm() return render_template('index.html', keyForm=keyForm, emailForm=emailForm)