Example #1
0
def subscribers(request):
	# logger.info("Welcome to GLUEBOX api")
	response = Epoxy( request )
	if response.method=="POST":

		form = SubscriberForm( request.REQUEST )
		
		if not form.is_valid():
			return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json()
		
		try:
			s = Subscriber(
				first_name = form.cleaned_data['first_name'],
				last_name = form.cleaned_data['last_name'],
				email = form.cleaned_data['email'],
				affiliation = form.cleaned_data['affiliation'],
				accepted_terms = form.cleaned_data['accepted_terms'],
				description = form.cleaned_data['description'])
			s.save()

		except IntegrityError, e:
			try:
				s = Subscriber.objects.get( email=form.cleaned_data['email']  )

			except Subscriber.DoesNotExist, e:
				return response.throw_error( error="%s" % e, code=API_EXCEPTION_INTEGRITY).json()	
Example #2
0
def signups(request):
	# logger.info("Welcome to GLUEBOX api")
	response = Epoxy( request )
	if response.method=="POST":

		form = SignupForm( request.REQUEST )
		
		if not form.is_valid():
			return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json()
		
		
		if(form.cleaned_data['password1'] != form.cleaned_data['password2']):
			return response.throw_error( 
									error={'password1':'Please enter and confirm your password', 
										'password2':'Please enter and confirm your password'}, 
									code=API_EXCEPTION_FORMERRORS).json()
		"""else:
			if CheckPassword( form.cleaned_data['password1'] ) < 3 :
				return response.throw_error( 
									error=_('The password stength is too weak.'),
									code=API_EXCEPTION_FORMERRORS,
									fields={'password1':'', 'password2':''}
									
									).json()
		"""
		
		#Check email already exists in database
		
			
		
		if User.objects.filter( email = form.cleaned_data['email'] ).count() > 0 :
			return response.throw_error( 
									error=_('This email is already used in the database.'),
									code=API_EXCEPTION_FORMERRORS,
									fields={'email':''}).json()
		
		
		try:
			created_user =  User.objects.get( username = form.cleaned_data['username'] )
		
		except User.DoesNotExist, e:	
			# User creation
			created_user = User.objects.create(
				first_name = form.cleaned_data['first_name'],
				last_name = form.cleaned_data['last_name'],
				username = form.cleaned_data['username'].lower(),
				email = form.cleaned_data['email'],
				is_active = False,
			)
			
			created_user.set_password(str(form.cleaned_data['password2']))
			created_user.save()

	
		else: #If the user already exists
			
			return response.throw_error( error=_('This username is already used'), code=API_EXCEPTION_INTEGRITY, fields={"username":""}).json()
		
	
		
		try:
			s = Subscriber.objects.get( user=created_user )

		except Subscriber.DoesNotExist, e:

			s = Subscriber(
				user = created_user,
				affiliation = form.cleaned_data['affiliation'],
				first_name = form.cleaned_data['first_name'],
				last_name = form.cleaned_data['last_name'],
				status = form.cleaned_data['status'],
				accepted_terms = form.cleaned_data['accepted_terms'],
				description = form.cleaned_data['description'],
				email = form.cleaned_data['email'],
				email_confirmed=False
			)
			s.save()
				
			mail_send = send_confirmation_mail( subscriber=s, request=request, action="signup" )
			
			if( mail_send ==  False ):
				created_user.delete()
				return response.throw_error( error=_('This email does not exists'), code=API_EXCEPTION_INTEGRITY, fields={"email":""}).json()
Example #3
0
def signups(request):
    # logger.info("Welcome to GLUEBOX api")
    response = Epoxy(request)
    if response.method == "POST":

        form = SignupForm(request.REQUEST)

        if not form.is_valid():
            return response.throw_error(error=form.errors,
                                        code=API_EXCEPTION_FORMERRORS).json()

        if (form.cleaned_data['password1'] != form.cleaned_data['password2']):
            return response.throw_error(error={
                'password1':
                'Please enter and confirm your password',
                'password2':
                'Please enter and confirm your password'
            },
                                        code=API_EXCEPTION_FORMERRORS).json()
        """else:
			if CheckPassword( form.cleaned_data['password1'] ) < 3 :
				return response.throw_error( 
									error=_('The password stength is too weak.'),
									code=API_EXCEPTION_FORMERRORS,
									fields={'password1':'', 'password2':''}
									
									).json()
		"""

        #Check email already exists in database

        if User.objects.filter(email=form.cleaned_data['email']).count() > 0:
            return response.throw_error(
                error=_('This email is already used in the database.'),
                code=API_EXCEPTION_FORMERRORS,
                fields={
                    'email': ''
                }).json()

        try:
            created_user = User.objects.get(
                username=form.cleaned_data['username'])

        except User.DoesNotExist, e:
            # User creation
            created_user = User.objects.create(
                first_name=form.cleaned_data['first_name'],
                last_name=form.cleaned_data['last_name'],
                username=form.cleaned_data['username'].lower(),
                email=form.cleaned_data['email'],
                is_active=False,
            )

            created_user.set_password(str(form.cleaned_data['password2']))
            created_user.save()

        else:  #If the user already exists

            return response.throw_error(
                error=_('This username is already used'),
                code=API_EXCEPTION_INTEGRITY,
                fields={
                    "username": ""
                }).json()

        try:
            s = Subscriber.objects.get(user=created_user)

        except Subscriber.DoesNotExist, e:

            s = Subscriber(user=created_user,
                           affiliation=form.cleaned_data['affiliation'],
                           first_name=form.cleaned_data['first_name'],
                           last_name=form.cleaned_data['last_name'],
                           status=form.cleaned_data['status'],
                           accepted_terms=form.cleaned_data['accepted_terms'],
                           description=form.cleaned_data['description'],
                           email=form.cleaned_data['email'],
                           email_confirmed=False)
            s.save()

            mail_send = send_confirmation_mail(subscriber=s,
                                               request=request,
                                               action="signup")

            if (mail_send == False):
                created_user.delete()
                return response.throw_error(
                    error=_('This email does not exists'),
                    code=API_EXCEPTION_INTEGRITY,
                    fields={
                        "email": ""
                    }).json()