Esempio n. 1
0
 def activateUser(self):
     errors = []
     username = request.POST['username'].strip()
     password = request.POST['password']
     reminder = request.POST['reminder']
     activation_code = request.POST['code']
     
     if username:
         if model.Manager.get_manager_with_username(username):
             errors.append('The username you have chosen exists.  Please choose a different username.')
     else:
         errors.append('You did not enter a username.')
         
     if not password:
         errors.append('You did not enter a password')
     
     if not reminder:
         errors.append('You did not enter a secret reminder to help remember your password')
     
     if not errors:
         manager = model.Manager.get_user_by_activation_code(activation_code)
         manager.username = username
         manager.password_secret = reminder
         manager.activation_code = None
         users.user_create(username, password, group=manager.type)
         meta.Session.commit()
         session.save()
         
         company_name = model.Company.get_name_by_id(manager.companyid)
         mailman.sendWelcome(manager.email, manager.id, manager.first_name, company_name, username, password)
     
     return json.dumps({'errors':errors})
Esempio n. 2
0
    def createNewClient(self):
        captchaPrivateKey = settings.RECAPTCHA_PRIVATE_KEY
        response = captcha.submit(
            request.POST['captchaChallenge'],
            request.POST['captchaResponse'],
            captchaPrivateKey,
            request.environ['REMOTE_ADDR'],
            )
        if not response.is_valid:
            errors = []
            errors.append({"selector":"#recaptcha_response_field", "message":"Sorry, please try again."})
            return json.dumps({"errors":errors})
        else:
            usertype = 'admin'
            
            company_id = str(uuid.uuid1())
            company_name = request.POST['company']
            username = request.POST['username'].strip()
            first_name = request.POST['fname'].strip()
            last_name = request.POST['lname'].strip()
            email = request.POST['email'].strip().lower()
            phone = request.POST['phone']
            password_secret = request.POST['secret'].strip()
            
            model.Company.create(
                                 id = company_id,
                                 name = company_name,
                                 email = email,
                                 phone = phone,
                                 maxunits = 500
                                 )
            
            manager_id = str(uuid.uuid1())

            model.Manager.create(
                             id = manager_id, 
                             companyid = company_id, 
                             username = username, 
                             first_name = first_name, 
                             last_name = last_name, 
                             email = email, 
                             phone = phone,
                             type = usertype,
                             password_secret = password_secret,
                             created_by = 'rentfox'
                             )
            
            users.user_create(request.POST['username'], request.POST['password'], group=usertype)
            meta.Session.commit()
            session.save()
            
            type_id = str(uuid.uuid1())
            model.Contact_type.create(id=type_id, label='Vendors', companyid=company_id)
            type_id = str(uuid.uuid1())
            model.Contact_type.create(id=type_id, label='Utilities', companyid=company_id)
            
            mailman.sendWelcome(email, manager_id, first_name, company_name, username, request.POST['password'])
            
            return json.dumps({"errors":0})