Exemple #1
0
    def save(self):
        usr = Users.load(self.request.POST.get('user_id'))
        if not usr:
            usr = Users()
            if 'enterprise_id' not in self.request.POST:
                usr.enterprise_id = self.enterprise_id

        if not usr.priv:
            usr.priv = UserPriv()
        usr.priv.bind(self.request.POST, True, 'pv')
        usr.priv.save()
        usr.priv.flush()

        orig_pass = usr.password
        bogus_pass = ''.join(['-' for _ in range(usr.password_len)]) if usr.password_len else '-'
        usr.bind(self.request.POST)
        if usr.password != bogus_pass:
            usr.password_len = len(usr.password)
            usr.password = Users.encode_password(usr.password)
        else:
            usr.password = orig_pass
        usr.save()
        usr.flush()
        usr.invalidate_self()

        self.request.session.flash('Saved user %s' % usr.user_id)
        return HTTPFound('/crm/users/edit/%s' % usr.user_id)
Exemple #2
0
    def provision(self):
        ent = Enterprise()
        ent.bind(self.request.POST, True, 'ent')
        ent.save()
        ent.flush()

        comp = Company()
        comp.bind(self.request.POST, True, 'cmp')
        comp.enterprise_id = ent.enterprise_id
        comp.save()
        comp.flush()

        campaign = Campaign()
        campaign.name = comp.name + ' Default'
        campaign.company_id = comp.company_id
        campaign.save()
        campaign.flush()

        comp.default_campaign_id = campaign.campaign_id
        comp.save()
        comp.flush()

        user = Users()
        user.bind(self.request.POST, True, 'u')
        user.password = Users.encode_password('password')
        user.enterprise_id = ent.enterprise_id
        user.type = 'Admin'
        user.save()
        user.flush()

        site = Site()
        site.bind(self.request.POST, True, 'st')
        site.company = comp
        site.description = comp.name + ' Site'
        site.creator = user
        #site.template = Template.find_by_name('default')
        site.save()
        site.flush()

        return {
            'enterprise' : ent,
            'company' : comp,
            'campaign' : campaign,
            'user' : user,
            'site' : site,
            'done' : True
            }