Esempio n. 1
0
    def test_user_has_no_role(self):
        user = self.user

        assign_role(user, 'sho_role1')
        remove_role(user)

        self.assertEquals(get_user_role(user), None)
    def test_user_has_no_role(self):
        user = self.user

        assign_role(user, 'sho_role1')
        remove_role(user)

        self.assertEquals(get_user_role(user), None)
Esempio n. 3
0
	def form_valid(self, form):
		obj = form.save(commit=False)
		assign_role(form.instance,'student')
		obj.set_password(User.objects.make_random_password())
		obj.save()
		context = self.get_context_data(form=form)
		context['success'] = True
		return self.render_to_response(context)
Esempio n. 4
0
    def setUp(self):
        self.client = Client()

        self.user = User.objects.create_user(username='******',
                                             email='*****@*****.**',
                                             is_staff=True,
                                             is_active=True,
                                             password='******')
        assign_role(self.user, 'system_admin')
Esempio n. 5
0
    def form_valid(self, form):
        context = super(CadatroAlunoView, self).form_valid(form)
        user = User.objects.get(username=form.cleaned_data['username'])
        assign_role(user, 'aluno')
        context['sucesso'] = True

        # print ((self.request.POST))
        # print ((form))
        # print (dir(form))
        return context
Esempio n. 6
0
def save_assign_role_to_user(sender, instance, **kwargs):  # pylint: disable=unused-argument
    """
    Signal handler to assign a logical role to an user every time
    the same role is assigned to an user for a program
    """
    log.debug(
        'assigning role %s to user %s',
        instance.role,
        instance.user.username,
    )
    assign_role(instance.user, instance.role)
Esempio n. 7
0
    def form_valid(self, form):
        context = super(CadatroProfessorView, self).form_valid(form)
        user = User.objects.get(username=form.cleaned_data['username'])
        assign_role(user, 'professor')
        user.is_professor = True
        user.save()
        context['sucesso'] = True

        # print ((self.request.POST))
        # print ((form))
        # print (dir(form))
        return context
Esempio n. 8
0
def add_user(request):
    if request.method == 'POST':
        user = User.objects.create_user(
            username=request.POST.get('username', None),
            password=request.POST.get('username', None),
            email=None)
        if request.user.is_superuser:
            assign_role(user, 'lead_recruiter')
        else:
            assign_role(user, 'recruiter')
        user.save()
        return redirect('/web/users')
    return render(request, 'add_user.html')
Esempio n. 9
0
def update(request, login):
	context = {}

	user = get_object_or_404(User, username = login)

	form = UserForm(request.POST or None, request.FILES or None, instance = user)
	
	if form.is_valid():
		new_user = form.save(commit = False)

		if user.type_profile == 2:
			assign_role(user, 'student')
		elif user.type_profile == 1:
			assign_role(user, 'professor')
		elif user.is_staff:
			assign_role(user, 'system_admin')

		new_user.save()

		messages.success(request, _('User edited successfully!'))

		return redirect('app:users:manage')
	
	context['form'] = form

	return render(request, "users/update.html", context)
Esempio n. 10
0
File: utils.py Progetto: defivelo/db
    def __init__(self):
        super(AuthClient, self).__init__()
        self.USERNAME = get_new_username()
        self.PASSWORD = fake.password()
        self.EMAIL = fake.email()

        # Create that user
        self.user = get_user_model().objects.create_user(
            username=self.USERNAME,
            password=self.PASSWORD,
            email=self.EMAIL,
            first_name=fake.first_name(),
            last_name=fake.last_name(),
        )
        UserProfile.objects.get_or_create(user=self.user)
        # Create his trusted Email
        EmailAddress.objects.create(user=self.user, email=self.EMAIL, verified=True, primary=True)
        self.login(email=self.EMAIL, password=self.PASSWORD)

        self.language = "fr"
        activate(self.language)

        if self.role:
            assign_role(self.user, self.role)
