예제 #1
0
 def post (self):
     """ Create a Sheet with given JSON """
     user = Auth.getUser()
     
     new_sheet = Sheet(
                     name = request.json['name'],
                     description = request.json['description'],
                     #location = request.json.get('location',None),
                     public = request.json.get('public', True),
                     links = request.json.get('links', []),
                     color = request.json.get('color', None),
                     tags = request.json.get('tags', None)
                     )
     
     new_sheet.created_by = user
     new_sheet.alive = True
     new_sheet.save()
     # connect the user to the new sheet
     user_sheet = UserSheet(name=new_sheet.name,
                          user=user, 
                          sheet=new_sheet,
                          alive=True
                          )
     
     user_sheet.save()
     return jsonify(ok=True, objects=[ new_sheet.to_json() ]), 201
예제 #2
0
 def profile(self):
     ''' get the profile of the currently authenticated user '''
     try:
         user = Auth.getUser()  # @Todo rename this to getLoggedInUser()
         return jsonify(ok=True, objects=[user.to_json()]), 200
     except:
         # @Todo
         pass
     abort(500)
예제 #3
0
 def profile(self):
     ''' get the profile of the currently authenticated user '''
     try:
         user = Auth.getUser() # @Todo rename this to getLoggedInUser()
         return jsonify(ok=True, objects=[user.to_json()]), 200
     except:
         # @Todo
         pass
     abort(500)
예제 #4
0
    def get (self, id):
        """ Get Sheet document with given id if user is allowed """
        user = Auth.getUser()
        #try:
        sheet = Sheet.objects.get(id=id)

        #check if the user has privileges to view this sheet
        user_sheet = UserSheet.objects.get(sheet=sheet, user=user, alive=True)
        if (user_sheet) :
            return jsonify(ok=True, objects=[user_sheet.to_json()]), 200
예제 #5
0
    def get(self, id):
        """ Get Sheet document with given id if user is allowed """
        user = Auth.getUser()
        #try:
        sheet = Sheet.objects.get(id=id)

        #check if the user has privileges to view this sheet
        user_sheet = UserSheet.objects.get(sheet=sheet, user=user, alive=True)
        if (user_sheet):
            return jsonify(ok=True, objects=[user_sheet.to_json()]), 200
예제 #6
0
 def put(self, id):
     """ Update a user's details """
     user = User.objects.get_or_404(id=id)
     #prevent non authorised users from editing other user's details
     _currentUser = Auth.getUser()
     
     if _currentUser != user :
         abort(401)
         
     if 'user' in request.json:
         # save the old details in history
         user.history.append( user )
         
         user.name = request.json['user']['name']
         user.description = request.json['user']['description']
         user.location = request.json['user']['location']
         user.phone = request.json['user']['phone']
         user.links = request.json['user'].get('links', [])
         user.alive = True
         user.save()
         
         # create an Auth account if it doesn't exist or
         # update the password if it does
         if 'password' in request.json['user'] :
             try:
                 auth = Auth.objects.get(user=user)
             except(Exception):
                 auth = Auth(user=user,
                             password=request.json['user']['password'],
                             alive=True
                             )
             
             auth.password = Auth.hash_password(user.email, auth.password)
             
             auth.save()
         
         return jsonify(ok=True),200
     abort(401)
예제 #7
0
    def put(self, id):
        """ Update a user's details """
        user = User.objects.get_or_404(id=id)
        #prevent non authorised users from editing other user's details
        _currentUser = Auth.getUser()

        if _currentUser != user:
            abort(401)

        if 'user' in request.json:
            # save the old details in history
            user.history.append(user)

            user.name = request.json['user']['name']
            user.description = request.json['user']['description']
            user.location = request.json['user']['location']
            user.phone = request.json['user']['phone']
            user.links = request.json['user'].get('links', [])
            user.alive = True
            user.save()

            # create an Auth account if it doesn't exist or
            # update the password if it does
            if 'password' in request.json['user']:
                try:
                    auth = Auth.objects.get(user=user)
                except (Exception):
                    auth = Auth(user=user,
                                password=request.json['user']['password'],
                                alive=True)

                auth.password = Auth.hash_password(user.email, auth.password)

                auth.save()

            return jsonify(ok=True), 200
        abort(401)
예제 #8
0
    def post(self):
        """ Create a Sheet with given JSON """
        user = Auth.getUser()

        new_sheet = Sheet(
            name=request.json['name'],
            description=request.json['description'],
            #location = request.json.get('location',None),
            public=request.json.get('public', True),
            links=request.json.get('links', []),
            color=request.json.get('color', None),
            tags=request.json.get('tags', None))

        new_sheet.created_by = user
        new_sheet.alive = True
        new_sheet.save()
        # connect the user to the new sheet
        user_sheet = UserSheet(name=new_sheet.name,
                               user=user,
                               sheet=new_sheet,
                               alive=True)

        user_sheet.save()
        return jsonify(ok=True, objects=[new_sheet.to_json()]), 201