def POST_login(self, site): i = input('username', 'password') a = site.get_account_manager() status = a.login(i.username, i.password) if status == "ok": a.set_auth_token(get_user_root() + i.username) return {"ok": True} else: raise common.BadData(code=status, message="Login failed")
def bootstrap(site, admin_password): """Creates system types and objects for a newly created site. """ from infogami.infobase import cache cache.loadhook() import web web.ctx.infobase_bootstrap = True query = make_query() site.save_many(query) from infogami.infobase import config import random import string def random_password(length=20): chars = string.letters + string.digits return "".join(random.choice(chars) for i in range(length)) # Account Bot is not created till now. Set account_bot to None in config until he is created. account_bot = config.get("account_bot") config.account_bot = None a = site.get_account_manager() a.register(username="******", email="*****@*****.**", password=admin_password, data=dict(displayname="Administrator"), _activate=True) a.update_user_details("admin", verified=True) if account_bot: username = account_bot.split("/")[-1] a.register(username=username, email="*****@*****.**", password=random_password(), data=dict(displayname=username), _activate=True) a.update_user_details(username, verified=True) # add admin user to admin usergroup from infogami.infobase import account q = [ usergroup('/usergroup/admin', 'Group of admin users.', [{ "key": account.get_user_root() + "admin" }]) ] site.save_many(q) config.account_bot = account_bot web.ctx.infobase_bootstrap = False
def has_permission(self, author, key): # admin user can modify everything if author and author.key == account.get_user_root() + 'admin': return True permission = self.get_permission(key) if permission is None: return True else: groups = permission.get('writers') or [] # admin users can edit anything groups = groups + [self.get_thing('/usergroup/admin')] for group in groups: if group.key == '/usergroup/everyone': return True elif author is not None: members = [m.key for m in group.get('members', [])] if group.key == '/usergroup/allusers' or author.key in members: return True else: return False