def register(request): db = DBSession() form = Form(request, RegistrationSchema) if form.validate(): user = form.bind(User(), exclude=['password_confirmation']) group = db.query(Group).filter(Group.name == 'users').one() user.groups.append(group) db.add(user) db.flush() transaction.commit() return HTTPFound(location=request.route_url('root')) return dict(form=FormRenderer(form))
def edit(request): name = request.matchdict['game'] user_id = authenticated_userid(request) db = DBSession() game = db.query(Game).filter( Game.user_id == user_id).filter(Game.name == name).first() if not game: return HTTPNotFound(request.translate("A game named %s doesn't exist" % name)) form = Form(request, EditGameSchema, obj=game) if form.validate(): form.bind(game, exclude=['name']) transaction.commit() return HTTPFound(location=request.route_url('games')) return dict(form=FormRenderer(form))
def login(request): came_from = request.params.get('came_from', '/') auth_failed = False form = Form(request, LoginSchema) if form.validate(): db = DBSession() user = db.query(User).filter(User.name == form.data['name']).first() if user and user.validate_password(form.data['password']): return HTTPFound(location=came_from, headers=remember(request, user.id)) auth_failed = True return dict( auth_failed = auth_failed, form = FormRenderer(form) )
def add(request): user_id = authenticated_userid(request) form = Form(request, AddGameSchema, state=State(user_id=user_id), defaults=dict(port=23)) if form.validate(): game = form.bind(Game()) game.user_id = user_id db = DBSession() db.add(game) db.flush() transaction.commit() #template_dir = os.path.join(os.path.dirname(__file__), # '_game_session_template') #session_dir = os.path.join(self.users_dir, metauser.name, session.name) #if not os.path.exists(session_dir): # shutil.copytree(template_dir, session_dir) return HTTPFound(location=request.route_url('games')) return dict(form=FormRenderer(form))