コード例 #1
0
ファイル: app.py プロジェクト: martinspetlik/PWA
def post_reset():
    """
    Handle post request, send email, save token to database
    :return:
    """
    email = request.get_json()['email']
    cur_user = User.objects(email=email).first()

    if not cur_user:
        return jsonify({
            "success": False,
            "message": "No user has this email: {}".format(email)
        }), 200

    token = s.dumps(email, salt='email-password-reset')
    msg = MailMessage('Confirm Email',
                      sender=mail_settings["MAIL_USERNAME"],
                      recipients=[email])
    link = "https://pwachat2.herokuapp.com/?token={}".format(token)
    msg.body = 'Your link is {}'.format(link)
    mail.send(msg)

    return jsonify({
        "success": True,
        "message": "Email was sent to: {}".format(email)
    }), 200
コード例 #2
0
    def post(self):
        """
        Handle post request, send email, save token to database
        :return:
        """
        email = request.get_json()['email']
        cur_user = User.objects(email=email).first()

        if not cur_user:
            return {
                "success": False,
                "message": "No user has this email: {}".format(email)
            }

        #PasswordReset_db(user=cur_user, token=token).save()
        token = s.dumps(email, salt='email-password-reset')
        msg = MailMessage('Confirm Email',
                          sender='*****@*****.**',
                          recipients=[email])
        link = url_for('passwordreset', token=token, _external=True)
        link = "http://localhost:3000/reset/{}".format(token)
        msg.body = 'Your link is {}'.format(link)
        mail.send(msg)

        return {
            "success": True,
            "message": "Email was sent to: {}".format(email)
        }
コード例 #3
0
def contact():
    form = ContactForm()

    if request.method == 'POST' and form.validate_on_submit():
        name = request.form.get('user_name')
        email = request.form.get('user_email')
        message = request.form.get('message')

        msg_body = "%s %s <br><br> %s" % (name, email, message)
        msg = MailMessage(body=msg_body,
                          html=msg_body,
                          subject=u"İletişime geçmek isteyen var",
                          sender=(u"Eşya Kütüphanesi",
                                  "*****@*****.**"),
                          recipients=[
                              "*****@*****.**",
                              "*****@*****.**"
                          ])

        mail.send(msg)

        flash(u"E-postan gönderildi!")
        return redirect(url_for('contact'))

    return render_template("contact.html", form=form, user=current_user)
コード例 #4
0
ファイル: admin.py プロジェクト: EsyaKutuphanesi/things-demo
    def request_detail_view(self, id):
        unapproved_user = User.query.filter(User.approved == False,
                                            User.id == id).first()
        if not unapproved_user:
            flash(u"Kullanıcı zaten onaylı!")
            return redirect(url_for('.index_view'))

        msg_body = render_template('email/request_detail.txt',
                                   user=unapproved_user)
        html_msg = render_template('email/request_detail.html',
                                   user=unapproved_user)

        msg_subject = u"Ufak bir rica!"
        msg = MailMessage(body=msg_body,
                          html=html_msg,
                          subject=msg_subject,
                          sender=(u"Eşya Kütüphanesi",
                                  "*****@*****.**"),
                          recipients=[unapproved_user.email])

        mail.send(msg)
        flash(
            u"Kullanıcıya e-posta gönderilerek daha fazla bilgi vermesi talep edildi!"
        )
        return redirect(url_for('.index_view'))
コード例 #5
0
ファイル: malimo.py プロジェクト: malimohub/malimoHome
def messenger():
    inquirerName = request.form['name']
    inquirerEmail = request.form['email']
    inquirerMessage = request.form['message']
    msg = MailMessage(inquirerMessage,
                      sender=inquirerEmail,
                      recipients=["*****@*****.**"])
    mail.send(msg)
    return redirect(url_for('get_malimo_home'))
