예제 #1
0
    def loginWithoutPwd(self):
        appUserHelper = ClassHelper('develop', "AppUser")
        appUser = appUserHelper.find_one({'username': self['username']})
        obj = copy.deepcopy(self.dirty)
        if appUser == None:
            # 涉及到不同的应用,所以AppUser不存储bundleId和package
            if obj.has_key('bundleId'):
                del (obj['bundleId'])
            elif obj.has_key('package'):
                del (obj['package'])
            appUser = MeObject('develop', 'AppUser', obj)
            appUser.save()
        # 如果用户发生系统更新
        else:
            appUser = MeObject('develop', 'AppUser', appUser)
            if obj['system'] != appUser['system']:
                appUser['system'] = obj['system']
                appUser.save()

        userHelper = ClassHelper(self.appDb, 'User')
        user = userHelper.find_one({'username': obj['username']})
        if user == None or (not user.has_key('appUserId')):
            self['appUserId'] = appUser.objectId
            self.save()
        else:
            self.copySelf(user)
            self.dirty.clear()
예제 #2
0
    def readAccess(self, user):
        if self.has_key('*') and self['*'].has_key(
                'read') and self['*']['read']:
            return True
        # 如果user不为*,那么必须有为MeUser
        # if not (type(user) is MeUser):
        #    return False

        # 如果明确指定了某个用户的权限,则不再检查Role
        if self.has_key(user.objectId) and self[user.objectId].has_key(
                'read') and self[user.objectId]['read']:
            return True
        # 检查role

        for k in self:
            if k.startswith('role:'):
                roleQuery = ClassHelper('Role')
                role = roleQuery.find_one({
                    'name': k[5:],
                    'user': user.objectId
                })
                # 如果有一个角色有读权限,那么就有读权限
                if role is not None and self[k].has_key(
                        'read') and self[k]['read']:
                    return True
        return False
예제 #3
0
 def fetch(self):
     roleClass = ClassHelper(self.className)
     role = roleClass.find_one({'name': self['name']})
     if role == None:
         return False
     self.dirty.clear()
     self.objectId = obj['_id']
     for k in obj:
         dict.__setitem__(self, k, obj[k])
     return True
예제 #4
0
 def login(self, username, password):
     userHelper = ClassHelper(self.appDb, self.className)
     user = userHelper.find_one({
         'username': username,
         'password': password
     })
     if user != None:
         del (user['password'])
         self.copySelf(user)
         return True
     else:
         return False
예제 #5
0
	def signUp(self):
		if self['username']==None or self['password']==None:
			raise ERR_NOPARA
		if len(self['username'])<=6 or len(self['password'])<=6:
			raise ERR_PARA

		helper = ClassHelper(self.appDb, self.className)
		print self;
		if(helper.find_one({'username': self['username']})):
			raise ERR_USER_TAKEN
		print 'xxxxxxxxxxxxxxyyyyyyyyy'
		return self.save()