def _doPost(self, dataObject): if "email" in dataObject and "password" in dataObject: username = dataObject['email'] password = dataObject['password'] try: umapper = UserMapper() selectedUser = umapper.getUserByEmail(username) except mdb.DatabaseError, e: raise ServerError("Unable to search the user database (%s: %s)" % e.args[0], e.args[1]) # check we have a result if selectedUser is None: raise NotFound("We have no record of a user with the username %s" % username) # check password is correct return corresponding key if not checkHash(password, selectedUser.getPassword()): raise Unauthorised("Failed to login with that username and password") # get API token from the database and return it try: rdata = {} ATM_ = ApitokenMapper() rdata["apitoken"] = ATM_.findTokenByUserId(selectedUser.getId()).getToken() rdata["user"] = selectedUser.dict(1) return self._response(rdata, CODE.CREATED) except mdb.DatabaseError, e: raise ServerError("Unable to get API key from the database (%s: %s)" % e.args[0], e.args[1])
def _doPost(self, dataObject): if "email" in dataObject and "password" in dataObject: UM = UserMapper() ATM = ApitokenMapper() # Build user and token objects user = User() if not checkEmail(dataObject["email"]): raise BadRequest("The e-mail supplied was invalid.") user.setEmail(dataObject["email"]) user.setPreHash(dataObject["password"]) user.setRegistered(True) token = Apitoken() token.setUser(user) token.setToken(getKey()) # Save changes to user try: UM.insert(user) # handle the possibility the user already exists except mdb.IntegrityError, e: raise Conflict( "A user with that e-mail address exists already.") # handle all other DB errors except mdb.DatabaseError, e: raise ServerError( "Unable to create user in the database (%s)" % e.args[1])
def setApiKey(self, key): self.key = key if key is not None: try: ATM_ = ATM() apikey = ATM_.findByKey(key) if apikey is None: raise Unauthorised("An invalid API token was supplied.") self.apikey = apikey self.user = self.apikey.getUser() except mdb.DatabaseError, e: raise ServerError("Unable to search the user database (%s)" % e.args[1]) except:
def main(): from Common.config import TopHatConfig # setup the config kwargs = {"path": "/home/specialk/Dev/tophat/config.py"} TopHatConfig(**kwargs) # do the other stuff from Model.Mapper.qrzargamemapper import QRzarGameMapper from Model.Mapper.usermapper import UserMapper from Model.Mapper.killmapper import KillMapper from Model.Mapper.qrzarplayermapper import QRzarPlayerMapper from Model.Mapper.apitokenmapper import ApitokenMapper from Model.Mapper.objectwatcher import ObjectWatcher # Get All the current Users from the database UM = UserMapper() users = UM.findAll() for usr in users: print usr GM = QRzarGameMapper() games = GM.findAll() for game_ in games: print game_ KM = KillMapper() kills = KM.findAll() for kill_ in kills: print kill_ PM = QRzarPlayerMapper() players = PM.findAll() for player_ in players: print player_ ATM = ApitokenMapper() tokens = ATM.findAll() for token in tokens: print token usr1 = UM.find(1)
def main(): from Common.config import TopHatConfig #setup the config kwargs = {"path":"/home/specialk/Dev/tophat/config.py"} TopHatConfig(**kwargs) # do the other stuff from Model.Mapper.gamemapper import GameMapper from Model.Mapper.usermapper import UserMapper from Model.Mapper.killmapper import KillMapper from Model.Mapper.playermapper import PlayerMapper from Model.Mapper.apitokenmapper import ApitokenMapper from Model.Mapper.objectwatcher import ObjectWatcher # Get All the current Users from the database UM = UserMapper() users = UM.findAll() for usr in users: print usr KM = KillMapper() kills = KM.findAll() for kill_ in kills: print kill_ PM = PlayerMapper() players = PM.findAll() for player_ in players: print player_ GM = GameMapper() games = GM.findAll() for game_ in games: print game_ ATM = ApitokenMapper() tokens = ATM.findAll() for token in tokens: print token usr1 = UM.find(1)
raise ServerError("Unable to get API key from the database (%s: %s)" % e.args[0], e.args[1]) else: # Anonymous login rdata = {} token = Apitoken() token.setToken(getKey()) blank = User() blank.setToken(token) token.setUser(blank) umapper = UserMapper() ATM = ApitokenMapper() blank.setRegistered(False) # Save changes to user try: umapper.insert(blank) # handle the possibility the user already exists except mdb.IntegrityError, e: raise Conflict(CODE.CONFLICT, "A unexpected conflict occurred when trying to create your anonymous login token.") # handle all other DB errors except mdb.DatabaseError, e: raise ServerError("Unable to create user in the database (%s)" % e.args[1])