示例#1
0
def forgot_password():

    kwargs = {
        'page_title':
        'Reset Password',
        'form_title':
        'Reset Your Password',
        'action':
        url_for('forgot_password'),
        'primary_button':
        'Submit',
        'links': [("Don't have an account?", url_for('signup')),
                  ('Need help?', '#')]
    }

    form = EmailForm(request.form)

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if not user:
            flash('Cannot find that email, sorry.', 'danger')
        else:
            user.reset = True
            db.session.commit()

            send_reset_password(user.email)
            flash('Check your email for a link to reset your password.',
                  'success')

            return redirect(url_for('homepage'))

    return render_template('formbuilder.html', form=form, **kwargs)
示例#2
0
def inputemail():
    """Through Email to get a link for reseting password."""

    form = EmailForm()

    if form.validate_on_submit():
        user = Users.query.filter(Users.email == form.email.data)

        if user.count() != 1:
            flash("Wrong email, please try again.")

        else:
            username = user[0].username
            email = user[0].email

            msg = Message(f'for {username}',
                          sender='*****@*****.**',
                          recipients=[f'{email}'])
            msg.body = URL_HOME + 'resetpw'
            mail.send(msg)

            session['username'] = username

            return 'Mail Sent. Please check your E-mail.'

    return render_template('users/inputemail.html', form=form)
示例#3
0
def password_reset_via_email():
    form = EmailForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user is None:
            flash('Error! Invalid email address!', 'danger')
            return render_template('users/password_reset_via_email.html',
                                   form=form)

        if user.email_confirmed:

            @copy_current_request_context
            def send_email(email_message):
                with current_app.app_context():
                    mail.send(email_message)

            # Send an email confirming the new registration
            message = generate_password_reset_email(form.email.data)
            email_thread = Thread(target=send_email, args=[message])
            email_thread.start()

            flash('Please check your email for a password reset link.',
                  'success')
        else:
            flash(
                'Your email address must be confirmed before attempting a password reset.',
                'danger')
        return redirect(url_for('users.login'))

    return render_template('users/password_reset_via_email.html', form=form)
示例#4
0
def resend_confirmation():

    kwargs = {
        'page_title':
        'Resend Confirmation',
        'form_title':
        'Resend Confirmation Token',
        'action':
        url_for('resend_confirmation'),
        'primary_button':
        'Submit',
        'links': [("Don't have an account?", url_for('signup')),
                  ('Need help?', '#')]
    }

    form = EmailForm(request.form)

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if not user:
            flash('Cannot find that email, sorry.', 'danger')
        elif user.confirmed:
            flash(
                'Your account has already been verified. You can log in using your credentials',
                'info')
        else:
            send_confirm_email(user.email)
            flash('Check your email for a link to verify your account.',
                  'success')

            return redirect(url_for('homepage'))

    return render_template('formbuilder.html', form=form, **kwargs)
示例#5
0
def re_verify():
    form = EmailForm(request.form)

    if form.validate_on_submit():
        send_verification_email(form.get_user())
        flash('Check your email for verification!')
        return redirect(url_for('home'))
    return render_template('no_email_verification.html', form=form) 
