Exemple #1
0
def register(request):
    # Like before, get the request's context.
    context = RequestContext(request)
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        if user_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            registered = True
            new_user = authenticate(username=request.POST['username'],
                                    password=request.POST['password'])
            login(request, new_user)
            return HttpResponseRedirect('/profile/create')
        # Invalid form or forms - mistakes or something else?
        else:
            messages.success(request, user_form.errors)
            return HttpResponseRedirect('/signup/')

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()

    # Render the template depending on the context.
    return render_to_response(
            'base/signup.html',
            {'user_form': user_form, 'registered': registered},
            context)
    def post(self, request):
        user_form = UserForm(request.POST)

        if user_form.is_valid():
            user = user_form.save()
            confirmation_token = ConfirmationToken.objects.create(
                user=user, confirmation_key=secrets.token_hex(16))

            # Empilhando a task
            email_confirmacao.delay(
                confirmation_token.confirmation_key,
                user.id,
                user.email,
            )

            messages.success(request, 'Usuário cadastrado com sucesso.')

            return redirect('registration')

        messages.warning(request,
                         'Verifique todos os dados antes de prosseguir.')

        context = {
            "form": user_form,
        }
        return render(request, "core/registration.html", context)
Exemple #3
0
    def post(self, request):
        user_form = \
            UserForm(request.POST,
                     instance=self.request.user)
        profile_form = \
            UpdateUserProfileForm(request.POST,
                                  instance=self.request.user.profile)
        referral_form = \
            ReferralTokenForm(request.POST,
                              instance=self.request.user.referral_code.get())
        success_message = _('Profile updated with success')

        if user_form.is_valid() and \
                profile_form.is_valid():
            user_form.save()
            profile_form.save()
            # referral_form.save()
            messages.success(self.request, success_message)

            return redirect(reverse('core.user_profile'))
        else:
            ctx = {
                'user_form': user_form,
                'profile_form': profile_form,
                'referral_form': referral_form
            }

            return render(
                request,
                'core/user_profile.html',
                ctx,
            )