コード例 #6
0
def inviamail(ricevente):
    msg = MailMessage('NoReply - Officina',
                      sender='*****@*****.**',
                      recipients=[ricevente.email])
    msg.body = "Buongiorno, \n la riparazione sul mezzo: " + ricevente.marca + " " + ricevente.modello + ", a nome: " + ricevente.nome + " " + ricevente.cognome + " è terminata.\nPrezzo Finale: " + ricevente.prezzo + "\nSaluti, MechSite"
    with app.open_resource("/var/www/webApp/webApp/static/blank.pdf") as fp:
        msg.attach("Resoconto.pdf", "application/pdf", fp.read())
    mail.send(msg)
    return 1
コード例 #7
0
    def send_reset_email(self):
        """Send password reset email."""
        token = self.get_reset_token()
        msg = MailMessage(
            "Password Reset Request",
            recipients=[self.email],
        )
        msg.body = f"""To reset your password, visit the following link:

{url_for('users.reset_token', token=token, _external=True)}

If you did not make this request, please ignore this email.
"""
        mail.send(msg)
コード例 #8
0
def send_reset_email(user):
    token = user.reset_token()
    try:
        msg = MailMessage(subject='Password Reset Request',
                          sender='*****@*****.**',
                          recipients=[user.email])

        msg.body = f'''To reset your password please visit the following link
        {url_for('reset_password', token=token, _external=True)}
        If you didn't make this request, Ignore this email and nothing is gonna change.
        ''' ''
        mail.send(message=msg)
    except Exception as e:
        raise e
コード例 #9
0
ファイル: user.py プロジェクト: xcodinas/covidcore
 def post(self):
     args = password_recovery_parser.parse_args()
     user = User.query.filter_by(email=args.email).first()
     if not user:
         return abort(400, message='This user does does not exist.')
     user.recovery_code = uuid.uuid4().hex
     user.recovery_code_expiration = (datetime.datetime.now() +
                                      datetime.timedelta(hours=3))
     db.session.commit()
     with mail.connect() as conn:
         # Send Email
         msg = MailMessage("Cambiar contraseña",
                           sender=("mail", "*****@*****.**"))
         msg.add_recipient(user.email)
         msg.html = render_template("email/pass_recovery.html", user=user)
         conn.send(msg)
     return {'success': 1}
コード例 #10
0
ファイル: Orms.py プロジェクト: williamtse/dotadytt
    def send_active_mail(self):
        with app.app_context():
            print 'send active mail to ' + self.email
            email = self.email
            username = self.name
            active_token = md5(email + str(self.token_expire) +
                               app.config['SECRET_KEY'])
            msg = MailMessage(u"DOTA电影天堂-欢迎-请验证邮箱地址",
                              sender=u"DOTA电影天堂用户注册<*****@*****.**>",
                              recipients=[email])
            token = base64.b64encode(active_token)
            domain = app.config['SITE_DOMAIN']
            url = domain + '/signup_active?user='******'&token=' + token
            msg.html = '<h1 style="text-align:center"><a href="'+domain\
            +'" target="_blank"><img src="'+domain+'/static/img/logo.png"></h1><p><a href="'+url+'">'+url+'</a></p>'

            thread = Thread(target=send_async_email, args=[app, mail, msg])
            thread.start()
            return True
コード例 #11
0
ファイル: views.py プロジェクト: baa-archieve/esyakutuphanesi
def invite():
    form = InvitationForm()

    if request.method == 'POST' and form.validate_on_submit():

        emails = request.form.get('emails')
        message = request.form.get('message')

        invite_info = Invitations(
            user_id=current_user.id,
            emails=emails,
            message=message
        )

        db.session.add(invite_info)
        db.session.commit()

        email_list = emails.split()

        for email in email_list:
            msg_body = '%s <br><br> %s <br><br> esyakutuphanesi.com'\
                       % (current_user.name, message)
            html_msg = '%s <br><br> %s <br><br> <a href="http://esyakutuphanesi.com/">esyakutuphanesi.com</a>' \
                       % (current_user.name, message)
            msg_subject = u"%s seni Eşya Kütüphanesi'ne davet ediyor!" % current_user.name
            msg = MailMessage(
                body=msg_body,
                html=html_msg,
                subject=msg_subject,
                sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
                recipients=[email]
            )

            mail.send(msg)

        flash(u"Davetini ilettik!")
        return redirect(url_for('invite'))

    return render_template("invite.html", form=form, user=current_user)
