Exemplo n.º 1
0
def registro(req):
	if req.method == 'POST':
		nombre = req.POST.get('nombre')
		email  = req.POST.get('email')
		tel    = req.POST.get('telefono')
		prods   = req.POST.getlist('producto[]')

		if nombre and email and tel:

			user = User.objects.create_user(username=utils.generate_username(nombre), email=email)
			user.save()

			empresa = user.get_profile()
			empresa.telefono = tel
			empresa.nombre = nombre

			if prods: empresa.publico = True

			empresa.save()

			if prods:
				for p in prods:
					# TODO: checar si el producto ya existe, si ya existe no volverlo a crear
					producto = Producto(nombre=p)
					producto.save()

					empresa.productos.add(producto)

			return HttpResponse('<legend>Gracias por registrarte.</legend><p>Revisa tu correo y haz click en el link que te enviamos para completar tu registro.</p>')

	return render_to_response('website/registro.html', RequestContext(req))
Exemplo n.º 2
0
def create_profile(line):
    first_name = line[1].split()[0]
    last_name = line[1].split()[-1]
    email = line[3]
    if not email: return None
    username = email.split('@')[0][:30]
    username = generate_username(username)
    user = User.objects.create_user(username, email)
    user.first_name = first_name
    user.last_name = last_name
    user.set_unusable_password()
    user.save()
    user_created = True
    
    phone = "".join(c for c in line[2] if c.isdigit())[:20]
    city = line[12].split("/")[0].strip()[:100]
    
    sep = '-'
    if '/' in line[12]:
        sep = '/'

    try:   
        state = line[12].split(sep)[1].strip().upper()[:2]
    except IndexError:
        state = ""
    
    profile = Profile.objects.create(
            user=user, 
            phone=phone,
            state=state,
            city=city,
            active=True,
            is_bikeanjo=True
    )
    return profile
Exemplo n.º 3
0
 def register_account(self, server):
     reactor.callLater(10, self._failed, "timeout")
     username = utils.generate_username()
     self._jid = "%s@%s" % (username, server)
     self._password = utils.generate_password()
     jid_obj = jid.JID(self._jid)
     if self._verbose:
         print "Connecting to", jid_obj.host
     a = RegisterAuthenticator(jid_obj, self._password)
     factory = xmlstream.XmlStreamFactory(a)
     factory.maxRetries = 0
     factory.clientConnectionFailed = self._failed
     factory.addBootstrap(STREAM_CONNECTED_EVENT, self._connected)
     factory.addBootstrap(xmlstream.INIT_FAILED_EVENT, self._failed)
     factory.addBootstrap(RegisterInitializer.REGISTER_SUCCEEDED_EVENT,
                          self._registered)
     factory.addBootstrap(RegisterInitializer.REGISTER_FAILED_EVENT,
                          self._failed)
     reactor.connectTCP(jid_obj.host, 5222, factory, timeout=4)
     return self._deferred
Exemplo n.º 4
0
 def register_account(self, server):
     reactor.callLater(10, self._failed, "timeout")
     username = utils.generate_username()
     self._jid = "%s@%s" % (username, server)
     self._password = utils.generate_password()
     jid_obj = jid.JID(self._jid)
     if self._verbose:
         print "Connecting to", jid_obj.host
     a = RegisterAuthenticator(jid_obj, self._password)
     factory = xmlstream.XmlStreamFactory(a)
     factory.maxRetries = 0
     factory.clientConnectionFailed = self._failed
     factory.addBootstrap(STREAM_CONNECTED_EVENT, self._connected)
     factory.addBootstrap(xmlstream.INIT_FAILED_EVENT, self._failed)
     factory.addBootstrap(RegisterInitializer.REGISTER_SUCCEEDED_EVENT,
                          self._registered)
     factory.addBootstrap(RegisterInitializer.REGISTER_FAILED_EVENT,
                          self._failed)
     reactor.connectTCP(jid_obj.host, 5222, factory, timeout=4)
     return self._deferred
Exemplo n.º 5
0
def new(request):
    if not auth.in_groups(request):
        logout(request)
        return HttpResponseRedirect( '/accounts/login/' )

    if request.method == "POST":
        form = TempUserForm(data=request.POST)
        if form.is_valid():
            duration = datetime.timedelta(days=form.cleaned_data['duration'])
            expires = datetime.datetime.now() + duration
            log = TempUserLog.objects.create(
                description=form.cleaned_data['description'],
                expires=expires,
                issued_by=request.user,
                count=form.cleaned_data['count'])
            for i in range(form.cleaned_data['count']):
                username = utils.generate_username()
                raw_password = utils.generate_password()
                # Store in Radius
                rc = Radcheck.objects.create(
                    username=username,
                    attribute='NT-Password',
                    op=':=',
                    value=utils.ntpass_hash(raw_password))
                # store raw_password
                UserPass.objects.create(
                    username=username,
                    password=raw_password,
                    radcheck_id=rc.id,
                    log=log)
            messages.success(request, log.id) # Store the id in session, since we are redirecting
            messages.success(request, 'Successfully created user(s) in radius database.')
            return HttpResponseRedirect( reverse('main.views.new_created') )
        else:
            form = TempUserForm(request.POST)
            return render_to_response('private/new.html', locals(), context_instance=RequestContext(request))
    form = TempUserForm()

    return render_to_response('private/new.html', locals(), context_instance=RequestContext(request))