Exemple #1
0
def edit_profile(request):
    u = request.user
    edit = False
    if request.is_ajax() and request.method == 'POST':
        old_password = request.POST.get('old_password')
        user = authenticate(username=u.username, password=old_password)
        # If we have a User object, the details are correct.
        # If None (Python's way of representing the absence of a value), no user
        # with matching credentials was found.
        if user:
            user_form = UserForm(data=request.POST, instance=u)
            if user_form.is_valid():
                user = user_form.save()
                user.set_password(user.password)
                user.player = u.player
                update_session_auth_hash(request, user)
                if 'profile_picture' in request.FILES:
                    user.player.profile_picture = request.FILES['profile_picture']
                user.save()
                edit = True
            return HttpResponse(json.dumps({'edit' : edit, 'errors' : user_form.errors }), content_type="application/json")
        else:
            return HttpResponse(json.dumps({ 'password_error' : "Incorrect password" }), content_type="application/json")
    else:
        return render(request, '/game/', {})
Exemple #2
0
def register(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 the two forms are valid...
                if user_form.is_valid():
                    # Save the user's form data to the database.
                    confirm_password = request.POST.get('confirm_password')
                    password = request.POST.get('password')
                    user = user_form.save()
                    if confirm_password == password:
                        user.set_password(user.password)
                        user.save()
                        registered = True
                        s = Status.objects.get_or_create(user=user)[0]
                        s.save()
                        return render(request, 'game/login.html')
                    else:
                     return HttpResponse("Password not match!")
                else:
                    return HttpResponse("User already exist or invalid email!")
            # Not a HTTP POST, so we render our form using two ModelForm instances.
            # These forms will be blank, ready for user input.
            else:
                     if request.user.is_authenticated():
                           logout(request)
                           return render(request, 'game/home.html')
                     else:
                        user_form = UserForm()
                        return render(request,
                            'game/register.html',
                            {'user_form': user_form, 'registered': registered} )
Exemple #3
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)

        # If the two 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()

            # create account
            a = Account.objects.get_or_create(user=user)[0]
            pic_id = random.randrange(1,5,1)
            a.picture = 'media/portraits/' + str(pic_id) + '.png'
            a.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:
            return render_to_response(
                'home/index.html',
                {'user_form': user_form, 'errors': user_form.errors},
                context)

    # 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(
        'home/index.html',
        {'user_form': user_form, 'registered': registered},
        context)
Exemple #4
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        # print(user_form)
        profile_form = UserProfileInfoForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            # our_user = UserProfileInfo(user = user_form.save(),indicesList = "'NDVI':'(nir-r)/(nir+r)'")
            # print(our_user)
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            # our_user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            # userInfo = UserProfileInfo.objects.all()
            # print(userInfo)
            profile.save()
            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(
        request, 'registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemple #5
0
def register(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 the two forms are valid...
        if user_form.is_valid():
            # Save the user's form data to the database.
            confirm_password = request.POST.get('confirm_password')
            password = request.POST.get('password')
            user = user_form.save()
            if confirm_password == password:
                user.set_password(user.password)
                user.save()
                registered = True
                s = Status.objects.get_or_create(user=user)[0]
                s.save()
                return render(request, 'game/login.html')
            else:
                return HttpResponse("Password not match!")
        else:
            return HttpResponse("User already exist or invalid email!")
    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        if request.user.is_authenticated():
            logout(request)
            return render(request, 'game/home.html')
        else:
            user_form = UserForm()
            return render(request, 'game/register.html', {
                'user_form': user_form,
                'registered': registered
            })
Exemple #6
0
def register(request):
    # use this to decide what to show in html
    registered = False
    # get the user input
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        # Save data
        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 '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()

    return render(
        request, 'game/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemple #7
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

            # log user in
            login(request, user)
            return HttpResponseRedirect(reverse('index'))

        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(
        request, 'registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemple #8
0
def register(request):
    context = RequestContext(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
            
            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()
        
    return render_to_response(
        'game/register.html',
        {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
        context)
Exemple #9
0
def register(request):
    error = 'noerror'
    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.is_active = False
            user.save()
            #email verifiation
            current_site = get_current_site(request)
            mail_subject = 'Activate your blog account.'
            message = render_to_string(
                'acc_active_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(
                        user.pk)).decode(),
                    'token': account_activation_token.make_token(user),
                })
            to_email = user_form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()
            #set extra data to UserProfileInfo
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()
            return HttpResponse(
                '<br><br><center><h1>Please confirm your email address to complete the registration.</h1><br><h2 style="color: red">Please Check your SPAM folder for verification Mail.</h2></center>'
            )
        else:
            error = "error"
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(request, 'game/login/register.html', {
        'user_form': user_form,
        'profile_form': profile_form,
        'error': error
    })
Exemple #10
0
def registerUser(request):
    #Funktio on lähes kokonaan kopioitu www.tangowithdjango.com/ tutoriaalista

    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():
            # 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)

            #KOMMENTOI POIS SEURAAVAT KAKSI RIVIÄ, JOS ET HALUA ERIKSEEN AKTIVOIDA ACCOUNTTIA!
            user.is_active = False
            sendConfirmEmail(user)

            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.
    if not registered:
        return render(request, 'register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
        })
    else:
        return render(
            request, 'message.html', {
                'title':
                "Thank you for registering!",
                'message':
                "Please check you email in order to activate the account.",
            })