Exemple #4
0
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = LandlordForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            profile = profile_form.save()
            profile.save()
            user = user_form.save()
            user.set_password(user.password)
            user.landlord_profile = profile
            user.save()

            registered = True

        else:
            print(user_form.errors, profile_form.errors)

    else:
        user_form = UserForm()
        profile_form = LandlordForm()

    return render(request, 'user_management/register_landlord.html',
                  {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
def save_data(request):
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            sid = request.POST.get("sid")
            name = request.POST['name']
            mobile = request.POST['mobile']
            password = request.POST['password']
            if sid == "":
                usr = UserModel(name=name, mobile=mobile, password=password)
            else:
                usr = UserModel(id=sid,
                                name=name,
                                mobile=mobile,
                                password=password)

            usr.save()
            stu = UserModel.objects.values()
            student_data = list(stu)
            return JsonResponse({
                "status": "saved",
                'student_data': student_data
            })
        else:
            return JsonResponse({"status": 0})
Exemple #6
0
    def post(self, request, **kwargs):
        # create a form instance and populate it with data from the request:
        form = UserForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            attendee = None
            message = None
            try:
                possible_match = Attendee.objects.get(
                    name=form.cleaned_data['name'])
            except ObjectDoesNotExist:
                return render(request, 'core/history.html', {
                    'form': form,
                    'msg': "No user with this name"
                })

            if possible_match.token == form.cleaned_data['token']:
                attendee = possible_match
            else:
                return render(request, 'core/history.html', {
                    'form': form,
                    'msg': "Wrong token"
                })

            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            return render(request, 'core/history.html', {
                'form': form,
                'attendee': attendee
            })
Exemple #7
0
def register(request):
	context = RequestContext(request)
	registered = False

	if request.method == 'POST':
		user_form = UserForm(data=request.POST)

		if user_form.is_valid():

			user = user_form.save()

			user.set_password(user.password)
			user.save()


		else:
			print user_form.errors

	else:

		user_form = UserForm()

	return render_to_response(
			'base/register.html',
			{'user_form': user_form, 'registered': registered}, 
			context)
Exemple #8
0
def register(request):
    context = RequestContext(request)
    msg = []

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        if user_form.is_valid():
            password = request.POST['password']
            password_repeat = request.POST['password_repeat']
            if password == password_repeat:
                user = user_form.save()
                user.set_password(user.password)
                user.userextension.ip = getIP(request)
                user.userextension.save()
                user.userextension.participated_lans.add(getCurrentLAN())
                user.save()
                user = authenticate(username=user.username, password=password)
                auth_login(request, user)
                return HttpResponseRedirect(reverse('home'))
            else:
                msg.append("Passwörter sind verschieden!")
        else:
            msg.append(
                "Benutzername enthält ungültige Zeichen oder ist schon vergeben!")
    else:
        user_form = UserForm()
    return render_to_response('register.html', {'errors': msg, 'user_form': user_form}, context_instance=context)
Exemple #9
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form_new = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        if user_form_new.is_valid() and profile_form.is_valid():
            user = user_form_new.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']
            profile.save()
            registered = True
        else:
            print user_form.errors, profile_form.errors
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
    context = {
        'user_form': user_form,
        'profile_form': profile_form,
        'registered': registered
    }
    template = loader.get_template('auth/register.html')
    return HttpResponse(template.render(context, request))
Exemple #10
0
def register(request):
    # Like before, get the request's context.
    context = RequestContext(request)

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set commit=False.
            # This delays saving the model until we're ready to avoid integrity problems.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render_to_response(
            'base/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
            context)
Exemple #11
0
def add_new_person(request):
	user = User()
	user_form = UserForm(request.POST or None)
	if user_form.is_valid():
		user = user_form.save()
		return redirect(people) 
	messages.warning(request, u', '.join(user_form.errors))
	return render(request, 'add_new_person.html', {'form':user_form})
Exemple #12
0
def add_new_person(request):
    user = User()
    user_form = UserForm(request.POST or None)
    if user_form.is_valid():
        user = user_form.save()
        return redirect(people)
    messages.warning(request, u', '.join(user_form.errors))
    return render(request, 'add_new_person.html', {'form': user_form})
Exemple #13
0
def new_user(request):
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.save()
            return HttpResponseRedirect('/users')
    else:
        form = UserForm()
    return render(request,'users/new_user.html', {'form':form})
Exemple #14
0
 def post(self, request, *args, **kwargs):
     user_form_class = UserForm(request.POST, prefix="user_form")
     campaign_form_class = CampaignForm(request.POST,
                                        prefix="campaign_form")
     if user_form_class.is_valid() and campaign_form_class.is_valid():
         return HttpResponseRedirect('/')
     return render(request, self.template_name, {
         'user_form': user_form_class,
         'campaign_form': campaign_form_class
     })
Exemple #15
0
def profile(request, template='core/profile.html'):
    up = get_object_or_404(UserProfile, for_user=request.user.id)
    form = UserForm(request.POST or None, instance=request.user)
    if form.is_valid():
        form.save()
        messages.info(request, u'Your changes have been saved.')

    return render_to_response(template,
        {'profile': up,
         'profile_form': form},
         context_instance=RequestContext(request))
Exemple #16
0
    def test_valid_user_form(self):
        form_data = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'first_name': 'Nikola',
            'last_name': 'Nikolic'
        }

        form = UserForm(data=form_data)
        self.assertTrue(form.is_valid())
Exemple #17
0
    def test_invalid_user_form(self):
        form_data = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'first_name': 'Milan',
            # last name is required
        }

        form = UserForm(data=form_data)
        self.assertFalse(form.is_valid())
