예제 #1
0
def supervisor_new(request):
	try:
		first_name = request.POST.get('first_name', '')
		last_name = request.POST['last_name']
		email = request.POST['email']
		phone = request.POST.get('tel', '')
		is_admin = request.POST.get('is_admin', '')

		password = request.POST.get('password', last_name)

		new_supervisor = InfoUser(
			username=email,
			first_name=first_name,
			last_name=last_name,
			tipo=InfoUser.SUPERVISOR,
			email=email,
			password=password,
			telefono=phone)
		new_supervisor.is_active = (is_admin.lower() == "true")
		new_supervisor.save()

		registerLog(request.user, 'Nuevo', 'Supervisor', new_supervisor.pk)
		data = simplejson.dumps({
			'code' : 1,
			'msg' : "Bien",
			'user_id':new_supervisor.pk
		})
	except :
		data = simplejson.dumps({
			'code' : 0,
			'msg' : "Fallo"
		})
	return render(request, 'simple_data.html', { 'data':data }, content_type='application/json' )
예제 #2
0
def admin_new(request):
	try:
		if not check_superadmin(request.user):
			data = simplejson.dumps({
				'code' : 0,
				'msg' : "Sin permiso"
			})
			return render(request, 'simple_data.html', { 'data':data }, content_type='application/json')
		first_name = request.POST.get('first_name', '')
		last_name = request.POST['last_name']
		email = request.POST['email']
		phone = request.POST.get('tel', '')
		password = request.POST.get('password', '')
		is_admin = request.POST.get('is_admin', '')

		my_password = request.POST.get('my_password', None)
		if not request.user.check_password(my_password):
			data = simplejson.dumps({
				'code' : 0,
				'msg' : "Contraseña incorrecta"
			})
			return render(request, 'simple_data.html', { 'data':data }, content_type='application/json')

		new_admin = InfoUser(
			username=email,
			first_name=first_name,
			last_name=last_name,
			tipo=InfoUser.ADMINISTRADOR,
			email=email,
			password=password,
			telefono=phone)
		new_admin.is_active = (is_admin.lower() == "true")
		new_admin.save()

		registerLog(request.user, 'Nuevo', 'Administrador', new_admin.pk)

		data = simplejson.dumps({
			'code' : 1,
			'msg' : "Bien",
			'user_id' : new_admin.pk
		})
	except :
		data = simplejson.dumps({
			'code' : 0,
			'msg' : "Fallo"
		})
	return render(request, 'simple_data.html', { 'data':data }, content_type='application/json')