示例#6
0
def mass_mail():
    form = EmailForm()
    if request.method == 'GET':
        if 'workshop' in request.args:
            uid = request.args.get('workshop')
            workshop = db_session.query(Workshop).filter_by(id=uid).first()

            return render_template('email.html',
                                   form=form,
                                   workshop=workshop,
                                   title='cutrenet')
        else:
            return render_template('email.html', form=form, title='cutrenet')
    if request.method == 'POST':
        if form.validate_on_submit():
            if form.attachment.data:
                f = form.attachment.data
                filename = secure_filename(f.filename)
                file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
                f.save(file_path)
                if 'workshop' in request.args:
                    uid = request.args.get('workshop')
                    users = User.query.filter(User.workshops.any(id=uid)).all()
                    flash(
                        u'Correo enviado a todos los participantes del taller',
                        'success')
                else:
                    users = User.query.filter(User.roles.any(Role.id.in_([
                        2
                    ]))).all(
                    )  # We pick the users that have role member (ID 2 in table roles)
                    flash(u'Correo enviado a todos los miembros', 'success')
                email(app, mail, request.form, filename, users)
                os.remove(file_path)
            else:
                if 'workshop' in request.args:
                    uid = request.args.get('workshop')
                    users = User.query.filter(User.workshops.any(id=uid)).all()
                    flash(
                        u'Correo enviado a todos los participantes del taller',
                        'success')
                else:
                    users = User.query.filter(User.roles.any(Role.id.in_([
                        2
                    ]))).all(
                    )  # We pick the users that have role member (ID 2 in table roles)
                    flash(u'Correo enviado a todos los miembros', 'success')
                email(app, mail, request.form, '', users)

        if 'workshop' in request.args:
            uid = request.args.get('workshop')
            workshop = db_session.query(Workshop).filter_by(id=uid).first()
            return render_template('email.html',
                                   form=form,
                                   workshop=workshop,
                                   title='cutrenet')
        else:
            return render_template('email.html', form=form, title='cutrenet')
示例#7
0
def profile():
    form = EmailForm()
    if form.validate_on_submit():
        g.user.email = form.email.data
        db.session.add(g.user)
        db.session.commit()
        flash("Email was changed", "success")
        return redirect(url_for("index"))
    else:
        flash_errors(form)
    form.email.data = g.user.email
    return render_template("profile.html", form=form)
示例#8
0
def publish_poster(id_admin):
    p = Poster.query.filter_by(id_admin=id_admin).first_or_404()
    form = EmailForm()
    if form.validate_on_submit():
        p.email = form.email.data
        db.session.add(p)
        db.session.commit()
        send_admin_info(p, sender=app.config['MAIL_FROM'])
        flash(
            'Information successfully updated! You should receive an email soon.'
        )
        return redirect(url_for('publish_poster', id_admin=p.id_admin))
    return render_template('publish_poster.html', form=form, poster=p)
示例#9
0
def EmailIt():
    form = EmailForm()
    global file_name
    text2 = open(file_name, 'r+')
    contents = text2.read()
    text2.close()
    if (form.validate_on_submit()):
        emailsender(form.email.data)
        flash('Email sent', 'info ')
        return render_template('contents.html',
                               title="read",
                               contents=contents)
    return render_template('emailit.html', title="emailit", form=form)
示例#10
0
文件: views.py 项目: faith0811/chart3
def sign_in():
    form = EmailForm()
    if form.validate_on_submit():
        email = form.email.data
        try:
            user = User.get(email=email)
        except User.DoesNotExist:
            #print ('errorrrrrrr!')
            return render_template('sign_in.html', form=form, login_error=True, reg_url=url_for('reg'))
        else:
            log_user(user)
            return redirect(url_for('index'))
    return render_template('sign_in.html', form=form, login_error=False, reg_url=url_for('reg'))
示例#11
0
def reset_password():
    form = EmailForm()
    if form.validate_on_submit():
        user = mongo_db.users.User.find_one({'email' : form.email.data})

        subject = "Succor password reset requested"
        token = ts.dumps(user.email, salt='recover-key')
        recover_url = url_for('reset_with_token', token=token, _external=True)
        body = render_template('email/recover.txt', url=recover_url)
        html = render_template('email/recover.html', url=recover_url)
        send_email(subject, app.config['FROM_EMAIL_ADDRESS'], [user.email], body, html)

        flash('Check your email for password reset link')
        return redirect(url_for('home'))
    return render_template('reset.html', form=form)