def resolve_login(
    obj: None, info: GraphQLResolveInfo, email: Optional[str] = None
) -> Optional[Token]:
    request = info.context["request"]
    if not request.user.is_authenticated and email:
        try:
            user: Optional[User] = User.objects.get(email=email)
        except User.DoesNotExist:
            form = UserForm({"email": email})
            user = form.save() if form.is_valid() else None
        if user:
            login(request, user)
    if request.user.is_authenticated:
        token, _ = Token.objects.get_or_create(user=request.user)
        return token
    return None
def user_edit(request, uuid):
    profile_object = get_object_or_404(UserProfile, uuid=uuid)
    user_object = profile_object.user
    if request.method == "POST":
        uform = UserForm(data=request.POST, instance=user_object)
        pform = UserProfileForm(data=request.POST, instance=profile_object)
        if uform.is_valid() and pform.is_valid():
            user = uform.save()
            profile = pform.save(commit = False)
            profile.user = user
            profile.save()
            return HttpResponseRedirect(reverse('core.views.user', args=(uuid,)))
    else:
        uform = UserForm(instance=user_object)
        pform = UserProfileForm(instance=profile_object)
        
    return render_to_response('core/edit_user.html', {'profile_user': user_object, 'uform': uform, 'pform': pform}, context_instance=RequestContext(request))
Exemple #20
0
def settings_edit(request):
    user = request.user
    profile = user.get_profile()
    old_image = profile.logo_file
    address = profile.address

    if request.method == 'POST':
        userform = UserForm(request.POST, prefix="user", instance=user)
        profileform = UserProfileForm(request.POST, request.FILES, prefix="profile", instance=profile)
        if request.POST.get('profile-register'):
            profileform.fields['registration_city'].required = True
        if request.POST.get('profile-registration_city'):
            profileform.fields['register'].required = True
        addressform = AddressForm(request.POST, prefix="address", instance=address)

        if userform.is_valid() and profileform.is_valid() and addressform.is_valid():
            if request.FILES:
                try:
                    if old_image:
                        if os.path.exists(old_image.path):
                            os.remove(old_image.path)
                except:
                    pass
            userform.save()
            profile = profileform.save()
            address = addressform.save(commit=False)
            address.save(user=user)
            messages.success(request, _('Your settings have been updated successfully'))
            if profile.creation_date > datetime.date.today():
                messages.warning(request, _("Creation date is in the future, is this normal ?"))
            return redirect(reverse('settings_edit'))
        else:
            messages.error(request, _('Data provided are invalid'))
    else:
        userform = UserForm(prefix="user", instance=user)
        profileform = UserProfileForm(prefix="profile", instance=profile)
        addressform = AddressForm(prefix="address", instance=address)

    return render_to_response('core/settings_edit.html',
                              {'active': 'account',
                               'title': _('Settings'),
                               'userform': userform,
                               'profileform': profileform,
                               'addressform': addressform,
                               'logo': user.get_profile().logo_file},
                              context_instance=RequestContext(request))
Exemple #21
0
 def get(self, request, *args, **kwargs):
     user_form_class = UserForm(prefix="user_form")
     campaign_form_class = CampaignForm(prefix="campaign_form")
     context = {
         'user_form': user_form_class,
         'campaign_form': campaign_form_class
     }
     return render(request, self.template_name, context)
def update_user(request, user_id=None):
    user = get_object_or_404(User, id=user_id)

    if request.POST:
        form = UserForm(request.POST, instance=user)
        if form.is_valid():
            user = form.save()
            user.save()
            return redirect(user)
    else:
        form = UserForm(instance=user)

    variables = {
        'pagetitle': 'Rediger profil',
        'form': form,
    }

    return render(request, 'user_form.html', variables)
