Example #1
0
def dict_group(group):
    with session_scope() as s:
        return {
            'id': group.id,
            'book_list': group.book_list(s),
            'user_list': group.user_list(s)
        }
Example #2
0
 def profile(self):
     cherrypy.response.status = 200
     with session_scope() as s:
         user = User.query_by_id(s, cherrypy.request.user_id)
         cherrypy.session["variables"] = {
             "user_name": user.name,
             "user_email": user.email
         }
Example #3
0
def dict_user(user):
    # TODO: add list of groups the user is in to the json
    with session_scope() as s:
        return {
            'id': user.id,
            'email': user.email,
            'latitude': user.latitude,
            'longitude': user.longitude,
            'bio': user.bio,
            'groups': user.groups
        }
Example #4
0
 def index(self, login = None, email = None, password = None, next = None):
     if email and password:
         with session_scope() as s:
             user = User.query_by_email(s, email)
             if user:
                 cherrypy.session["user_id"] = user.id
         next = cherrypy.session["next"] if "next" in cherrypy.session else "/"
         raise cherrypy.HTTPRedirect(next)
     else:
         cherrypy.session["next"] = next
         return cherrypy.lib.static.serve_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../static/login/index.html"))
Example #5
0
    def _fetch(self):
        login_url = "/login?next=%s" % urllib.parse.quote(cherrypy.url())
        if 'user_id' not in cherrypy.session:  # not authenticated
            cherrypy.lib.cptools.redirect(login_url)

        with session_scope() as s:
            user = User.query_by_id(s, cherrypy.session['user_id'])
            if user:
                cherrypy.request.user_id = user.id  # store the user for the request
            else:  # invalid user ID
                cherrypy.lib.cptools.redirect(login_url)
Example #6
0
 def _fetch(self):
     login_url = "/login?next=%s" % urllib.parse.quote(cherrypy.url())
     if 'user_id' not in cherrypy.session: # not authenticated
         cherrypy.lib.cptools.redirect(login_url)
     
     with session_scope() as s:
         user = User.query_by_id(s, cherrypy.session['user_id'])
         if user:
             cherrypy.request.user_id = user.id # store the user for the request
         else: # invalid user ID
             cherrypy.lib.cptools.redirect(login_url)
Example #7
0
 def create(self, name, password, email, latitude, longitude, bio):
     user = User(name, password, email, latitude, longitude, bio)
     with session_scope() as s:
         s.add(user)
         return "OK"
     return "FAIL"
Example #8
0
 def index(self, filter = ""):
     with session_scope() as s:
         return json.dumps(dict_user(user) for user in [User.list(s, filter)])
Example #9
0
 def groups(self, filter=""):
     with session_scope() as s:
         return json.dumps(Group.list(s, filter))
Example #10
0
 def delete(self):
     user = cherrypy.request.user
     with session_scope() as s:
         s.delete(user)
         return "OK"
     return "FAIL"
Example #11
0
 def index(self, filter=""):
     with session_scope() as s:
         return json.dumps(
             [dict_group(group) for group in Group.list(s, filter)])
Example #12
0
 def index(self, filter = ""):
     with session_scope() as s:
         return json.dumps([dict_group(group) for group in Group.list(s, filter)])
Example #13
0
 def index(self, filter = ""):
     with session_scope() as s:
         return json.dumps([dict_book(book) for book in Book.list(s, filter)])
Example #14
0
 def groups(self, filter = ""):
     with session_scope() as s:
         return json.dumps(Group.list(s, filter))
Example #15
0
 def profile(self):
     cherrypy.response.status = 200
     with session_scope() as s:
         user = User.query_by_id(s, cherrypy.request.user_id)
         cherrypy.session["variables"] = {"user_name": user.name, "user_email": user.email}
Example #16
0
 def create(self, title, isbn, author):
     book = Book(title, isbn, author)
     with session_scope() as s:
         s.add(book)
         return "OK"
     return "FAIL"
Example #17
0
 def index(self, filter=""):
     with session_scope() as s:
         return json.dumps(
             [dict_book(book) for book in Book.list(s, filter)])
Example #18
0
 def create(self, title, password):
     group = Group(title, password)
     with session_scope() as s:
         s.add(group)
         return "OK"
     return "FAIL"
Example #19
0
 def delete(self):
     user = cherrypy.request.user
     with session_scope() as s:
         s.delete(user)
         return "OK"
     return "FAIL"
Example #20
0
 def leave(self, group_id):
     user = cherrypy.request.user
     group = Group.query_by_id(group_id)
     with session_scope() as s:
         user.leave_group(s, group)
Example #21
0
 def create(self, name, password, email, latitude, longitude, bio):
     user = User(name, password, email, latitude, longitude, bio)
     with session_scope() as s:
         s.add(user)
         return "OK"
     return "FAIL"
Example #22
0
 def create(self, title, password):
     group = Group(title, password)
     with session_scope() as s:
         s.add(group)
         return "OK"
     return "FAIL"
Example #23
0
 def leave(self, group_id):
     user = cherrypy.request.user
     group = Group.query_by_id(group_id)
     with session_scope() as s:
         user.leave_group(s, group)
Example #24
0
 def create(self, title, isbn, author):
     book = Book(title, isbn, author)
     with session_scope() as s:
         s.add(book)
         return "OK"
     return "FAIL"
Example #25
0
 def index(self, filter=""):
     with session_scope() as s:
         return json.dumps(
             dict_user(user) for user in [User.list(s, filter)])