示例#12
0
def form():
    info_form = EmailForm()
    if info_form.validate_on_submit():
        # flash(f"Email sent for {info_form.job_position.data} at {info_form.company_name.data} ", 'success')
        job_position = info_form.job_position.data
        company_name = info_form.company_name.data
        heard_about = info_form.heard_about.data
        recipient_email = info_form.recipient_email.data
        send_email(job_position, company_name, recipient_email, heard_about)
        return redirect(url_for('form', form=info_form))
        # return redirect(url_for('email_render', job_position = job_position, company_name = company_name, heard_about = heard_about, recipient_email = recipient_email))
    # else:
    #     flash("failure!")
    #     return redirect(url_for('form'))
    return render_template(r"form.html",  form = info_form)
示例#13
0
def edit_email(contact_id):
    my_email = Email.query.filter_by(contact_id=contact_id).first()
    form = EmailForm(obj=my_email)

    if form.validate_on_submit():
        try:
            form.populate_obj(my_email)
            database.session.add(my_email)
            database.session.commit()

            flash('Save Successfully', 'success')
            return redirect(url_for('emails', contact_id=contact_id))
        except:
            database.session.rollback()

            flash('Error !', 'danger')
            return redirect(url_for('emails', contact_id=contact_id))

    return render_template('web/edit_email.html', form=form)
示例#14
0
def subscribe():
    # TODO: conditional on method?
    # TODO: fill with form data?
    email_form = EmailForm()

    mime_type = request.mimetype
    # json
    if mime_type == 'application/json':
        return 'ok'
    # html
    else:
        # Form submission
        if email_form.validate_on_submit():
            sub = Subscription(email_form.email.data)
            db_session.add(sub)
            db_session.commit()

        flash("Thanks! You've been subscribed.")
        return redirect(url_for('index'))
示例#15
0
def editemail(id):
  user = User.query.get(session['user_id'])
  emailForm = EmailForm()
  emailForm.email.default = user.email
  if emailForm.validate_on_submit():
    if (emailForm.email.data != emailForm.email.default):
      users1 = user.query.all()
      for user1 in users1:
        if (emailForm.email.data == user1.email):
          flash('Error: Email is already in use by another user')
          return redirect(url_for('show', id=user.id))
      user.email = emailForm.email.data
      db.session.commit()
      flash('Email Successfully Updated')
      return redirect(url_for('show', id=user.id))
    flash('Your original email, '+user.email+' has been saved')
    return redirect(url_for('show', id=user.id))
  flash('Error: Invalid Email Address')
  return redirect(url_for('show', id=user.id))
示例#16
0
def login():
    email_form = EmailForm()

    enter_code_block_expired_at = session.get('enter_code_block_expired_at')
    if enter_code_block_expired_at and datetime.now(
    ) < enter_code_block_expired_at:
        seconds_to_wait = (enter_code_block_expired_at -
                           datetime.now()).seconds

        err_msg = f'Please wait {seconds_to_wait} seconds before create a new enter code'
        email_form.email.errors = [err_msg]

        return render_template('auth/login.html', form=email_form)

    if email_form.validate_on_submit():
        email_form.send_enter_code()
        return redirect(url_for('.login_by_code'))

    return render_template('auth/login.html', form=email_form)
示例#17
0
def subscribe():
    # TODO: conditional on method?
    # TODO: fill with form data?
    email_form = EmailForm()

    mime_type = request.mimetype
    # json
    if mime_type == 'application/json':
        return 'ok'
    # html
    else:
        # Form submission
        if email_form.validate_on_submit():
            sub = Subscription(email_form.email.data)
            db_session.add(sub)
            db_session.commit()

        flash("Thanks! You've been subscribed.")
        return redirect(url_for('index'))
示例#18
0
def contact():
    form = EmailForm()
    email_filler = ""
    name_filler = ""
    if session.get('email'):
        email_filler = session.get('email')
        name_filler = session.get('username')
    if form.validate_on_submit():
        # send email here
        msg = Message(request.form['subject'],
                      recipients=['*****@*****.**'])
        msg.body = f'This Email was sent from your website\nfrom {request.form["name"]} \temail: {request.form["email"]}\n\n{request.form["message"]}'
        mail.send(msg)
        flash("Your email has been sent!!!")
        return redirect(url_for('contact'))

    return render_template("contact.html",
                           page="contact",
                           form=form,
                           email_filler=email_filler,
                           name_filler=name_filler)
