示例#1
0
 async def updateUserName(self, id, userName):
     r = await self.collection.update_one(
         {UserManager.UserID: id}, {'$set': {
             UserManager.Name: userName
         }})
     if r.modified_count == 0:
         raise IFException('Failed to update UserName.')
示例#2
0
 async def updateAvatar(self, id, avatar):
     r = await self.collection.update_one(
         {UserManager.UserID: id}, {'$set': {
             UserManager.Avatar: avatar
         }})
     if r.modified_count == 0:
         raise IFException('Failed to update Avatar.')
示例#3
0
 async def createUser(self,
                      id,
                      name=None,
                      password=None,
                      privilege=[],
                      avatar=None):
     if await self.hasUser(id):
         raise IFException('User [{}] exists.'.format(id))
     if name == None:
         name = id.split('@')[0]
     if password == None:
         password = self.__randomPassword()
     saltA = self.__randomSalt()
     saltB = self.__randomSalt()
     hashedPassword = self.__hashPassword(password, [saltA, saltB])
     privilege = list(set(privilege))
     await self.collection.insert_one({
         UserManager.UserID: id,
         UserManager.Name: name,
         UserManager.SaltA: saltA,
         UserManager.SaltB: saltB,
         UserManager.HashedPassword: hashedPassword,
         UserManager.Privilege: privilege,
         UserManager.Avatar: avatar,
     })
示例#4
0
 async def updateDescription(self, launcherName, description):
     r = await self.collection.update_one(
         {IFLocal.LauncherName: launcherName},
         {'$set': {
             IFLocal.Description: description
         }})
     if r.modified_count == 0:
         raise IFException('Failed to update Description.')
示例#5
0
 async def updateBrief(self, launcherName, brief):
     r = await self.collection.update_one(
         {IFLocal.LauncherName: launcherName},
         {'$set': {
             IFLocal.Brief: brief
         }})
     if r.modified_count == 0:
         raise IFException('Failed to update Brief.')
示例#6
0
 async def removePrivilege(self, id, onePrivilege):
     P = await self.getPrivilege(id)
     if P.__contains__(onePrivilege):
         P.remove(onePrivilege)
         await self.updatePrivilege(id, P)
     else:
         raise IFException('User [{}] does not has provilege [{}].'.format(
             id, onePrivilege))
示例#7
0
 async def getCommands(self, launcherName):
     commands = await self.collection.find_one(
         {IFLocal.LauncherName: launcherName}, {
             IFLocal.Commands: 1,
             '_id': 0
         })
     if commands == None:
         raise IFException('Launcher [{}] not exist.'.format(launcherName))
     return commands[IFLocal.Commands]
示例#8
0
 async def getDescription(self, launcherName):
     description = await self.collection.find_one(
         {IFLocal.LauncherName: launcherName}, {
             IFLocal.Description: 1,
             '_id': 0
         })
     if description == None:
         raise IFException('Launcher [{}] not exist.'.format(launcherName))
     return description[IFLocal.Description]
示例#9
0
 async def getBrief(self, launcherName):
     brief = await self.collection.find_one(
         {IFLocal.LauncherName: launcherName}, {
             IFLocal.Brief: 1,
             '_id': 0
         })
     if brief == None:
         raise IFException('Launcher [{}] not exist.'.format(launcherName))
     return brief[IFLocal.Brief]
示例#10
0
 async def createLauncher(self, launcherName, brief=None, description=None):
     if await self.hasLauncher(launcherName):
         raise IFException('Launcher [{}] exists.'.format(launcherName))
     await self.collection.insert_one({
         IFLocal.LauncherName: launcherName,
         IFLocal.Brief: brief,
         IFLocal.Description: description,
         IFLocal.Commands: {}
     })
示例#11
0
 async def updatePrivilege(self, id, privilege):
     privilege = list(set(privilege))
     r = await self.collection.update_one(
         {UserManager.UserID: id},
         {'$set': {
             UserManager.Privilege: privilege
         }})
     if r.modified_count == 0:
         raise IFException('Failed to clear Privilege.')
示例#12
0
 async def getBriefAndDescription(self, launcherName):
     bad = await self.collection.find_one(
         {IFLocal.LauncherName: launcherName}, {
             IFLocal.Brief: 1,
             IFLocal.Description: 1,
             '_id': 0
         })
     if bad == None:
         raise IFException('Launcher [{}] not exist.'.format(launcherName))
     return [bad[IFLocal.Brief], bad[IFLocal.Description]]
示例#13
0
 async def getUserInfo(self, id):
     info = await self.collection.find_one({UserManager.UserID: id}, {
         UserManager.Name: 1,
         UserManager.Avatar: 1,
         UserManager.Privilege: 1,
         '_id': 0
     })
     if info == None:
         raise IFException('User [{}] not exist.'.format(id))
     return info
示例#14
0
 async def __getHashedPassword(self, id):
     info = await self.collection.find_one({UserManager.UserID: id}, {
         UserManager.SaltA: 1,
         UserManager.SaltB: 1,
         UserManager.HashedPassword: 1,
         '_id': 0
     })
     if info == None:
         raise IFException('User [{}] not exist.'.format(id))
     return info
示例#15
0
 async def updatePassword(self, id, pwd):
     saltA = self.__randomSalt()
     saltB = self.__randomSalt()
     hashedPassword = self.__hashPassword(pwd, [saltA, saltB])
     r = await self.collection.update_one({UserManager.UserID: id}, {
         '$set': {
             UserManager.SaltA: saltA,
             UserManager.SaltB: saltB,
             UserManager.HashedPassword: hashedPassword,
         }
     })
     if r.modified_count == 0:
         raise IFException('Failed to update Password.')