Ejemplo n.º 1
0
    def create_user(self):
        schema = AdminUserSchema()
        schema = schema.bind(request=self.request)
        form = HorusForm(schema)

        if self.request.method == "GET":
            if isinstance(self.request.context, RootFactory):
                return dict(form=form)
            else:
                return dict(form=form, appstruct=self.request.context.__json__())
        else:
            try:
                controls = self.request.POST.items()
                captured = form.validate(controls)
            except deform.ValidationFailure as e:
                return dict(form=e, errors=e.error.children)

            if isinstance(self.request.context, RootFactory):
                user = self.User(username=captured["username"], email=captured["email"])
            else:
                user = self.request.context

            if captured["password"]:
                user.password = captured["password"]

            self.db.add(user)

            FlashMessage(self.request, self.Str.admin_create_user_done, "success")

            return HTTPFound(location=self.request.route_url("admin_users_index"))
Ejemplo n.º 2
0
    def create_user(self):
        schema = AdminUserSchema()
        schema = schema.bind(request=self.request)
        form = HorusForm(schema)

        if self.request.method == 'GET':
            if isinstance(self.request.context, RootFactory):
                return dict(form=form)
            else:
                return dict(form=form,
                            appstruct=self.request.context.__json__(
                                self.request))
        else:
            try:
                controls = self.request.POST.items()
                captured = form.validate(controls)
            except deform.ValidationFailure as e:
                return dict(form=e, errors=e.error.children)

            if isinstance(self.request.context, RootFactory):
                user = self.User(username=captured['username'],
                                 email=captured['email'])
            else:
                user = self.request.context

            if captured['password']:
                user.password = captured['password']

            self.db.add(user)

            FlashMessage(self.request, self.Str.admin_create_user_done,
                         'success')

            return HTTPFound(
                location=self.request.route_url('admin_users_index'))
Ejemplo n.º 3
0
    def create_user(self):
        if self.enabled is False:
            return HTTPNotImplemented()
        schema = AdminUserSchema()
        schema = schema.bind(request=self.request)
        form = HorusForm(schema)

        if self.request.method == 'GET':
            return dict(form=form)
        else:
            try:
                controls = self.request.POST.items()
                captured = form.validate(controls)
            except deform.ValidationFailure, e:
                return dict(form=e, errors=e.error.children)

            user = self.User()
            user_account = self.UserAccount(
                    username=captured['Username'],
                    email=captured['Email'],
                    password=captured['Password']
            )
            user.accounts.append(user_account)

            self.db.add(user)

            self.request.session.flash(translate(u'The user account was created'), 'success')

            return HTTPFound(
                location=self.request.route_url('horus_admin_users_list')
            )
Ejemplo n.º 4
0
    def create_user(self):
        schema = AdminUserSchema()
        schema = schema.bind(request=self.request)
        form = HorusForm(schema)

        if self.request.method == 'GET':
            if isinstance(self.request.context, RootFactory):
                return dict(form=form)
            else:
                return dict(
                    form=form,
                    appstruct=self.request.context.__json__()
                )
        else:
            try:
                controls = self.request.POST.items()
                captured = form.validate(controls)
            except deform.ValidationFailure as e:
                return dict(form=e, errors=e.error.children)

            if isinstance(self.request.context, RootFactory):
                user = self.User(
                    username=captured['username'],
                    email=captured['email']
                )
            else:
                user = self.request.context

            if captured['password']:
                user.password = captured['password']

            self.db.add(user)

            self.request.session.flash(_('The user was created'), 'success')

            return HTTPFound(
                location=self.request.route_url('admin_users_index')
            )