Пример #1
0
 def addNewUser(self,
                name: str,
                access: str = 'guest',
                state: str = 'home'):
     insertId = self.databaseInsert(
         tableName='users',
         query=
         'INSERT INTO :__table__ (username, accessLevel, state, lang) VALUES (:username, :accessLevel, :state, :lang)',
         values={
             'username': name.lower(),
             'accessLevel': access,
             'state': state,
             'lang': self.LanguageManager.activeLanguageAndCountryCode
         })
     if insertId > -1:
         self._users[name] = User({
             'username': name.title(),
             'accessLevel': access,
             'state': state,
             'lang': self.LanguageManager.activeLanguageAndCountryCode,
             'tts': '',
             'ttsLanguage': '',
             'ttsType': '',
             'ttsVoice': ''
         })
Пример #2
0
	def addNewUser(self, name: str, access: str = 'guest', state: str = 'home', pinCode: int = None):
		hashedPassword = self.getHashedPassword(pinCode or 1234)

		insertId = self.databaseInsert(
			tableName='users',
			values={
				'username'   : name.lower(),
				'accessLevel': access,
				'state'      : state,
				'pin'        : hashedPassword,
				'lang'       : self.LanguageManager.activeLanguageAndCountryCode
			})
		if insertId > -1:
			self._users[name] = User({
				'id'         : insertId,
				'username'   : name.title(),
				'accessLevel': access,
				'state'      : state,
				'pin'        : hashedPassword,
				'lang'       : self.LanguageManager.activeLanguageAndCountryCode,
				'tts'        : '',
				'ttsLanguage': '',
				'ttsType'    : '',
				'ttsVoice'   : '',
				'apiToken'   : ''
			})
 def _loadUsers(self):
     rows = self.databaseFetch(tableName='users',
                               query='SELECT * FROM :__table__',
                               method='all')
     for row in rows:
         user = User(row)
         self._users[user.name] = user
         self._validtokens[user.apiToken] = user
Пример #4
0
	def createApiToken(self, user: User, save: bool = True) -> str:
		token = jwt.encode({'user': user.name, 'birth': time()}, 'projectalice', algorithm='HS256')
		self._validtokens[token] = user

		if save:
			user.apiToken = token
			self.DatabaseManager.update(
				tableName='users',
				callerName=self.name,
				values={'apiToken': token},
				row=('username', user.name))

		return token
Пример #5
0
 def _loadUsers(self):
     rows = self.databaseFetch(tableName='users',
                               query='SELECT * FROM :__table__',
                               method='all')
     for row in rows:
         self._users[row['username']] = User(row)
Пример #6
0
	def checkPinCode(self, user: User, password: str):
		return user in self._users.values() and user.checkPassword(password)