コード例 #1
0
    def generate_data(apps, schema_editor):
        from django.contrib.auth.models import User
        from home.models import Profile
        user_test_data = [
            ('Rebecca', 'RebeccaRebecca', '*****@*****.**', 'F'),
            ('Danit', 'DanitDanit', '*****@*****.**', 'F'),
            ('Aviv', 'AvivAviv', '*****@*****.**', 'M'),
            ('Ido', 'IdoIdo', '*****@*****.**', None),
        ]

        with transaction.atomic():
            # Test: Create a User and Profile from a User via username.
            for username, password, email, gender in user_test_data:
                user = User.objects.create_user(username=username,
                                                password=password,
                                                email=email)
                if gender:
                    Profile(user=user, gender=gender).save()
                else:
                    Profile(user=user).save()
            # Test: Create a Profile with user who was updated to superuser (admin)
            user = User.objects.create_superuser(
                username='******', password='******',
                email='*****@*****.**').save()
            Profile(user=user).save()
            # Test: Update a profile to be blocked.
            profile = Profile.objects.get(user=User.objects.get(
                username="******"))
            profile.is_blocked = True
            profile.save()
コード例 #2
0
ファイル: views.py プロジェクト: Alvina96/Django
def registrationuser(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()

            username = form.cleaned_data.get('username')
            email = form.cleaned_data.get('email')
            raw_password = form.cleaned_data.get('password')

            user = User.objects.get(username=username)
            person_create = Profile(user_id=user.id)
            # person_create.save()
            user = authenticate(username=username, password=raw_password)
            messages.success(request, "Check Your Email")
            subject, from_email, to = 'Confirm account', '*****@*****.**', email
            text_content = 'Confirm pleas your account.'
            html_content = '<p>Click  this link <a href=http://127.0.0.1:8000/confirm/' + username + '>Confirm</a> and activate your account.</p>'
            msg = EmailMultiAlternatives(subject, text_content, from_email,
                                         [to])
            msg.attach_alternative(html_content, "text/html")
            msg.send()
    else:
        form = SignUpForm()
    return render(request, 'home/home.html')
コード例 #3
0
def register(request):
    if request.method == 'POST':
        form = UserRegisterForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            messages.success(request, f'Account created for {username}.')
            u = User.objects.filter(username=username)
            prof = Profile(user=u[0],
                           name=None,
                           country=None,
                           city=None,
                           age=None,
                           sex=None)
            prof.save()
            return redirect('login')
    else:
        form = UserRegisterForm()
    return render(request, 'registration/register.html', {'form': form})
コード例 #4
0
def handlesignup(request):
    if request.method == 'POST':
        username = request.POST['username']
        email = request.POST['email']
        pass1 = request.POST['pass1']
        pass2 = request.POST['pass2']
        if len(username) > 12:
            messages.error(request, 'User name must be under 12 characters')
            return redirect('student')
        if not username.islower():
            messages.error(request, 'User name must be in lowercases')
            return redirect('student')
        if not username.isalnum():
            messages.error(request,
                           'User name must contain letters and numbers')
            return redirect('student')
        if pass1 != pass2:
            messages.error(request, 'your password is not matched correctly')
            return redirect('student')

        myuser = User.objects.create_user(username, email, pass1)
        # myuser.save()
        fname = request.POST['fname']
        lname = request.POST['lname']
        roll = request.POST['roll']
        address = request.POST['address']
        branch = request.POST['branch']
        info = Profile(username=myuser,
                       roll=roll,
                       address=address,
                       branch=branch,
                       fname=fname,
                       lname=lname)
        info.save()
        messages.success(request, 'your account has been successfully created')
        return redirect('student')

    else:
        return HttpResponse('Not allowed')
コード例 #5
0
    def generate_data(apps, schema_editor):
        from django.contrib.auth.models import User
        from home.models import Profile

        with transaction.atomic():
            # Create Blocked user profile
            user = User.objects.create_user(username='******',
                                            password='******',
                                            email='*****@*****.**')
            blockedProfile = Profile(user=user)
            blockedProfile.is_blocked = True
            blockedProfile.save()

            # Create Admin superuser profile
            superuser = User.objects.create_superuser(
                username='******', password='******',
                email='*****@*****.**').save()
            Profile(user=superuser).save()
コード例 #6
0
ファイル: views.py プロジェクト: Pockemonchik/abitur
def reg(request):
    regform = UserRegisterForm(request.POST)
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')

        if regform.is_valid():
            try:
                newuser = User.objects.create_user(
                    regform.cleaned_data.get('username'), None,
                    regform.cleaned_data.get('password'))

                newuser.save()
                profile = Profile()
                profile.user = newuser
                profile.nomer = request.POST.get('password')
                profile.familiya = newuser.username
                newuser.save()
                profile.save()
                login(request, newuser)
                return HttpResponseRedirect(reverse('index'))
            except:
                return render(request, 'error.html',
                              {'content': "Произошла ошибка при регистрации"})

        else:
            print(regform.errors)
            return render(request, 'error.html', {
                'content':
                "Произошла ошибка при регистрации, ошибка в форме"
            })

    else:
        form = UserLoginForm()
        regform = UserRegisterForm()
        return render(request, 'login.html', {
            'form': form,
            'regform': regform
        })
コード例 #7
0
ファイル: utils.py プロジェクト: sauloantuness/bang
def set_profile(backend, response, user, is_new=False, *args, **kwargs):
    from home.models import Profile    
    profile = Profile.objects.filter(email=email(backend, response)).first()

    if not profile:
        profile = Profile()

    if backend.name == 'facebook':
            profile.name = response['name']
            profile.picture = 'http://graph.facebook.com/{0}/picture'.format(response['id'])
            profile.facebookId = response['id']
            profile.email = response['email']

    elif backend.name == 'google-oauth2':
        profile.name = response['displayName']
        profile.picture = response['image']['url'].split('?')[0]
        profile.email = response['emails'][0]['value']

    profile.user = user
    profile.save()
コード例 #8
0
def profile():
    profile = Profile.create(username="******",
                             password="******",
                             email="*****@*****.**")
    return profile