コード例 #1
0
ファイル: utils.py プロジェクト: Anych/shop
def _profile(user):
    """
    Create an User Profile
    """
    profile = UserProfile()
    profile.user_id = user.id
    profile.save()
コード例 #2
0
ファイル: views.py プロジェクト: Angshumaan/greatkart-django
def register(request):
    if request.method == "POST":
        # request.post will contain all the field values
        form = RegistrationForm(request.POST)
        if form.is_valid(
        ):  # if form has all the required field and validations
            # fetching all field from request.pOSt
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            email = form.cleaned_data['email']
            phone_number = form.cleaned_data['phone_number']
            password = form.cleaned_data['password']
            # if email is [email protected] we will get only basu coz indexing is 0
            username = email.split('@')[0]
            user = Account.objects.create_user(first_name=first_name,
                                               last_name=last_name,
                                               email=email,
                                               username=username,
                                               password=password)
            # we did like this coz phone_number argument is not specified in create_user
            user.phone_number = phone_number
            user.save()

            # create user profile
            profile = UserProfile()
            profile.user_id = user.id
            profile.profile_picture = 'default/default-user.png'
            profile.save()

            # User activation
            current_site = get_current_site(request)
            mail_subject = 'Please activate your account'
            message = render_to_string(
                'accounts/account_verification_email.html', {
                    'user': user,
                    'domain': current_site,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': default_token_generator.make_token(user),
                })
            to_email = email
            send_email = EmailMessage(mail_subject, message, to=[to_email])
            send_email.send()
            # messages.success(
            #     request, 'Thank you for registering with us.We have sent you an verification email.Please Verify it')
            return redirect('/accounts/login/?command=verification&email=' +
                            email)
    else:
        form = RegistrationForm()

    context = {
        'form': form,
    }
    return render(request, 'accounts/register.html', context)
コード例 #3
0
ファイル: view.py プロジェクト: blx666/MyBlog
def loadfile(request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            adminuser = User.objects.get(id=1)
            newuser = UserProfile()
            newuser.avatar = form.cleaned_data['userpic']
            newuser.user_id = adminuser.id
            newuser.accepted_eula = True
            newuser.favorite_animal = '*****@*****.**'
            newuser.save()
            return HttpResponse('ok!')
        else:
            return HttpResponse('parameters is wronngs!')