コード例 #1
0
ファイル: views.py プロジェクト: remontees/EliteHebergPanel
def inscription(request):
    if request.method == "POST":
        form = UserForm(request.POST)

        if form.is_valid():
            # On sauvegarde le nouveau membre
            form.save()

            # On envoie un mail pour dire qu'il a bien envoyé sa requête d'inscription !
            sujet = _("Inscription à Eliteheberg")
            mail = _(
                "Bonjour. Vous avez bien demandé un compte d'hébergement sur Eliteheberg. Nous vous contacterons bientôt pour vous indiquer votre espace d'hébergement. Merci."
            )
            try:
                send_mail(mail, "*****@*****.**", form.email)

                txtmessage = _("Votre inscription a bien été enregistrée.")
                messages.add_message(request, messages.SUCCESS, txtmessage)
            except BadHeaderError:
                return HttpResponse(status=500)

            # On le redirige vers l'accueil (pour l'instant une erreur 404)
            return redirect("home.views.home", {"form": UserForm()})
    else:
        form = UserForm()

    return render(request, "home/inscription.html", {"form": form})
コード例 #2
0
def profile(request):
    if request.method == "POST":
        userform = UserForm(request.POST, instance=request.user)
        user_profile = UserProfile.objects.get(user=request.user)
        userprofileform = UserProfileForm(request.POST, instance=user_profile)
        try:
            pilot = Pilot.objects.get(user=request.user)
            pilotform = PilotProfileForm(request.POST, instance=pilot)
            pilot_valid = pilotform.is_valid()
            if pilot_valid:
                pilotform.save()
        except ObjectDoesNotExist:
            pilotform = None
            pilot_valid = True
        user_valid = userform.is_valid()
        user_profile_valid = userprofileform.is_valid()
        if pilot_valid and user_valid and user_profile_valid:
            change = "Changes Submitted"
            print("PILOT SAVED!")
        else:
            print("PILOT INVALID")
        if user_valid:
            userform.save()
            print("User SAVED!")
        if user_profile_valid:
            userprofileform.save()
            user_profile = UserProfile.objects.get(user=request.user)
            request.session["django_timezone"] = user_profile.timezone
            print("User Profile Saved!")
        else:
            print("USER INVALID")

    else:
        try:
            pilot = Pilot.objects.get(user=request.user)
            pilotform = PilotProfileForm(instance=pilot)
        except ObjectDoesNotExist:
            pilotform = None
        userform = UserForm(instance=request.user)
        userprofile = UserProfile.objects.get(user=request.user)
        userprofileform = UserProfileForm(instance=userprofile)
        change = ""

    return render(
        request,
        "home/profile.html",
        {
            "userform": userform,
            "change": change,
            "pilotform": pilotform,
            "userprofileform": userprofileform,
        },
    )
コード例 #3
0
def add_user(request):
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return HttpResponseRedirect('/school')
    else:
        form = UserForm()
    return render(request, 'home/signup.html', {'form': form})
コード例 #4
0
ファイル: views.py プロジェクト: Abhishek553/Agape-Web
def register(request):

    print(request.POST)
    if request.method == 'POST':
        form = UserForm(request.POST)
        print(form)
        if form.is_valid():
            form.save()

        return redirect('login')
    else:
        form = UserForm()

    return render(request, "register/register.html", {'form': form})
コード例 #5
0
ファイル: views.py プロジェクト: Jay-gupta/Django_tutorial
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,'home/registration.html',
                          {'user_form':user_form,
                           'profile_form':profile_form,
                           'registered':registered})