Exemple #23
0
def settings_edit(request):
    user = request.user
    profile = user.get_profile()
    old_image = profile.logo_file
    address = profile.address

    if request.method == 'POST':
        userform = UserForm(request.POST, prefix="user", instance=user)
        profileform = UserProfileForm(request.POST,
                                      request.FILES,
                                      prefix="profile",
                                      instance=profile)
        if request.POST.get('profile-register'):
            profileform.fields['registration_city'].required = True
        if request.POST.get('profile-registration_city'):
            profileform.fields['register'].required = True
        addressform = AddressForm(request.POST,
                                  prefix="address",
                                  instance=address)

        if userform.is_valid() and profileform.is_valid(
        ) and addressform.is_valid():
            if request.FILES:
                try:
                    if old_image:
                        if os.path.exists(old_image.path):
                            os.remove(old_image.path)
                except:
                    pass
            userform.save()
            profile = profileform.save()
            address = addressform.save(commit=False)
            address.save(user=user)
            messages.success(request,
                             _('Your settings have been updated successfully'))
            if profile.creation_date > datetime.date.today():
                messages.warning(
                    request,
                    _("Creation date is in the future, is this normal ?"))
            return redirect(reverse('settings_edit'))
        else:
            messages.error(request, _('Data provided are invalid'))
    else:
        userform = UserForm(prefix="user", instance=user)
        profileform = UserProfileForm(prefix="profile", instance=profile)
        addressform = AddressForm(prefix="address", instance=address)

    return render_to_response('core/settings_edit.html', {
        'active': 'account',
        'title': _('Settings'),
        'userform': userform,
        'profileform': profileform,
        'addressform': addressform,
        'logo': user.get_profile().logo_file
    },
                              context_instance=RequestContext(request))
Exemple #24
0
def add_user(request):

    form = UserForm(request.POST or None)

    if form.is_valid():

        username = request.POST['username']
        first_name = request.POST['first_name']
        last_name = request.POST['last_name']
        email = request.POST['email']
        password = request.POST['password']
        cpassword = request.POST['confirm_password']

        if helper.is_unique(username):

            User.objects.create_user(username, email, password, first_name=first_name, last_name=last_name)

            user = User.objects.get(username=username)

            if cpassword != password:
                return HttpResponse("passwords do not match")

            Profile.objects.create(
                user=user,
                first_name=first_name,
                last_name=last_name,
                email=email,
                address=request.POST['address'],
                user_type=request.POST['user_type']
            )

            messages.success(request, 'User added!')
            return redirect('core:index')

        else:

            messages.add_message(request, messages.ERROR, 'Username is already taken')
            return redirect('core:add_user')

    context = {'form': form}
    return render(request, 'core/add_user.html', context)
Exemple #25
0
    def post(self,request):

        data = request.POST
        user_form = UserForm(data=data)
        user_profile_form = UserProfileForm(data=data)
        if user_form.is_valid() and user_profile_form.is_valid():

            user_object = user_form.save(commit=False)
            user_object.set_password(user_object.password)
            user_object.save()

            user_prof_object = user_profile_form.save(commit=False)
            user_prof_object.user = user_object
            user_prof_object.save()

            return HttpResponseRedirect('/accounts/login/?message=Registration successfull, Please login with your credentials')
        context = {
            'user_profile_form':user_profile_form,
            'user_form': user_form
        }
        return render(request,'registration/registration.html',context)
Exemple #26
0
def register(request):

    if request.method=='POST':
        userform = UserForm(data=request.POST)
        genresList = request.POST.getlist('genres')
        if userform.is_valid():
            newUser = userform.save(commit=False)
            newUser.latitude = request.POST.get('latitude')
            newUser.longitude = request.POST.get('longitude')
            newUser.save()
            for g in genresList:
                #print(g)
                newUser.favGenres.connect(Genre.nodes.get(name=g))
            return message(request,'Registered successfully! You can login to proceed.')
        else:
            print(userform.errors)
            return message(request,'Error in registering. Please try again.')
    else:

        #createGenreNodes(request)
        user = request.user
        if user.is_authenticated:
            return message(request, 'You are already logged in.')
        else:
            userform = UserForm()
            genreNodes = Genre.nodes
            return render(request,'core/register.html',{'userform':userform,'genreNodes':genreNodes})