コード例 #12
0
ファイル: views.py プロジェクト: baa-archieve/esyakutuphanesi
def check_approved(source=None):
    if current_user.approved:
        return redirect(url_for('home'))
    else:
        if source == 'register':

            flash(u'Üyeliğin onay bekliyor. Onaylandığı zaman e-posta ile sana haber vereceğiz.')
            msg_body = "%s %s <br><br> %s" % (current_user.name, current_user.email, current_user.why)
            msg = MailMessage(
                body=msg_body,
                html=msg_body,
                subject=u"Yeni Üye",
                sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
                recipients=["*****@*****.**"]
            )

            mail.send(msg)

        elif source == 'login':
            flash(u'Üyeliğin onay bekliyor.')
        logout_user()
        return redirect(url_for('home'))
コード例 #13
0
ファイル: admin.py プロジェクト: EsyaKutuphanesi/things-demo
    def approval_view(self, id):
        unapproved_user = User.query.filter(User.approved == False,
                                            User.id == id).first()
        if not unapproved_user:
            flash(u"Kullanıcı zaten onaylı!")
            return redirect(url_for('.index_view'))

        unapproved_user.approved = True
        db.session.commit()

        msg_body = render_template('email/welcome.txt', user=unapproved_user)
        html_msg = render_template('email/welcome.html', user=unapproved_user)

        msg_subject = u"Hoşgeldin!"
        msg = MailMessage(body=msg_body,
                          html=html_msg,
                          subject=msg_subject,
                          sender=(u"Eşya Kütüphanesi",
                                  "*****@*****.**"),
                          recipients=[unapproved_user.email])

        mail.send(msg)
        flash(u"Kullanıcı onaylandı ve e-posta gönderildi!")
        return redirect(url_for('.index_view'))
コード例 #14
0
ファイル: views.py プロジェクト: baa-archieve/esyakutuphanesi
def moderation():
    action = request.args.get("action")
    id = request.args.get("id")

    user_action = request.args.get("user_action")
    user_id = request.args.get("user_id")

    new_user = User.query.filter(User.id > 0).order_by(User.id.desc()).limit(40)

    if action == 'approve' and id > 0:
        if 'admin' in current_user.roles:
            stuff = Stuff.query.filter(Stuff.approved == 0,
                                       Stuff.id == id). \
                order_by(Stuff.id.desc()).first()
        else:
            stuff = Stuff.query.join(Group).join(GroupMembership) \
                .filter(GroupMembership.user_id == current_user.id,
                        GroupMembership.is_moderator,
                        Stuff.id == id,
                        Stuff.approved == 0). \
                order_by(Stuff.id.desc()).first()
        if stuff:
            stuff.approved = 1
            db.session.commit()

            msg_body = render_template('email/approved.txt', user=stuff.owner, stuff=stuff)

            html_msg = render_template('email/approved.html', user=stuff.owner, stuff=stuff)

            msg_subject = u"Eşyan artık sitede!"

            msg = MailMessage(
                body=msg_body,
                html=html_msg,
                subject=msg_subject,
                sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
                recipients=[stuff.owner.email]
            )

            mail.send(msg)

            flash(u"Eşya onaylandı ve e-posta gönderildi!")

    if user_action == 'approve_user' and user_id > 0:
        unapproved_user = User.query.filter(User.approved == False, User.id == user_id). \
            order_by(User.id.desc()).first()

        if unapproved_user:
            unapproved_user.approved = True
            db.session.commit()

            msg_body = render_template('email/welcome.txt', user=unapproved_user)
            html_msg = render_template('email/welcome.html', user=unapproved_user)

            msg_subject = u"Hoşgeldin!"
            msg = MailMessage(
                body=msg_body,
                html=html_msg,
                subject=msg_subject,
                sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
                recipients=[unapproved_user.email]
            )

            mail.send(msg)

            flash(u"Kullanıcı onaylandı ve e-posta gönderildi!")

    if 'admin' in current_user.roles:
        last_objects = Stuff.query.filter(Stuff.id > 0).\
            order_by(Stuff.id.desc()).limit(40)

    else:
        last_objects = Stuff.query.join(Group).join(GroupMembership)\
            .filter(GroupMembership.user_id == current_user.id,
                    GroupMembership.is_moderator).order_by(Stuff.id.desc()).limit(40)

    return render_template(
        "moderation.html",
        user=current_user,
        new_user=new_user,
        last_objects=last_objects
    )