コード例 #6
0
def register(request):

    registered = False

    if request.method == 'POST':

        # Get info from "both" forms
        # It appears as one form to the user on the .html page
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        # Check to see both forms are valid
        if user_form.is_valid() and profile_form.is_valid():

            # Save User Form to Database
            user = user_form.save()

            # Hash the password
            user.set_password(user.password)

            # Update with Hashed password
            user.save()

            # Now we deal with the extra info!

            # Can't commit yet because we still need to manipulate
            profile = profile_form.save(commit=False)

            # Set One to One relationship between
            # UserForm and UserProfileInfoForm
            profile.user = user

            # Check if they provided a profile picture
            if 'profile_pic' in request.FILES:
                print('found it')
                # If yes, then grab it from the POST form reply
                profile.profile_pic = request.FILES['profile_pic']

            # Now save model
            profile.save()

            # Registration Successful!
            registered = True
        else:
            # One of the forms was invalid if this else gets called.
            print(user_form.errors, profile_form.errors)

    else:
        # Was not an HTTP post so we just render the forms as blank.
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    # This is the render and context dictionary to feed
    # back to the registration.html file page.
    return render(
        request, 'home/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
コード例 #7
0
ファイル: views.py プロジェクト: srivastava9/Codefundo-2019
def registered(request):
    registered = False
    if request.method == "POST":
        print(request.POST)
        print(request.FILES)
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(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
            profile.save()
            registered = True
            login(request, user)
            return redirect("/home/user-demand")

        else:
            # user_errors = user_form.errors
            # profile_errors = profile_form.errors
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(
        request,
        "registration/registration_form.html",
        {
            "user_form": user_form,
            "profile_form": profile_form,
            "registered": registered,
        },
    )
コード例 #8
0
def register(request):
    registered = True
    if request.method == "POST":

        userform = UserForm(data=request.POST)
        userInfo = UserProfileInfoForm(data=request.POST)
        if userform.is_valid() and userInfo.is_valid():

            user_data = userform.save(commit=False)
            user_data.set_password(user_data.password)

            userprofile = userInfo.save(commit=False)
            user_data.save()
            userprofile.user = user_data
            userprofile.save()
            registered = False
        else:
            return render(
                request, 'signin.html', {
                    'registered': registered,
                    'userform': userform,
                    'userinfoform': userInfo
                })

    userform = UserForm
    userinfoform = UserProfileInfoForm
    return render(
        request, 'signin.html', {
            'registered': registered,
            'userform': userform,
            'userinfoform': userinfoform
        })
コード例 #9
0
ファイル: views.py プロジェクト: spektion/ABD_trab
def sign_in(request):

    # Set to False initially. registered changes value to True when registration succeeds.
    registered = False

    # Se for um POST estamos a processar dados que vêm do REQUEST.
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)

        # Se o formulário vem bem preenchido...
        if user_form.is_valid():
            user = user_form.save()

            # set_password encripta a password enviada para colocar na BD.
            user.set_password(user.password)
            user.save()

            # Agora sim, o registo ficou feito e gravado.
            registered = True

        else:
            # They'll also be shown to the user.
            print user_form.errors

    #Nao sendo um post, estão a pedir o Formulário para preenchimento de um novo user
    else:
        user_form = UserForm()

    # Render the template depending on the context.
    return render(request,
            'sign_in.html',
            {'user_form': user_form, 'registered': registered} )
コード例 #10
0
def update_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()
            return HttpResponseRedirect('/')
        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, 'home/profile.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
コード例 #11
0
def signup(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST)
        profile_form = ProfileForm(request.POST)
        print('40 = ', profile_form.errors.as_data())
        print('41 = ', user_form.errors.as_data())
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            print('test')
            return render(request, 'home/home.html')
    else:
        user_form = UserForm()
        profile_form = ProfileForm
    context = {'user_form': user_form, 'profile_form': profile_form}
    template = 'home/signup.html'
    return render(request, template, context)
コード例 #12
0
ファイル: views.py プロジェクト: Tetrix/Slavic-Mythology
def register(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(request,
            'home/registration/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered} )	
コード例 #13
0
    def test_valid_data(self):
        form = UserForm({
            'username': "******",
            'email': "*****@*****.**",
            'password': "******",
        })

        self.assertTrue(form.is_valid())
        user = form.save()
        self.assertEqual(user.name, "Turanga Leela")
        self.assertEqual(user.email, "*****@*****.**")
        self.assertEqual(user.password, "Hi 2513698514258there")
コード例 #14
0
ファイル: views.py プロジェクト: Wannesvp/Sport-Club
def update_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 succesfully updated!')
            return redirect('/profile/')
        else:
            messages.error(request, 'Please correct the error bellow')
    else:
        user_form = UserForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)
    context = {
        'user_form': user_form,
        'profile_form': profile_form
    }
    return render(request, 'home/update_profile.html', context)

    
コード例 #15
0
def register(request):
    registered = False
    if request.method == 'GET':
        # display registration form
        user_form = UserForm()
    elif request.method == 'POST':
        user_form = UserForm(data=request.POST)
        if user_form.is_valid():
            user = user_form.save()
            user.set_password(user_form.cleaned_data['password'])
            user.save()
            registered = True
            logger.info('User %s registered', user.username)
        else:
            logger.error(user_form.errors)
    return render(request, 'register.html', locals())
コード例 #16
0
def signup_page(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, 'home/signup.html', {'user_form': user_form, 'registered': registered})
コード例 #17
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()

            return render(request, 'home/login.html', {'user_form': user_form})
        else:
            print(user_form.errors)
            return render(request, 'home/registration.html',
                          {'user_form': user_form})
    else:
        user_form = UserForm()
        return render(request, 'home/registration.html',
                      {'user_form': user_form})
コード例 #18
0
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(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
            profile.save()

            registered = True
        else:
            print(user_form.errors, profile_form.errors)

    return HttpResponse("Registered")
コード例 #19
0
def sign_up(request):
    # Set to False initially. registered changes value to True when
    # registration succeeds.
    registered = False
    
    # Se for um POST estamos a processar dados que vem do REQUEST.
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        
        # Se o formulario vem bem preenchido...
        if user_form.is_valid():
            user = user_form.save()
            
            # set_password encripta a password enviada para colocar na BD.
            user.set_password(user.password)
            user.save()
            
            # adicionar o utilizador ao grupo "site_user"
            site_user_group = Group.objects.get(name='site_users')
            site_user_group.user_set.add(user)
            
            # verificar se ficou OK, i.e. se o utilizador pertence ao grupo
            if user.groups.filter(name="site_users").count():
                print("user added to group")
                
            # Agora sim, o registo ficou feito e gravado.
            registered = True
            
        else:
            # Os erros sao passados ao user tb, mas esta parte imprime na linha de comando.
            print user_form.errors
            
    #Nao sendo um post, estao a pedir o Formulario para preenchimento de um novo user
    else:
        user_form = UserForm()
        
    # Render the template depending on the context.
    return render(request,
                  'sign_up.html',
                  {'user_form': user_form, 'registered': registered} )
コード例 #20
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:
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()

            registered = True

            return render(
                request, 'home/registration.html', {
                    'user_form': user_form,
                    'profile_form': profile_form,
                    'registered': registered
                })
        else:
            my_dict = {'register_alert': "User Already Registered"}
            return render(request, 'home/login.html', context=my_dict)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
        return render(
            request, 'home/registration.html', {
                'user_form': user_form,
                'profile_form': profile_form,
                'registered': registered
            })
コード例 #21
0
def register(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)

        # If the forms are valid...
        if user_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()
            # 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

    # 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(request, 'auth/register.html', {
        'user_form': user_form,
        'registered': registered
    })
コード例 #22
0
def view_profile(request):
    user = request.user
    user_form = UserForm(instance=user)

    ProfileInlineFormset = inlineformset_factory(User, UserProfile, can_delete=False,
                                                 fields=('description', 'address', 'education', 'phone', 'image'))
    formset = ProfileInlineFormset(instance=user)

    if request.user.is_authenticated and request.user.id == user.id:
        if request.method == "POST":
            user_form = UserForm(request.POST, request.FILES, instance=user)
            formset = ProfileInlineFormset(request.POST, request.FILES, instance=user)

            if user_form.is_valid():
                created_user = user_form.save(commit=False)
                formset = ProfileInlineFormset(request.POST, request.FILES, instance=created_user)

                if formset.is_valid():
                    created_user.save()
                    formset.save()
                    return redirect('view_profile')

        try:
            progress = Progress.objects.get(user=request.user)
            achievements = json.loads(progress.all_quiz_records)
            achievements = achievements.get('all_records')
        except Progress.DoesNotExist:
            achievements = None

        return render(request, "home/profile.html", {
            'user': user,
            "noodle_form": user_form,
            "formset": formset,
            'achievements':achievements,
        })

    else:
        raise PermissionDenied
コード例 #23
0
def admin(request):
    registered = False
    admin_auth_key = "jrk898989#"
    error = False
    error_value = ""
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        inp_admin_ac = request.POST.get('id_admin_auth')
        inp_confirm_pass = request.POST.get('id_password_confirm')
        if(inp_admin_ac == admin_auth_key):
                       

            if(inp_confirm_pass == request.POST.get('password')):

                if user_form.is_valid():
                    user = user_form.save()
                    user.set_password(user.password)
                    user.save()
                    registered = True
                else:
                    error=True
                    error_value = user_form.errors
                    print(error_value)
            else:
                error=True
                error_value = "Password are not matching"
                print(error_value)

        else:
            error=True
            error_value = "Invalid Auth Code"      
            print(error_value)
        return render(request,'home/admin.html',{'userform':user_form,'registered':registered,'error':error,'error_value':error_value})
    else:
        userform = UserForm()
        return render(request,'home/admin.html',{'userform':userform,'registered':registered,'error':error,'error_value':error_value})
コード例 #24
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)

            # Did the user provide a group?
            # If so, we need to get it from the post and put it in the User model, empty otherwise.
            user.groups.add(request.POST.get('group', ''))

            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

            # Register this user to all candidate questions
            registerNewUserToAllCandidateQuestions(user)

        # 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(
        'home/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        }, context)