def all_feedback():
    all_messages = messages.get_messages()
    user_id = session["user_id"]
    if users.is_admin(user_id):
        return render_template("/all_feedback.html", messages=all_messages)
    else:
        abort(403)
예제 #2
0
def show_messages():
    if not is_logged_in():
        return redirect(url_for('login'))
    else:
        username = session['username']
        messages = get_messages(username)
        return render_template('messages.html', messages=messages)
    '''To do: If the user is logged in, render the 'messages.html' template
예제 #3
0
def change_room(id):
    user_id = session.get("user")[0]
    message_list = messages.get_messages(id)
    room_list = rooms.get_rooms()
    user_room_list = rooms.get_user_rooms(user_id)
    return render_template("account.html",
                           message_list=message_list,
                           room_list=room_list,
                           room=id,
                           user_room_list=user_room_list)
예제 #4
0
def pull_minimal_messages(folder="INBOX", read_only=True, *args):
    connection = messages.connect()
    msgs = messages.get_messages(connection, folder, read_only, *args)
    connection.logout()
    if msgs:
        minimal_messages = [messages.MinimalMessage(m) for m in msgs]
        valid_minimal_messages = [m for m in minimal_messages if m.mail_type == "SALE"]
        print(len(minimal_messages), "messages pulled,", len(valid_minimal_messages), "valid.")
        return valid_minimal_messages
    else:
        print("0 messages to pull.")
예제 #5
0
def show_messages():
    '''To do: If the user is logged in, render the 'messages.html' template
	together with the user's messages ('inbox').
	If the user is NOT logged in, redirect to the login page.'''

    if is_logged_in():
        username = session['username']
        all_messages = messages.get_messages(username)
        return render_template('messages.html', messages=all_messages)
    else:
        return redirect(url_for('login'))
예제 #6
0
def test_default():
    messages.db.delete('messages', where='to_userid=2')
    msgid = messages.send_message(1, 2, 'test message')

    msg = messages.get_message(msgid)
    assert msg.content == 'test message'

    msgs = messages.get_messages(2)
    assert len(list(msgs)) == 1

    messages.read_message(msgid)
    msg = messages.get_message(msgid)
    assert msg.unread == 0
예제 #7
0
 def handle_get_messages(self, postdata):
     request = json.loads(postdata)
     print("header keys are ", self.headers.keys())
     token = self.headers.get("Authorization").strip("Bearer").strip()
     print("token is ", token)
     if sessions.authenticate(self.server.conn, request["recipient"],
                              token):
         limit = 100 if not "limit" in request else request["limit"]
         msg_list = messages.get_messages(self.server.conn,
                                          request["recipient"],
                                          request["start"], limit)
         self.send_response(200)
         self.end_headers()
         self.wfile.write(json.dumps(msg_list).encode('UTF-8'))
     else:
         self.send_error(401, "authentication error")
예제 #8
0
def index():
    user = session.get("user")
    if user != None:
        if (len(user) <= 3):
            session["user"] = [user[0], user[1]]
        room_id = 1
        message_list = messages.get_messages(room_id)
        room_list = rooms.get_rooms()
        room = room_list[room_id - 1]
        user_room_list = rooms.get_user_rooms(user[0])
        return render_template("account.html",
                               message_list=message_list,
                               room_list=room_list,
                               room=room,
                               user_room_list=user_room_list)
    else:
        return render_template("login.html")
예제 #9
0
def list_messages(topic_id):
    login_id = users.login_id()
    if login_id == 0:
        return render_template("index.html", login="******")
    else:
        user_rights = users.get_userrights(login_id)
        topic_name = topics.get_topicname(topic_id)
        area_id = topics.get_area_id(topic_id)
        area_name = areas.get_areaname(area_id)
        mlist = messages.get_messages(topic_id)
        return render_template("messages.html",
                               login_id=login_id,
                               user_rights=user_rights,
                               area_id=area_id,
                               area_name=area_name,
                               topic_id=topic_id,
                               topic_name=topic_name,
                               count=len(mlist),
                               messages=mlist)
예제 #10
0
def thread(id, m_id, e):
    allow = False
    list = messages.get_messages(id)
    starter = threads.get_thread(id)
    if starter[0][4] == 1:
        if users.logged():
            if users.private_access(id):
                allow = True
    elif starter[0][4] == 0:
        allow = True
    if users.logged() == True:
        is_admin = users.is_admin()
    else:
        is_admin = False
    return render_template("thread.html",
                           starter=starter,
                           messages=list,
                           id=id,
                           is_admin=is_admin,
                           message_id=m_id,
                           allow=allow,
                           error=error(e))
예제 #11
0
 def check_login(self, *args, **kwargs):
     d = {
         'SITENAME': SITENAME,
         'COMPANY_NAME': COMPANY_NAME,
         'YEAR': datetime.now().year,
         'CURTIME': datetime.now(),
         'GA_ID': GA_ID,
         'DEV': tools.on_dev_server(),
     }
     allow = False
     handled = False
     error_code = 0
     user = enterprise = None
     session = self.session
     messages.get_messages(self, d)
     if session.has_key('user'):
         user = session['user']
     if 'enterprise' in session:
         enterprise = session['enterprise']
     if not role:
         allow = True
     elif role == "user":
         if user:
             allow = True
     elif role == "admin":
         if user and user.is_admin():
             allow = True
     elif role == "api":
         status = None
         from models import User
         api_auth = self.request.get('auth')
         if not user:
             if api_auth == API_AUTH:
                 uid = self.request.get_range('uid')
                 pw = self.request.get('pw')
                 token = self.request.get('token')
                 if uid:
                     _user = User.get_by_id(uid)
                     if _user and pw and _user.validatePassword(pw):
                         user = _user  # Authorized client API
                     else:
                         error_code = 5  # Auth failed
                 else:
                     error_code = 4  # Malformed
             else:
                 error_code = 1  # Unauthorized
                 status = 401
         if user:
             d['user'] = user
             if not enterprise:
                 enterprise = user.enterprise
             self.user = d['user'] = user
             self.enterprise = d['enterprise'] = enterprise
         else:
             error_code = 3  # User not found
         if not error_code:
             kwargs['d'] = d
             handler_method(self, *args, **kwargs)
         else:
             message = messages.ERROR.LABELS.get(error_code)
             logging.error(message)
             self.json_out(success=False,
                           error=error_code,
                           message=message,
                           status=status)
         handled = True
     if not handled:
         if allow:
             d['user'] = user
             d['enterprise'] = enterprise
             d['logout_url'] = "/logout"  #users.create_logout_url("/logout")
             kwargs['d'] = d
             handler_method(self, *args, **kwargs)
         else:
             self.redirect("/login")
예제 #12
0
 def check_login(self, *args, **kwargs):
     d = {
         'SITENAME':SITENAME,
         'COMPANY_NAME': COMPANY_NAME,
         'YEAR':datetime.now().year,
         'CURTIME': datetime.now(),
         'GA_ID': GA_ID,
         'DEV': tools.on_dev_server(),
     }
     allow = False
     handled = False
     error_code = 0
     user = enterprise = None
     session = self.session
     messages.get_messages(self, d)
     if session.has_key('user'):
         user = session['user']
     if 'enterprise' in session:
         enterprise = session['enterprise']
     if not role:
         allow = True
     elif role == "user":
         if user:
             allow = True
     elif role == "admin":
         if user and user.is_admin():
             allow = True
     elif role == "api":
         status = None
         from models import User
         api_auth = self.request.get('auth')
         if not user:
             if api_auth == API_AUTH:
                 uid = self.request.get_range('uid')
                 pw = self.request.get('pw')
                 token = self.request.get('token')
                 if uid:
                     _user = User.get_by_id(uid)
                     if _user and pw and _user.validatePassword(pw):
                         user = _user # Authorized client API
                     else:
                         error_code = 5 # Auth failed
                 else:
                     error_code = 4 # Malformed
             else:
                 error_code = 1 # Unauthorized
                 status = 401
         if user:
             d['user'] = user
             if not enterprise:
                 enterprise = user.enterprise
             self.user = d['user'] = user
             self.enterprise = d['enterprise'] = enterprise
         else:
             error_code = 3 # User not found
         if not error_code:
             kwargs['d'] = d
             handler_method(self, *args, **kwargs)
         else:
             message = messages.ERROR.LABELS.get(error_code)
             logging.error(message)
             self.json_out(success=False, error=error_code, message=message, status=status)
         handled = True
     if not handled:
         if allow:
             d['user'] = user
             d['enterprise'] = enterprise
             d['logout_url'] = "/logout" #users.create_logout_url("/logout")
             kwargs['d'] = d
             handler_method(self, *args, **kwargs)
         else:
             self.redirect("/login")
예제 #13
0
def show_messages():
    if 'username' in session:
        msgs = messages.get_messages(session.get('username'))
        return render_template('messages.html', messages=msgs)
    else:
        return redirect(url_for('login'))
예제 #14
0
def show_messages():
    m = messages.get_messages()
    name = users.get_username()
    print(name)
    return render_template('show_messages.html', messages=m, name=name)
예제 #15
0
def get_messages(userID):
    return messages.get_messages(userID)