コード例 #15
0
ファイル: views.py プロジェクト: baa-archieve/esyakutuphanesi
def make_request(stuff_id=None):
    form = RequestForm()
    message = None
    return_url = request.form['return_url']
    if form.validate_on_submit():
        message = form.message.data
        stuff_id = form.stuff_id.data
        duration = int(form.duration.data)
        unit = int(form.unit.data)

        address = Address.query.filter(Address.user_id == current_user.id).first()

        if address:
            if stuff_id is None or not (stuff_id > ''):
                flash(u'İstek gönderilemedi.')
                return redirect(return_url)
            stuff = Stuff.query.filter(Stuff.id == stuff_id).first()

            if stuff.is_wanted == True:
                user = stuff.owner
                from_user = current_user
            else:
                user = current_user
                from_user = stuff.owner

            new_request = Request(
                stuff_id=stuff_id,
                user_id=user.id,
                from_user_id=from_user.id,
                duration=(duration * unit)
            )

            db.session.add(new_request)
            new_conversation = Conversation(
                title='%s' % stuff.title,
                users=[current_user, stuff.owner],
                request=new_request
            )

            db.session.add(new_conversation)

            new_message = Message(
                from_user=current_user,
                to_user=stuff.owner,
                conversation=new_conversation,
                txt=message
            )

            db.session.add(new_message)

            db.session.commit()

            msg_body = render_template('email/request.txt', to_user=user, from_user=from_user,
                                       stuff=stuff, conversation_url=new_conversation.url)

            html_msg = render_template('email/request.html', to_user=user, from_user=from_user,
                                       stuff=stuff, conversation_url=new_conversation.url)
            if stuff.is_wanted:
                msg_subject = u"%s sana %s ödünç vermek istiyor" % (from_user.name, stuff.title)

            else:
                msg_subject = u"%s için bir talip var!" % stuff.title

            msg = MailMessage(
                body=msg_body,
                html=html_msg,
                subject=msg_subject,
                sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
                recipients=[stuff.owner.email]
            )

            mail.send(msg)

            return redirect(url_for('my_messages'))

        else:
            flash(u'Ödünç istemek için adres girmelisin.')
            return redirect(url_for('new_address'))
    else:
        flash(u'İstek gönderilemedi. Kaç gün için ödünç istediğini girmelisin.')
        return redirect(return_url)