Exemple #27
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            if 'profile_pic' in request.FILES:
                print('found it')
                profile.profile_pic = request.FILES['profile_pic']
            profile.save()
            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(
        request, 'core/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemple #28
0
def register(request):
    #A boolean value is added to tell the template
    #whether the registration was successful
    #Initially it is set to False. It will change
    #to True when registration succeeds.
    registered = False

    #if it's a HTTP POST, processing of form data should done :D.
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)

        if user_form.is_valid():
            user = user_form.save()

            #saving the password after hashing wtih the set_password method
            user.set_password(user.password)
            user.save()

            #Updating variable to indicate that the template
            #registration was successful
            registered = True
        else:
            #Invalid form - mistaken something?
            #lets Print the problem
            print(user_form.errors)
    else:
        #Not a HTTP POST? render the form again :D
        user_form = UserForm()

    #Render the template with context
    return render(request, 'register.html', {
        'user_form': user_form,
        'registered': registered
    })
Exemple #29
0
    def post(self, request):

        data = request.POST
        user_form = UserForm(data=data)
        user_profile_form = UserProfileForm(data=data)
        if user_form.is_valid() and user_profile_form.is_valid():

            user_object = user_form.save(commit=False)
            user_object.set_password(user_object.password)
            user_object.save()

            user_prof_object = user_profile_form.save(commit=False)
            user_prof_object.user = user_object
            user_prof_object.save()

            return HttpResponseRedirect(
                '/accounts/login/?message=Registration successfull, Please login with your credentials'
            )
        context = {
            'user_profile_form': user_profile_form,
            'user_form': user_form
        }
        return render(request, 'registration/registration.html', context)
Exemple #30
0
def create_account(request):
    if request.POST:
        form = UserForm(request.POST)
        if form.is_valid():
            user = form.save()
            authenticated_user = authenticate(username=user.username, password=request.POST['password'])            
            login(request, authenticated_user)
            return render_to_response('index.html', {
                    'login_succeeded': True
                    }, context_instance=RequestContext(request))        
        else:
            return render_to_response(
                'create_account.html',
                {'form': form},
                context_instance=RequestContext(request)
                )
    else:
        form = UserForm()
        return render_to_response(
            'create_account.html',
            {'form': form},
            context_instance=RequestContext(request)
            )
Exemple #31
0
def register(request):
    form = UserForm()
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            school = form.save()
            return redirect(reverse('school', subdomain=school.username))

    return render(request, 'register.html', {'form': form})
Exemple #32
0
def update(request):
    school = get_object_or_404(User, username=request.subdomain)
    form = UserForm(instance=school)
    if request.method == 'POST':
        form = UserForm(request.POST, instance=school)
        if form.is_valid():
            school = form.save()
            return redirect(reverse('school', subdomain=school.username))

    return render(request, 'update.html', {'form': form})
Exemple #33
0
def form_user(request):
    datos = {
        'form':UserForm()
    }
    if request.method == 'POST':
        formulario = UserForm(request.POST)
        if formulario.is_valid():
            formulario.save()
            datos['mensaje'] = "Datos guardados correctamente"
    return render(request, 'registro.html', datos)
Exemple #34
0
def registrar(request):
    if request.user.is_authenticated():
        return redirect("core_home")
    form = UserForm()
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            user = form.save()
            return redirect("core_home")
    return render(request, "core/registrar.html", {'form': form })
