Esempio n. 1
0
def password_reset_form():
    email_server = EmailServer(TEMPLATES_DIR)

    if email_server.is_connected:
        if request.method == 'POST':
            email = request.form.get('email')

            if not email:
                flash('You have to specify an email address', 'danger')
            else:
                user = User.get(email=email)

                if user:
                    token = password_reset_token(user)
                    reset_url = urljoin(fame_config.fame_url, url_for('auth.password_reset', token=token))

                    msg = email_server.new_message_from_template("Reset your FAME account's password.", 'mail_reset_password.html', {'user': user, 'url': reset_url})
                    msg.send([user['email']])

                flash('A password reset link was sent.')
                return redirect('/login')

        return render_template('password_reset_form.html')
    else:
        flash('Functionnality unavailable. Contact your administrator', 'danger')
        return redirect('/login')
Esempio n. 2
0
 def notify_new_comment(self, analysis_id, commentator_id, comment):
     commentator = store.users.find_one({'_id': commentator_id})
     analysis = store.analysis.find_one({'_id': ObjectId(analysis_id)})
     analyst_id = analysis['analyst']
     recipients = set()
     # First let's add submiter analyst and check if he is not commentator
     if commentator_id != analyst_id:
         analyst = store.users.find_one({'_id': analysis['analyst']})
         recipients.add(analyst['email'])
     # iter on commentators and add them as recipient
     for comment in self['comments']:
         if comment['analyst'] not in [analyst_id, commentator_id]:
             recipient = store.users.find_one({'_id': comment['analyst']})
             recipients.add(recipient['email'])
     if len(recipients):
         config = Config.get(name="email").get_values()
         analysis_url = "{0}/analyses/{1}".format(fame_config.fame_url,
                                                  analysis_id)
         body = notification_body_tpl.format(commentator['name'],
                                             analysis_url,
                                             comment['comment'])
         email_server = EmailServer()
         if email_server.is_connected:
             msg = email_server.new_message(
                 "[FAME] New comment on analysis", body)
             msg.send(list(recipients))
Esempio n. 3
0
def create_user(user):
    user.save()

    user.generate_avatar()

    token = password_reset_token(user)
    reset_url = urljoin(fame_config.fame_url,
                        url_for('auth.password_reset', token=token))
    email_server = EmailServer(TEMPLATES_DIR)

    if email_server.is_connected:
        msg = email_server.new_message_from_template(
            "Define your FAME account's password.", 'mail_user_creation.html',
            {
                'user': user,
                'url': reset_url
            })
        msg.send([user['email']])
    else:
        if email_server.is_configured:
            error = "Could not connect to SMTP Server."
        else:
            error = "SMTP Server not properly configured."

        error += " The new user should visit '{}' in the next 24 hours in order to define his password".format(
            reset_url)
        flash(error, 'persistent')

    return True
Esempio n. 4
0
    def sendmail(self, attachment, analysis):

        server = EmailServer()

        msg = server.new_message(self.subject.format(analysis['_id']),
                                 self.mailbody.format(analysis['_id']))
        msg.add_attachment(attachment)
        msg.send([self.emails])

        print(">>> Report {0} sent to {1}").format(analysis['_id'],
                                                   [self.emails])
Esempio n. 5
0
    def submit(self, file):
        archive_name = "sample_{}.zip".format(uuid4())
        archive_file = path.join(fame_config.temp_path, archive_name)
        subprocess.call([
            "7z", "a", "-tzip", "-p{}".format(self.password), archive_file,
            file
        ])

        server = EmailServer()
        msg = server.new_message(self.mail_subject,
                                 self.mail_template.format(self.password))
        msg.add_attachment(archive_file, archive_name)
        msg.send([self.mail_submission])

        remove(archive_file)

        return True