コード例 #16
0
ファイル: views.py プロジェクト: baa-archieve/esyakutuphanesi
def show_conversation(conversation_id):
    conversation = Conversation.query.\
        filter(Conversation.id == conversation_id).first()

    if current_user not in conversation.users:
        redirect('/my_messages')

    form = ConversationForm()
    if request.method == 'POST' and form.validate_on_submit():

        if current_user.id == conversation.request.user.id:
            to_user = conversation.request.from_user
        else:
            to_user = conversation.request.user

        print to_user.id
        new_message = Message(
            from_user=current_user,
            to_user=to_user,
            conversation=conversation,
            txt=form.message.data
        )
        db.session.add(new_message)
        db.session.commit()

        msg_body = render_template('email/conversation.txt', user=to_user, from_user=current_user.name,
                                   stuff_title=conversation.title, conversation=new_message)

        html_msg = render_template('email/conversation.html', user=to_user, from_user=current_user.name,
                                   stuff_title=conversation.title, conversation=new_message)

        # msg_body = u'%s sana mesaj gönderdi. <br><br> esyakutuphanesi.com'\
        #            % current_user.name
        # html_msg = u'%s sana mesaj gönderdi. <br><br> Mesajı okumak için' \
        #            u' <a href="http://esyakutuphanesi.com/conversation/{{conversation_id}}">tıkla!</a>' \
        #            % current_user.name

        msg_subject = u"Mesajın var"

        msg = MailMessage(
            body=msg_body,
            html=html_msg,
            subject=msg_subject,
            sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
            recipients=[to_user.email]
        )

        mail.send(msg)

    Message.query.filter(
        Message.conversation_id == conversation_id,
        Message.status == 0,
        Message.to_user == current_user
    ).update({Message.status: 1})
    db.session.commit()

    form.message.data = None

    review_form = ReviewForm()

    if request.args.get('status'):
        status = int(request.args.get('status'))
    else:
        status = 0
    if status > 0 and \
            (conversation.request.stuff.owner == current_user or conversation.request.from_user_id == current_user.id):
        if conversation.request.stuff.status == 1:
            if status == 1 and conversation.request.status == 0:
                flash(u'Eşyayı vermeyi kabul ettiniz.')
                conversation.request.stuff.status = 0
                conversation.request.status = 1
                conversation.request.given_at = datetime.utcnow()
                db.session.commit()
        elif status == 2 and conversation.request.status == 1:
            flash(u'Eşyayı geri aldınız.')
            conversation.request.stuff.status = 1
            conversation.request.status = 2
            conversation.request.returned_at = datetime.utcnow()
            db.session.commit()
        else:
            flash(u'Eşya zaten başkasına verilmiş.')

    wanted_stuff = StuffPhoto.query.filter(StuffPhoto.stuff_id == conversation.request.stuff_id).first()
    review_form.request_id.data = conversation.request_id
    return render_template(
        "conversation.html",
        user=current_user,
        wanted_stuff=wanted_stuff,
        form=form,
        action='Edit',
        conversation=conversation,
        review_form=review_form
    )