Exemple #35
0
def candidate_register(request):
    """
    A function to dispose the sign up detail for a candidate.
    """
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserCandidateForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.is_candidate = True
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()
            """
            Reference for using this:
            https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method
            """
            profile_form.save_m2m()

            registered = True

            new_user = authenticate(
                email=user_form.cleaned_data['email'],
                password=user_form.cleaned_data['password'],
                key="UserLogIn")

            login(request, new_user)

            return redirect(reverse('core:dashboard'))

        else:
            print(user_form.errors, profile_form.errors)

    else:

        user_form = UserForm()
        profile_form = UserCandidateForm()

    return render(
        request, 'core/candidate_registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemple #36
0
    def get(self, request):
        user_form = UserForm(instance=self.request.user)
        profile_form = UpdateUserProfileForm(
            instance=self.request.user.profile)
        referral_form = ReferralTokenForm(
            instance=self.request.user.referral_code.get())

        ctx = {
            'user_form': user_form,
            'profile_form': profile_form,
            'referral_form': referral_form
        }

        return render(
            request,
            'core/user_profile.html',
            ctx,
        )
Exemple #37
0
def professor_register(request):
    """
    The function to dispose the sign up detail for a professor.
    """
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfessorForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():

            user = user_form.save()
            user.is_professor = True
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            registered = True

            new_user = authenticate(
                email=user_form.cleaned_data['email'],
                password=user_form.cleaned_data['password'],
                key="UserLogIn")

            login(request, new_user)

            return redirect(reverse('core:dashboard'))

        else:
            print(user_form.errors, profile_form.errors)

    else:

        user_form = UserForm()
        profile_form = UserProfessorForm()

    return render(
        request, 'core/professor_registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemple #38
0
def core_profile(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=request.user)
        profile_form = ProfileForm(request.POST, instance=request.user.profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            messages.success(request, 'Your profile was successfully updated!')
            return redirect('core_index')
        else:
            messages.error(request, 'Please correct the error below.')
    else:
        user_form = UserForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)

    return render(request, 'core_profile_edit.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
Exemple #39
0
def manage_user(request, user_id=None):
    # Try to locate the object to use it as an instance and if not, create a new one
    # to use it in a new form.
    # common_data = common_ticket_data()
    if request.user.is_superuser:
        if user_id:
            actual_user = get_object_or_404(User, pk=user_id)
        else:
            actual_user = User()
    else:
        if user_id and int(user_id) == request.user.id:
            actual_user = get_object_or_404(User, pk=user_id)
        else:
            raise Http404
    # POST mode
    if request.method == 'POST':
        form = UserForm(request.POST,
                        request.FILES,
                        request=request,
                        instance=actual_user)
        if form.is_valid():
            temp_form = form.save(commit=False)
            # If no modifications were made to password fields...
            if (not form.cleaned_data["password_first"]
                    and not form.cleaned_data["password_check"]
                ) and form.instance.pk is not None:
                pass
            else:
                # Validated by models, once password_check is cleaned, we proceeed updating password...
                temp_form.set_password(form.cleaned_data["password_check"])
            temp_form.save()
            form.save_m2m()
            return redirect('user-list')
    else:
        # Non-POST mode, show only
        form = UserForm(instance=actual_user, request=request)
    return render(request, 'core/users/create_edit_user.html', locals())
Exemple #40
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        if user_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            registered = True
        else:
            print(user_form.errors)
    else:
        user_form = UserForm()
    return render(request, 'core/registration.html', {
        'user_form': user_form,
        'registered': registered
    })
Exemple #41
0
def create_account(request):
    if request.POST:
        form = UserForm(request.POST)
        if form.is_valid():
            user = form.save()
            authenticated_user = authenticate(
                username=user.username, password=request.POST['password'])
            login(request, authenticated_user)
            return render_to_response('index.html', {'login_succeeded': True},
                                      context_instance=RequestContext(request))
        else:
            return render_to_response('create_account.html', {'form': form},
                                      context_instance=RequestContext(request))
    else:
        form = UserForm()
        return render_to_response('create_account.html', {'form': form},
                                  context_instance=RequestContext(request))
Exemple #42
0
def entrar(request):
    form = UserForm(request.POST or None)
    if request.method == "POST":
        if form.is_valid:
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
                return redirect('home')

            else:
                #return HttpResponseRedirect('/gerente/entrar/')
                context = {
                    'form': form,
                }
                return render(request, 'core/login.html', context)
        else:
            pass
    else:
        context = {
            'form': form,
        }
        return render(request, 'core/login.html', context)