Esempio n. 11
0
def registro_usuarios(request):
    
    usuario_log = request.user
    role = get_user_role(usuario_log)
    if (role == Estudiante or usuario_log.is_authenticated() == False):
        return HttpResponseRedirect('/index')
    
    if request.method == 'POST':
        user_form = RegistroForm(request.POST)
        if user_form.is_valid():
            if request.POST.get('permisos') == 'Estudiante':
                usuario = user_form.save(commit=False)
                usuario = User(username=request.POST['username'], email=request.POST['email'], first_name=request.POST['first_name'], last_name=request.POST['last_name'])
                usuario.set_password(request.POST['password1'])
                usuario.save()
                user = User.objects.get(username= request.POST['username'])
                assign_role(user,'estudiante')
                return HttpResponseRedirect('/index')
            elif request.POST.get('permisos') == 'Administrador':
                usuario = user_form.save(commit=False)
                usuario = User(username=request.POST['username'], email=request.POST['email'], first_name=request.POST['first_name'], last_name=request.POST['last_name'])
                usuario.set_password(request.POST['password1'])
                usuario.save()
                user = User.objects.get(username= request.POST['username'])
                assign_role(user,'administrador')
                return HttpResponseRedirect('/index')
            elif request.POST.get('permisos') == 'Calificador':
                usuario = user_form.save(commit=False)
                usuario = User(username=request.POST['username'], email=request.POST['email'], first_name=request.POST['first_name'], last_name=request.POST['last_name'])
                usuario.set_password(request.POST['password1'])
                usuario.save()
                user = User.objects.get(username= request.POST['username'])
                assign_role(user,'calificador')
            else:
                user_form = RegistroForm(request.POST)
                roles = Usuario_permisos.objects.all().order_by('id')
        else:
            user_form = RegistroForm(request.POST)
            roles = Usuario_permisos.objects.all().order_by('id')
    else:
        user_form = RegistroForm()
        roles = Usuario_permisos.objects.all().order_by('id')
    
    roles = Usuario_permisos.objects.all().order_by('id')
        
    contexto = {
        'formulario':user_form,'roles':roles
    }
    return render(request,'usuario/registrar.html',contexto)
Esempio n. 12
0
def edit_profile(request):
	form = ProfileForm(request.POST or None, request.FILES or None, instance=request.user)
    
	context = {}
    
	if form.is_valid():
		user = form.save(commit = False)

		if user.type_profile == 2:
			assign_role(user, 'student')
		elif user.type_profile == 1:
			assign_role(user, 'professor')
		elif user.is_staff:
			assign_role(user, 'system_admin')

		user.save()

		messages.success(request, _('Profile edited successfully!'))

	context['form'] = form

	return render(request, "users/edit_profile.html", context)
Esempio n. 13
0
def create(request):
	context = {}

	form = UserForm(request.POST or None, request.FILES or None)
	
	if form.is_valid():
		user = form.save(commit = False)

		if user.type_profile == 2:
			assign_role(user, 'student')
		elif user.type_profile == 1:
			assign_role(user, 'professor')
		elif user.is_staff:
			assign_role(user, 'system_admin')

		user.save()

		messages.success(request, _('User created successfully!'))

		return redirect('app:users:manage')
	
	context['form'] = form

	return render(request, "users/create.html", context)
    def test_assign_role(self):
        user = self.user

        assign_role(user, 'sho_role1')

        self.assertEquals(get_user_role(user), ShoRole1)
Esempio n. 15
0
def become_visitor(request, *args, **kwargs):
    if request.user:
        assign_role(request.user, Visitor)
    return redirect('website:index')
Esempio n. 16
0
    def test_assign_invalid_role(self):
        user = self.user

        with self.assertRaises(RoleDoesNotExist):
            assign_role(user, 'no role')
Esempio n. 17
0
    def test_assign_role(self):
        user = self.user

        assign_role(user, 'sho_role1')

        self.assertEquals(get_user_role(user), ShoRole1)
Esempio n. 18
0
def become_seller(request, *args, **kwargs):
    if request.user:
        assign_role(request.user, Seller)
    return redirect('website:index')
Esempio n. 19
0
 def form_valid(self, form):
     form.save()
     assign_role(form.instance, 'student')
     context = self.get_context_data(form=form)
     context['success'] = True
     return self.render_to_response(context)
