예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
 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)
예제 #7
0
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
예제 #8
0
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
예제 #9
0
파일: main.py 프로젝트: asimonov05/Shop
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)
예제 #10
0
파일: routes.py 프로젝트: Nunie123/ahm_back
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)
예제 #11
0
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)
예제 #12
0
파일: user.py 프로젝트: lei375809291/Flask
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)
예제 #13
0
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)
예제 #14
0
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)
예제 #15
0
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)
예제 #16
0
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)
예제 #17
0
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)
예제 #18
0
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)