示例#19
0
def contact():
    form = EmailForm()
    if form.validate_on_submit():
        msg = Message(form.subject.data,
                      sender='*****@*****.**',
                      recipients=['*****@*****.**'])
        msg.body = f"""{form.email.data}
{form.name.data}
{form.message.data}"""

        mail.send(msg)
        flash('Your Email Has Been Sent, Thanks!', 'flashed-success')
        form.name.data = ""
        form.email.data = ""
        form.subject.data = ""
        form.message.data = ""
    elif request.method == 'POST':
        flash('Your Email Is Invalid please Check of Its!', 'flashed-danger')
    return render_template('contact.html',
                           title='Mahmoud - Contact Me',
                           form=form)
示例#20
0
def check_email():
    """Password change: produces form for confirming user email"""

    form = EmailForm()
    if form.validate_on_submit():
        user = User.query.filter(User.email == form.email.data).first()
        secret_token = secrets.token_urlsafe(20)

        if user:
            user.reset_token = secret_token
            db.session.commit()

            send_mail_async(user)
            flash("A link has been sent to your email to reset your password",
                  "success")

            return redirect('/check-email')
        else:
            form.email.errors = ["We do not have this email in our system"]

    return render_template('check_email.html', form=form)
示例#21
0
def email_someone():
    """
    This function actually emails the message.

    Make sure you change the from_address variable if you want to use this
    functionality -- otherwise it won't work.
    """
    form = EmailForm()
    if request.method == 'POST' and form.validate_on_submit():
        from_address = form.name.data + '@<YOURAPPID>.appspotmail.com'
        to_address = form.recipient.data
        subject = "%s <%s>" % (form.name.data, form.email.data)
        message = ("From: %s\n\n"
                   "Email: %s\n\n"
                   "Message: %s") % (form.name.data, form.email.data,
                           form.message.data)
        mail.send_mail(sender=from_address, to=to_address,
                subject=subject, body=message)
        status = 'success'
    else:
        status = 'failed'
    return redirect(url_for('email_status', status=status))
def index():
	email_form = EmailForm()
	if email_form.validate_on_submit():
		email_address = email_form.email.data
		prev_user = User.query.filter_by(email = email_address).first()
		if (prev_user is not None):
			if (prev_user.verified):
				flash('That email address has already been submitted and verified')
			else:
				#the situation where a previous email has already been seen
				flash('That email address is already in our records but we will resend the verification email.')
				return redirect(url_for('index'))

			#NEED TO HANDLE CASE WHERE EMAIL ALREADY EXISTS
		new_user = User(email=email_address, date_submitted=datetime.now())
		db.session.add(new_user)
		db.session.commit()
		token = user.generate_confirmation_token()
		send_verification_email('email/confirm', 'Confirm Your Account', user=user, token = token)
 
		return redirect(url_for('thanks'))

	return render_template('index.html', form = email_form)
示例#23
0
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"
        print(subject)

        # 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('home.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(subject, 'no-reply@coeas', user.email, html)

        return redirect(url_for('home.index'))
    return render_template('home/reset.html', form=form)
示例#24
0
def show_main():
    form = EmailForm()
    if form.validate_on_submit():
        pass
    return render_template('home.html', form = form)
示例#25
0
def show_main():
    form = EmailForm()
    if form.validate_on_submit():
        pass
    return render_template('home.html', form=form)
示例#26
0
文件: app.py 项目: John-Oula/azalia
def index():
	form = EmailForm()
	if form.validate_on_submit():
		r = requests.post('https://api.airtable.com/v0/appkgAiCIYTQKx0Vx/Tenants', data = {'email': form.email.data})
		print(r.text)
	return render_template('index.html', form=form)