예제 #1
0
def recover(request):
    xmldoc = dom.parse(dazhu.settings.BASE_DIR + '/message.xml')
    itemlist = xmldoc.getElementsByTagName('blog')
    result = "over"
    tools.debug("start import")
    for item in itemlist:
        tempguid = item.attributes['guid'].value
        tools.debug("current guid is ", tempguid)
        try:
            tools.debug(tempguid, "tempguid is exist1")
            temp_message = Message.objects.get(guid=tempguid)
            tools.debug(tempguid, "tempguid is exist2")
        except:
            tools.debug(tempguid, "tempguid is not exist")
            result += tempguid + " imported <br>"
            temp_message = Message()
            temp_message.guid = item.attributes["guid"].value
            temp_message.author = item.attributes["author"].value
            tools.debug("author ", temp_message.author)

            temp_message.timestamp = datetime.strptime(
                item.attributes["timestamp"].value, "%Y%m%d %H%M%S")

            bodynode = item.getElementsByTagName('value')[0]
            temp_message.body = bodynode.firstChild.nodeValue
            tools.debug("value ", temp_message.body)

            temp_message.save()

    return HttpResponse(result)
예제 #2
0
def process_messages(limit):
    count = 0
    date_parser = dateutil.parser.parser()
    omsgs = OriginalMessage.objects()
    if limit:
        omsgs = omsgs.limit(limit)
    for raw_count, om in enumerate(omsgs):
        m = Message()
        m.body = om.body
        m.subFolder = om.subFolder
        m.filename = om.filename
        m.headers = om.headers
        m.subject = om.get_subject()
        m.date = date_parser.parse(om.get_date())
        m.to = [x for x in om.get_to() if "enron.com" in x]
        if not m.to:
            # Skip if none of the "To's" are to enron employees
            continue
        m.from_str = om.get_from()
        if "enron.com" not in m.from_str:
            # Skip if this email was not from an enron employee
            continue
        try:
            m.save()
        except Exception, e:
            print "Error trying to save: %s" % (m)
            print e
        count+=1
        if count % 5000 == 0:
            print "Processing %s raw messages, filtered to %s" % (raw_count, count)
예제 #3
0
def post(connection_id):
    get = request.json.get

    body = get("body")

    connection = Connection.query.filter(
        and_(
            or_(
                Connection.requestor_id == current_user.id,
                Connection.approver_id == current_user.id),
            Connection.id == int(connection_id))).first()

    # handle bad requests for non-member users
    if not connection:
        raise BadRequest(response={
            "notification": {
                "body": "You cannot send a message to this user.",
                "type": "popup_notifications",
                "delay": 3,
            },
        })

    other_user = connection.other_user(current_user.id)
    recipient_id = other_user.id

    message = Message()
    message.connection_id = int(connection_id)
    message.sender_id = current_user.id
    message.recipient_id = recipient_id
    message.body = body

    notification = Notification()
    notification.recipient_id = recipient_id
    notification.type = "message"
    notification.body = body,
    notification.action = f"/#/connections/{connection.id}"

    db.session.add(message)
    db.session.add(notification)
    db.session.commit()

    # emit to user's message room
    socketio.emit("deliver_message", {
        "data": message.to_dict(),
        "notification": {
            "body": {
                "sender_name": current_user.first_name,
                "sender_id": current_user.id,
                "message": body,
            },
            "action": f"/#/connections/{connection_id}/messages",
            "type": "message_notifications",
            "delay": 3,
        },
    }, to=f"message_{recipient_id}")

    return jsonify({
        "data": message.to_dict(),
    }), 201
예제 #4
0
 def send_mail(self, instance=None):
     token = uuid.uuid4().hex
     data = {"token": token, "user": instance.id}
     db.session.add(PasswordReset(**data))
     db.session.commit()
     from flask_mail import Message
     msg = Message("Reset Password", recipients=[instance.email, ])
     msg.body = "Click the following link to reset your password"
     msg.html = "<p>Click <a href='http://127.0.0.1:5000/api/v1/users/password-reset/?email="+instance.email+"&&token="+token+"'>here</a> " \
                "to reset your password</p>"
     mail.send(msg)
예제 #5
0
    def post(self, request, pid):

        commentUser = websecu.xss_white_list(request.POST['user'])
        message = websecu.xss_white_list(request.POST['message'])
        tools.debug("message:", pid, commentUser, message,
                    request.POST['message'])

        insert_message = Message()
        insert_message.body = message
        insert_message.author = commentUser
        insert_message.timestamp = datetime.now()
        insert_message.save()

        send_msg(rid=0, sid=0, title=u"新的留言", content=u"内容:{}".format(message))

        return redirect("/message/")
def sent_to(username, password, toUserName, bodyToUser, creation_date):
    print("SEND A MESSAGE TO A GIVEN USER")
    c = get_connection()
    cursor = c.cursor()
    u = User()
    u.set_password(password, "1")
    if u.get_item_by_login(username, cursor) and u.get_user_by_password(
            username, cursor)[1] == u.hashed_password and u.get_item_by_login(
                toUserName, cursor)[0]:
        m = Message()
        m.body = bodyToUser
        m.creation_date = creation_date
        m.from_user = u.get_user_by_password(username, cursor)[0]
        m.to_user = u.get_user_by_password(toUserName, cursor)[0]
        m.save_message(cursor)
        c.close()
    else:
        print(
            "Nie ma takiego usera lub podałeś złe hasło/login lub nie ma usera do ktorego chcesz cos wyslac"
        )
예제 #7
0
파일: views.py 프로젝트: Jovan3211/naucilus
def forgotpassword():

    if request.method == 'POST' and request.form['username']:
        try:
            userp = User.select().where(User.username==request.form['username']).get()
            user = User(
                username=request.form['username'],
                email=request.form['email'],
                password=userp.password
            )
            msg = Message("Naucilus Support",
                  sender="*****@*****.**",
                  recipients=[user.email])
            msg.body = "Hello, " + user.username + "! Your password is: " + userp.password  
            mail = Mail(app)
            mail.send(msg)
            return redirect(url_for('index'))


        except User.DoesNotExist:
            flash('That username does not exist')
    
    return render_template('forgotpassword.html')