Esempio n. 1
0
 def __init__(self, identity, service):
     UserResourceBase.__init__(self, identity, service)
     self.profileService = IUserProfileService(service)
     self.gomeeService = IGomeeService(service)
Esempio n. 2
0
class UserProfileResource(UserResourceBase):
    
    implements(interface.IUserProfileResource)
    
    def __init__(self, identity, service):
        UserResourceBase.__init__(self, identity, service)
        self.profileService = IUserProfileService(service)
        self.gomeeService = IGomeeService(service)
        
    def user_check_GET(self, authUser, user, request):
        return defer.succeed(authUser.login != "root")
    
    def user_auth_GET(self, authUser, user, request):
        
        def get_profile(user):
            return self.profileService.get_user_profile(user)
        
        def get_profile_gomees(profile):
            
            def complete(gomees):
                return defer.succeed((profile, gomees))
            
            return self.gomeeService.get_profile_gomees(user).addCallback(complete)
            
        def complete((profile, gomees)):
            return defer.succeed({
                                  "id" : profile.id,
                                  "firstName" : profile.firstName,
                                  "lastName" : profile.lastName,
                                  "email" : profile.email,
                                  "gomees" : map(lambda gm: {
                                                            "id" : gm.id,
                                                            "owner" : gm.owner.id,
                                                            "lat" : gm.lat,
                                                            "lng" : gm.lng,
                                                            "caption" : gm.caption,
                                                            "address" : gm.address,
                                                            "description" : gm.description,
                                                            "type" : gm.type
                                                            }, gomees)
                                  })
        
        d = defer.Deferred()
        
        d.addCallback(get_profile)
        d.addCallback(get_profile_gomees)
        d.addCallback(complete)
        
        reactor.callLater(0, d.callback, user)
        return d
    
    def user_check_PUT(self, authUser, user, request):
        return defer.succeed(authUser.login != "root" and authUser.id == user.id)
    
    def user_auth_PUT(self, authUser, user, request):
        
        def update_profile(_):
            profile = json.loads(request.content.read())
            return self.profileService.update_user_profile(user, profile)
            
        def complete(profile):
            return defer.succeed({
                                  "id" : profile.id,
                                  "firstName" : profile.firstName,
                                  "lastName" : profile.lastName,
                                  "email" : profile.email
                                  })
        
        d = defer.Deferred()
        
        d.addCallback(update_profile)
        d.addCallback(complete)
        
        reactor.callLater(0, d.callback, None)
        return d