def nueva_inscripcion(request):
    #Validacion, para que el usuario que este registrado no pueda ingresar al formulario de inscripcion
    role = get_user_role(request.user)
    if role == Estudiante:
        return HttpResponseRedirect('/index')
    if request.method == 'POST':
        #recibir los datos
        form = PersonaForm(request.POST)
        form2 = InscripcionForm(request.POST)
        if (form.is_valid() and form2.is_valid()):
            try:
                data_persona = form.cleaned_data
                data_inscripcion = form2.cleaned_data
                edad_inscripcion = data_persona['edad']
                diferencia = int(
                    ((datetime.date.today() - edad_inscripcion).days) / 365)
                existe = Persona.objects.filter(
                    num_identificacion=data_persona['num_identificacion']
                ).count()

                if (existe != 0):
                    messages.error(
                        request,
                        "Su Identificacion ya se encuentra registrada")
                    form = PersonaForm(request.POST)
                    form2 = InscripcionForm(request.POST)

                elif (data_persona['email'] == data_persona['email_acudiente']
                      ):
                    messages.error(
                        request,
                        "El email de contacto debe ser diferentes al del usuario"
                    )
                    form = PersonaForm(request.POST)
                    form2 = InscripcionForm(request.POST)

                elif (data_persona['num_identificacion'] <= 0
                      or data_persona['tel_contacto'] <= 0
                      or data_persona['telefono_acudiente'] <= 0):
                    messages.error(
                        request,
                        "Por favor revise la información diligenciada.")
                    form = PersonaForm(request.POST)
                    form2 = InscripcionForm(request.POST)

                elif (data_persona['tel_contacto'] ==
                      data_persona['telefono_acudiente']):
                    messages.error(
                        request,
                        "El número de contacto debe ser diferentes al del usuario"
                    )
                    form = PersonaForm(request.POST)
                    form2 = InscripcionForm(request.POST)

                elif (diferencia < 18
                      and data_persona['tipo_identificacion'] != 2):
                    messages.error(request,
                                   "Su tipo de documento es incorrecto")
                    form = PersonaForm(request.POST)
                    form2 = InscripcionForm(request.POST)

                else:
                    persona = form.save(commit=False)
                    inscripcion = form2.save(commit=False)
                    if (diferencia < 17):
                        persona.mayor_de_edad = False
                    else:
                        persona.mayor_de_edad = True

                    persona.telefono_acudiente = 0
                    if request.POST.get(
                            'solicitud_examen') == 'Deseo presentar examen':
                        inscripcion.sol_examen = True
                    else:
                        inscripcion.sol_examen = False

                    inscripcion.estado_inscripcion = False
                    inscripcion.cita_examen_creada = False
                    user = User.objects.create_user(
                        username=persona.num_identificacion,
                        email=persona.email,
                        password=persona.num_identificacion)
                    persona.usuario = user

                    assign_role(user, 'estudiante')
                    form.save()
                    persona_almacenada = Persona.objects.get(
                        num_identificacion=persona.num_identificacion)
                    inscripcion.persona = persona_almacenada
                    inscripcion.save()

                    alamacenamiento = agendar_inscripcion(inscripcion)

                    return redirect('index')
            except:
                messages.error(
                    request, "Por favor revise la información diligenciada.")
                form = PersonaForm(request.POST)
                form2 = InscripcionForm(request.POST)
        else:
            messages.error(request,
                           "Por favor revise la información diligenciada.")
            form = PersonaForm(request.POST)
            form2 = InscripcionForm(request.POST)
    else:
        form = PersonaForm(request.POST)
        form2 = InscripcionForm(request.POST)

    return render(request, 'inscripcion/user/inscripcion_form.html', {
        'form': form,
        'form2': form2
    })
def user_pre_save(sender, **kwargs):
    #sender is a user object
    user = kwargs.pop('instance')
    assign_role(user, 'visitor')
    print("visitor role assigned")
    def test_assign_invalid_role(self):
        user = self.user

        with self.assertRaises(RoleDoesNotExist):
            assign_role(user, 'no role')