Exemplo n.º 1
0
def _process_valid_message(body, number):
    from_name = get_name_from_number(number)
    from_phone = number
    message_body = parse.get_message_body(body)
    to_name = parse.get_message_to(body)
    # TODO: not random ID
    guess_id = str(random.randint(1,99999))  # we sms g_id out so people can guess!

    # if we know tagged user, we will forward the text body
    if user_exists(user_name):
        to_phone = get_number_from_name(user_name)
        create_message(from_name, from_phone, message_body, to_name, to_phone, guess_id)        
        send_message_and_id(message_body, guess_id, to_number) # send the text! 
    # user doesn't exist but we save the message body anyway
    else:
        to_phone = ''
        create_message(from_name, from_phone, message_body, to_name, to_phone, guess_id)
Exemplo n.º 2
0
def sendto():
    form = SendToMessageForm(request.form)
    if request.method == "POST" and form.validate():
        receiver = User.query.get_by_username(form.data["recv"].strip())
        if receiver:
            msg = create_message(
                sender_id=current_user.id, recv=receiver, title=form.data["title"], content=form.data["content"]
            )
            return render_template("send_ok.html", msg=msg)
        form.recv.errors.append(u"用户名不存在!")
    return render_template("send_message.html", form=form, actionurl=url_for(".sendto"))
Exemplo n.º 3
0
def send(recv):
    form = SendMessageForm(request.form)
    _recv = urllib.unquote(recv)
    receiver = User.query.filter(User.username == _recv.strip()).first()
    if not receiver:
        flash(u"未知用户%s" % _recv)
        return redirect(url_for(".sendto") or "/")
    if request.method == "POST" and form.validate():
        msg = create_message(
            sender_id=current_user.id, recv=receiver, title=form.data["title"], content=form.data["content"]
        )
        return render_template("send_ok.html", msg=msg)
    return render_template("send_message.html", form=form, actionurl=url_for(".send", recv=recv))
Exemplo n.º 4
0
def sendto():
    form = SendToMessageForm(request.form)
    if request.method == 'POST' and form.validate():
        receiver = User.query.get_by_username(form.data['recv'].strip())
        if receiver:
            msg = create_message(sender_id=current_user.id,
                                 recv=receiver,
                                 title=form.data['title'],
                                 content=form.data['content'])
            return render_template("send_ok.html", msg=msg)
        form.recv.errors.append(u'用户名不存在!')
    return render_template("send_message.html",
                           form=form,
                           actionurl=url_for(".sendto"))
Exemplo n.º 5
0
def send(recv):
    form = SendMessageForm(request.form)
    _recv = urllib.unquote(recv)
    receiver = User.query.filter(User.username == _recv.strip()).first()
    if not receiver:
        flash(u'未知用户%s' % _recv)
        return redirect(url_for(".sendto") or '/')
    if request.method == 'POST' and form.validate():
        msg = create_message(sender_id=current_user.id,
                             recv=receiver,
                             title=form.data['title'],
                             content=form.data['content'])
        return render_template("send_ok.html", msg=msg)
    return render_template("send_message.html",
                           form=form,
                           actionurl=url_for(".send", recv=recv))