コード例 #17
0
ファイル: views.py プロジェクト: baa-archieve/esyakutuphanesi
def edit_stuff(stuff_id=None):
    stuff = Stuff.query.filter(Stuff.id == stuff_id).first()
    form = EditStuffForm()
    is_new = True
    is_wanted = bool(request.args.get('is_wanted'))
    # if is_wanted == 'true':
    #     form.is_wanted.data = 'True'

    address_choices = []
    if current_user.addresses:
        address_choices = [(address.id, address.detail)
                           for address in current_user.addresses]
    address_choices += [(-1, u'Yeni adres: Haritadan sağ tıklayarak seçebilirsiniz.')]
    #else:
    #    flash('Adres girmeniz gerekiyor')
    #    return redirect(url_for("new_address",
    #                            next=request.script_root+request.path))

    form.address.choices = address_choices

    if current_user.groups:
        group_choices = [(membership.group.id, membership.group.name)
                         for membership in current_user.groups]
        group_choices = [(-1, u'Herkese açık')] + group_choices
    else:
        group_choices = [(-1, u'Herkese açık')]

    form.group.choices = group_choices

    categories = Category.query.order_by(Category.name)
    category_choices = [(category.id, category.name)
                        for category in categories]
    form.category.choices = category_choices
    if stuff:
        category = Category.query. \
            filter(Category.id == stuff.category_id).first()
    else:
        category = categories[0]
    stuff_types = category.type_list
    stuff_type_choices = [(stuff_type.id, stuff_type.name)
                          for stuff_type in stuff_types]
    form.stuff_type.choices = stuff_type_choices

    if request.args.get('status'):
        status = int(request.args.get('status'))

        if status:
            Stuff.query.filter(Stuff.id == stuff_id).\
                update({Stuff.approved: status})
            db.session.commit()
            flash(u"Eşya kaldırıldı.")
            return redirect(url_for("my_stuff"))

    if request.method == 'POST':
        category = Category.query.\
            filter(Category.id == form.category.data).first()

        stuff_types = category.type_list
        stuff_type_choices = [(stuff_type.id, stuff_type.name)
                              for stuff_type in stuff_types]
        form.stuff_type.choices = stuff_type_choices

        if form.validate_on_submit():
            if form.address.data == -1:
                address = Address(
                    user=current_user,
                    lat=request.form.get('lat'),
                    lng=request.form.get('lng'),
                    detail=unicode(request.form.get('address_str')),
                    name="addr"
                )
                db.session.add(address)
            else:
                address = Address.query.\
                    filter(Address.id == form.address.data).\
                    first()

            if stuff:
                stuff.title = form.title.data
                stuff.detail = form.detail.data
                stuff.stuff_address = address
                stuff.category_id = form.category.data
                stuff.type_id = form.stuff_type.data
                #stuff.is_wanted = form.is_wanted.data == 'True'
                flash(u"Eşya güncellendi.")

            else:
                group_id = None if form.group.data == -1 else form.group.data
                stuff = Stuff(
                    title=form.title.data,
                    detail=form.detail.data,
                    stuff_address=address,
                    owner=current_user,
                    category_id=form.category.data,
                    type_id=form.stuff_type.data,
                    group_id=group_id,
                    is_wanted=form.is_wanted.data == 'True'
                )
                db.session.add(stuff)
                db.session.commit()

                photo_file = form.photo.data

                stuff_id = str(stuff.id)

                if photo_file:
                    file_ext = get_file_extension(photo_file.filename)
                    generated_name = str(uuid.uuid1()) + '.' + file_ext

                    folder_path = app.config['UPLOADS_FOLDER'] + '/stuff/' + stuff_id + '/'

                    new_folder = os.path.dirname(folder_path)
                    if not os.path.exists(new_folder):
                        os.makedirs(new_folder)

                    filepath = os.path.join(folder_path, generated_name)
                    photo_file.save(filepath)

                    file_new_name = 'stuff/' + stuff_id + '/' + generated_name

                # else:
                #     generated_name = str(form.category.data)+'.jpg'
                #     file_new_name = generated_name

                    new_photo = StuffPhoto(
                        owner=current_user,
                        filename=file_new_name,
                        stuff=stuff
                    )
                    db.session.add(new_photo)
                    db.session.commit()

                flash(u"Eşya kaydedildi.")

                msg_body = u"Eşya ekleyen: %s %s <br><br>Eşya başlık: %s<br> Eşya detay : %s" \
                           % (current_user.name, current_user.email, stuff.title, stuff.detail)
                msg = MailMessage(
                    body=msg_body,
                    html=msg_body,
                    subject=u"Yeni Eşya",
                    sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
                    recipients=["*****@*****.**"]
                )

                mail.send(msg)

            tags = form.tags.data.split(',')
            for t in tags:
                if t > '':
                    new_tag = Tag(stuff=stuff, name=t)
                    db.session.add(new_tag)

            db.session.commit()

            if stuff_id is None:
                return redirect(url_for('edit_stuff', stuff_id=stuff.id))

    if stuff:
        is_new = False

        if stuff.group_id > 0:
            group_choices = [(stuff.group_id, stuff.group.name)]
        else:
            group_choices = [(-1, u'Herkese açık')]

        form.group.choices = group_choices
        form.fill_form(stuff)

    return render_template(
        "edit_stuff.html",
        user=current_user,
        is_wanted=is_wanted,
        form=form,
        action='Edit',
        stuff=stuff,
        is_new=is_new
    )
コード例 #18
0
def send_email(subject, sender, recipients, text_body, html_body):
    msg = MailMessage(subject, sender=sender, recipients=recipients)
    msg.body = text_body
    msg.html = html_body
    Thread(target=send_async_email,
           args=(current_app._get_current_object(), msg)).start()
コード例 #19
0
def send_email(to, subject, template):
    msg = MailMessage(subject,
                      recipients=[to],
                      html=template,
                      sender=os.environ.get('MAIL_DEFAULT_SENDER'))
    mail.send(msg)
コード例 #20
0
def sendEmail(email_subject, recipients, email_text=None, email_html=None):
    msg = MailMessage(email_subject, recipients=recipients)
    msg.body = email_text
    msg.html = email_html
    Thread(target=send_async_email, args=(app, msg)).start()