def authenticate(username, password, ip_address): """ Return the user id for the username/password combo, if valid. """ with get_exchange() as x: connect = x.get_verb(1, 'connect') if(connect): connect(ip_address) authentication = x.get_verb(1, 'authenticate') if(authentication): u = authentication(username, password, ip_address) if(u): return {'user_id': u.get_id()} try: u = x.get_object(username) if not(u): raise errors.PermissionError("Invalid login credentials. (2)") except errors.NoSuchObjectError as e: raise errors.PermissionError("Invalid login credentials. (3)") except errors.AmbiguousObjectError as e: raise errors.PermissionError("Invalid login credentials. (4)") multilogin_accounts = x.get_property(1, 'multilogin_accounts') if(u.is_connected_player()): if(not multilogin_accounts or u not in multilogin_accounts.value): raise errors.PermissionError('User is already logged in.') if not(u.validate_password(password)): raise errors.PermissionError("Invalid login credentials. (6)") return {'user_id': u.get_id()}
def reload_filesystem_verbs(p): """ Verb API: Reload the set of verbs initialized from the filesystem. """ if not (p.caller.is_wizard()): raise errors.PermissionError( "Only wizards can reload filesystem verbs.") p.exchange.reload_filesystem_verbs()
def set_location(self, location): """ Set this object's location to the provided object. [ACL] allowed to move this """ self.check('move', self) if (location and self.contains(location)): raise errors.RecursiveError("Sorry, '%s' already contains '%s'" % (self, location)) if (location and location.has_verb('accept')): if not (location.accept(self)): raise errors.PermissionError("%s won't let %s inside." % (location, self)) old_location = self.get_location() if (old_location and old_location.has_verb('provide')): if not (old_location.provide(self)): raise errors.PermissionError("%s won't let %s out." % (old_location, self)) if (location and location.has_verb('enter')): location.enter(self) self._location_id = location.get_id() if location else None self.save() if (location is not old_location): self.clear_observers() if (old_location and old_location.has_verb('exit')): old_location.exit(self) self.save() if (old_location): old_location.notify_observers() if (location): location.notify_observers() if (self.is_player() and old_location is not location): if (old_location): old_location.remove_observer(self) if (location): location.add_observer(self)