Beispiel #1
0
    def save(self, customerid):
        cOld = Customer.objects.get(id=customerid,isActive=True)
        c = Customer()
        c.user = cOld.user
        data = self.cleaned_data
        c.title = data['title']
        c.name = data['name']
        try:            
            c.birthday = data['birthday']
        except KeyError:
            pass

        c.language_code = data['language']

        email = data['email']
        try:
            if User.objects.filter(email=email).count > 0:
                if not cOld.user == User.objects.get(email=email):
                    raise forms.ValidationError(
                        _(u"Die Email-Adresse ist schon bei uns registriert."))
        except:
            pass

        c.user.email = email
        c.user.save()
        c.isActive = False
        c.save()

        try:
            subs = Subscriper.objects.get(user=c.user)
        except Subscriper.DoesNotExist:
            subs = Subscriper()
            subs.user = c.user

        if data['newsletter']:
            subs.isActivated = True
            if subs.signoff_date:
                subs.signon_date = datetime.datetime.now()
                subs.signoff_date = None
        else:
            subs.isActivated = False
            subs.signoff_date = datetime.datetime.now()

        subs.email = c.user.email
        tmp = '%s%s' % (subs.email,datetime.datetime.now())
        subs.confirmkey = hashlib.md5(hashlib.md5(tmp).hexdigest()).hexdigest()
        subs.save()

        cOld.isActive = False
        cOld.save()
        c.isActive = True
        c.save()
        return c
Beispiel #2
0
    def save(self, request=None, **kwargs):
        import logging
        logging.basicConfig(filename=settings.LOG_FILENAME,level=logging.INFO)

        logging.info('-----NEW REGISTRATION--- START')

        c = Customer()
        data = self.cleaned_data
        logging.info(data)
        c.title = FORM_CHOICES[data['form']][1]
        c.first_name = data['firstname']
        c.last_name = data['lastname']
        try:
            c.birthday = data['birthday']
        except:
            logging.info('birthday failed')
            pass
        c.language_code = 'de'

        email = data['email']
        password = data['password']
        uname = data['username']
        user = User.objects.create_user(uname, email, password)
        user.is_active = False
        user.save()
        logging.info('new user saved')
        c.user = user
        c.save()

        acc = Account(user=user, total_current=0, total_lifetime=0)
        acc.save()

        ec = EmailConfirm(user=user)
        tmp = '%s%s' % (user.email,datetime.datetime.now())
        ec.confirmkey = hashlib.md5(hashlib.md5(tmp).hexdigest()).hexdigest()
        ec.save()

        try:
            if data['newsletter']:
                s = Subscriper()
                s.email = email
                s.user = c.user
                tmp = '%s%s' % (s.email,datetime.datetime.now())
                s.confirmkey = hashlib.md5(hashlib.md5(tmp).hexdigest()).hexdigest()
                s.isActivated = True
                s.save()
        except:
            logging.info('maybe no newsletter')
            pass

        ref = Referral()
        ref.promoter = User.objects.get(username=data['refcode'])
        ref.referral = c.user
        ref.save()

        logging.info('send welcomemail to user')
        sendWelcomeMail(user)

        #user = authenticate(username=uname, password=password)
        #login(request, user)
        logging.info('-----NEW REGISTRATION--- END')
        return c