Beispiel #1
0
def change_password(request):
    response = Epoxy(request)
    if request.method == 'POST':
        form = ChangePasswordForm(request.REQUEST)

        if form.is_valid():
            uPass1 = form.cleaned_data['password1']
            uPass2 = form.cleaned_data['password2']

            if uPass1 == uPass2:
                user = User.objects.get(username=form.cleaned_data['username'])
                user.set_password(uPass1)
                user.save()
            else:
                return response.throw_error(
                    error={
                        'password1': 'the 2 pwd must be the same',
                        'password2': 'the 2 pwd must be the same'
                    },
                    code=API_EXCEPTION_FORMERRORS).json()
        else:
            return response.throw_error(error=form.errors,
                                        code=API_EXCEPTION_FORMERRORS).json()

    return response.json()
Beispiel #2
0
def test( request ):
	response = Epoxy( request )
	response.add( 'full_path', request.get_host()  )
	
	full_url =  "%s://%s%s"% ( 'https' if request.is_secure()  else 'http', request.get_host(), reverse('outside.views.confirm', args=( "dsdsdsds", 12 ) ) )
	response.add( 'full_url',  full_url  )
	
	

	return response.json()
Beispiel #3
0
def test(request):
    response = Epoxy(request)
    response.add('full_path', request.get_host())

    full_url = "%s://%s%s" % (
        'https' if request.is_secure() else 'http', request.get_host(),
        reverse('outside.views.confirm', args=("dsdsdsds", 12)))
    response.add('full_url', full_url)

    return response.json()
Beispiel #4
0
def auth_login(request):

    response = Epoxy(request)

    form = LoginForm(request.POST)
    try:
        if 'next' not in request.session:
            request.session['next'] = request.REQUEST['next']
    except:
        pass

    if request.method == 'POST':

        if form.is_valid():
            user = authenticate(username=form.cleaned_data['username'],
                                password=form.cleaned_data['password'])
            if user is not None:
                if user.is_active:
                    login(request, user)

                    try:
                        subscriber = Subscriber.objects.get(
                            user=request.user.id)
                    except Subscriber.DoesNotExist:
                        return redirect(
                            reverse('outside.views.create_profile'))

                    next_url = request.session['next']

                    del request.session['next']

                    response.add('next', next_url)

                else:
                    return response.throw_error(
                        _("user has been disabled"),
                        code=API_EXCEPTION_FORMERRORS).json()
            else:
                return response.throw_error(
                    error={
                        'username': '',
                        'password': ''
                    },
                    code=API_EXCEPTION_FORMERRORS).json()

                return response.throw_error(
                    error=form.errors, code=API_EXCEPTION_FORMERRORS).json()
        else:
            """login_message['error'] = _("invalid credentials")
			login_message['invalid_fields'] = form.errors"""
            #return HttpResponse('TEST')
            return response.throw_error(error=form.errors,
                                        code=API_EXCEPTION_FORMERRORS).json()

        return response.json()
Beispiel #5
0
def login(request):
	logout(request)
	response = Epoxy(request)
	
	form = LoginForm( request.POST )
	if form.is_valid():
		user = authenticate(username=request.POST['username'], password=request.POST['password'])
	else:
		return response.throw_error(error=form.errors, code=API_EXCEPTION_FORMERRORS ).json()
	
	if user is None:
		return response.throw_error(error="access denied" ).json()
	
	return response.json()
Beispiel #6
0
def auth_login( request ):
	
	response = Epoxy( request )

	form = LoginForm( request.POST )
	try:
		if 'next' not in request.session:
			request.session['next'] = request.REQUEST['next']
	except:
		pass
	
	
	if request.method == 'POST': 

		if form.is_valid():
			user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password'])
			if user is not None:
				if user.is_active:
					login(request, user)

					try:
						subscriber = Subscriber.objects.get(user=request.user.id)
					except Subscriber.DoesNotExist:
						return redirect( reverse('outside.views.create_profile') )
					
					next_url = request.session['next']
					
					del request.session['next']
					
					response.add( 'next', next_url  )
	
				else:
					return response.throw_error( _("user has been disabled"), code=API_EXCEPTION_FORMERRORS).json()
			else:
				return response.throw_error( 
									error={'username':'', 
										'password':''}, 
									code=API_EXCEPTION_FORMERRORS).json()
				
				return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json()
		else:
			"""login_message['error'] = _("invalid credentials")
			login_message['invalid_fields'] = form.errors"""
			#return HttpResponse('TEST')
			return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json()
	
		
		
		return response.json()
Beispiel #7
0
def publish_pin( request, pin_id ):
	response = Epoxy( request )
	new_status = request.POST.get("new_status")

	try:
		if new_status in dict(Pin.PIN_STATUS_CHOICES):
			p=Pin.objects.get( id=pin_id )
			p.status=new_status
			p.save()
			return response.json()
		else:
			return response.throw_error( error="status %s incorrect" % new_status).json()

	except Pin.DoesNotExist, e:
		return response.throw_error( error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST).json()
Beispiel #8
0
def publish_pin(request, pin_id):
    response = Epoxy(request)
    new_status = request.POST.get("new_status")

    try:
        if new_status in dict(Pin.PIN_STATUS_CHOICES):
            p = Pin.objects.get(id=pin_id)
            p.status = new_status
            p.save()
            return response.json()
        else:
            return response.throw_error(error="status %s incorrect" %
                                        new_status).json()

    except Pin.DoesNotExist, e:
        return response.throw_error(error="%s" % e,
                                    code=API_EXCEPTION_DOESNOTEXIST).json()
Beispiel #9
0
def change_password(request):
	response = Epoxy( request )
	if request.method == 'POST':
		form = ChangePasswordForm( request.REQUEST )
		
		if form.is_valid():
			uPass1 = form.cleaned_data['password1']
			uPass2 = form.cleaned_data['password2']
			
			if uPass1 == uPass2:
				user = User.objects.get(username=form.cleaned_data['username'])
				user.set_password(uPass1)
				user.save()
			else:
				return response.throw_error( error={'password1':'the 2 pwd must be the same', 'password2':'the 2 pwd must be the same'}, code=API_EXCEPTION_FORMERRORS).json()
		else:
			return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json()
				
	return response.json()
Beispiel #10
0
def test( request ):
	response = Epoxy( request )
	return response.json()