コード例 #1
0
def signup(request):
    if request.method == 'POST':
        f = CustomUserCreationForm(request.POST)
        if f.is_valid():
            f.save()
            messages.success(request, 'Account created successfully')
            username = f.cleaned_data['username']
            raw_password = f.cleaned_data['password1']
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            profile, create = BloggerProfile.objects.get_or_create(user=request.user, pk=request.user.pk)
            if create is True:
                profile.email = f.cleaned_data['email']
                profile.save()
            print('profile.name-->', profile.name)
        else:
            messages.info(request,"Something went wrong please fill out the details once more. THank you!")
            return redirect(reverse('accounts:signup'))
            # send_mail(subject, message, from_email, to_list, fail_silently=True)
        subject = 'We thank you for signing up'
        message = 'YOu have successfully signed up!./n Thank you for joining us!./n YOu will get an email to setup your password very very soon...'
        from_email = EMAIL_HOST_USER
        to_list = [f.cleaned_data['email'], '*****@*****.**', ]
        send_mail(subject, message, from_email, to_list, fail_silently=True)
        print('email is just sent')
        return redirect('/posts/')
    else:
        f = CustomUserCreationForm()

    return render(request, 'accounts/signup.html', {'form': f})
コード例 #2
0
def register(request):
    form = CustomUserCreationForm()
    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect(reverse('register'))
    return render(request, 'accounts/register.html', {'form': form})
コード例 #3
0
def register(request):
    if request.POST:
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('login')
    else:
        form = CustomUserCreationForm()
    return render(request, 'registration/register.html', {"form": form})
コード例 #4
0
def register_view(request):
    form = CustomUserCreationForm()
    if request.method == "POST":
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            print("USer successfully registered")
            return redirect(reverse('register'))
    return render(request, 'registration/register.html', {'form': form})
コード例 #5
0
def register(request):
    form = CustomUserCreationForm()
    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            user = form.cleaned_data.get('username')
            messages.success(request, 'Account was created for ' + user)
            return redirect('login')
    return render(request, 'accounts/register.html', {'form': form})
コード例 #6
0
def index(request):
    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('articles:index')
    else:
        form = CustomUserCreationForm()
    context = {
        'form': form,
    }
    return render(request, 'articles/index.html', context)
コード例 #7
0
def signup(request):
    if request.method == 'POST':
        form = CustomUserCreationForm(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 redirect('app', path='')
    else:
        form = CustomUserCreationForm()
    return render(request, 'registration/signup.html', {'form': form})
コード例 #8
0
def signup(request):
    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('blog:index')
    else:
        form = CustomUserCreationForm()

    context = {
        'form': form
    }
    return render(request, 'registration/signup.html', context)
コード例 #9
0
def signup(request):
    if request.method == 'POST':
        oldform = UserCreationForm(request.POST)
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            #messages.success(request, 'Account created successfully')
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('home')
    else:
        form = CustomUserCreationForm()
    return render(request, 'signup.html', {'form': form})
コード例 #10
0
def create_members(request):

    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = CustomUserCreationForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            user = form.save()
            user.is_staff = True
            user.company = request.user.company
            user.groups.clear()
            group = Group.objects.get(name='tenant_staff')
            group.user_set.add(user)
            user.save()
            return HttpResponseRedirect('/orgs/companies/members/')

    # if a GET (or any other method) we'll create a blank form
    else:
        form = CustomUserCreationForm()

    return render(request, 'org/create_members.html', {'form': form})
コード例 #11
0
ファイル: test_forms.py プロジェクト: Tamerz/bandfollow
 def test_form_saves_user(self):
     form = CustomUserCreationForm(data={
         'username': '******',
         'name': 'Jimmy Jazz',
         'email': '*****@*****.**',
         'password1': 'youneverknow8',
         'password2': 'youneverknow8'
     })
     new_user = form.save()
     self.assertEqual(new_user, User.objects.first())
     self.assertEqual(new_user.username, 'jjazz')
     self.assertEqual(new_user.name, 'Jimmy Jazz')
     self.assertEqual(new_user.email, '*****@*****.**')
コード例 #12
0
ファイル: views.py プロジェクト: igenedev1/project
def postUser(request):
    if request.method == "POST":
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            user = form.save(commit=True)
            print(user.igene_id)
            data = UserSerializer(User.objects.all(), many=True).data
            return JsonResponse({"result": data}, safe=False)

        else:
            data = json.loads(form.errors.as_json())
            return JsonResponse({"errors": data}, status=400, safe=False)

    return JsonResponse({"result": "success"})
コード例 #13
0
ファイル: views.py プロジェクト: DrinkChosun/DrinkChosun
def signup(request):
    if request.user.is_authenticated:
        return redirect('articles:index')
    
    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            auth_login(request, user)
            return redirect('articles:index')
    
    else:
        form = CustomUserCreationForm()
    context = {
        'form': form,
    }
    return render(request, 'accounts/signup.html', context)
コード例 #14
0
ファイル: views.py プロジェクト: hossamelneily/nexchange
def user_registration(request):
    template = 'accounts/user_registration.html'
    success_message = _('Registration completed. Check your phone '
                        'for SMS confirmation code.')
    error_message = _('Error during accounts. <br>Details: {}')

    if request.method == 'POST':
        user_form = CustomUserCreationForm(request.POST)
        profile_form = UserProfileForm(request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            try:
                with transaction.atomic(using='default'):
                    user = user_form.save(commit=False)
                    user.username = str(profile_form.cleaned_data['phone'])
                    user.save()

                    profile_form = UserProfileForm(request.POST,
                                                   instance=user.profile)
                    profile = profile_form.save(commit=False)
                    profile.disabled = True
                    profile.save()
                    send_auth_sms(user)

                    messages.success(request, success_message)

                user = authenticate(
                    request=request,
                    username=user.username,
                    password=user_form.cleaned_data['password1'])
                login(request, user)
                return redirect(reverse('accounts.user_profile'))

            except Exception as e:
                msg = error_message.format(e)
                messages.error(request, msg)

    else:
        user_form = CustomUserCreationForm()
        profile_form = UserProfileForm()

    return render(request, template, {
        'user_form': user_form,
        'profile_form': profile_form
    })
コード例 #15
0
def register(request):
    print(request.POST)
    if "cancel" in request.POST:
        return redirect('accounts:list_user')
    form = CustomUserCreationForm(request.POST or None, request.FILES or None)
    if request.method == 'POST':
        if form.is_valid():
            user = form.save(commit=False)
            user.save()
            if user is not None:
                return redirect('accounts:list_user')

        else:
            messages.error(request, 'Please correct the error below.')
    context = {
        "form": form,
    }
    return render(request, 'accounts/register.html', context)
コード例 #16
0
def user_register(request):
    if request.user.is_authenticated:
        return redirect('ticket:index')
    form = CustomUserCreationForm(request.POST or None)
    if request.method == 'POST':
        if form.is_valid():
            username = form.cleaned_data.get('username')
            user = form.save()
            return JsonResponse({
                'status':
                True,
                'message':
                f'{username}, cadastrado com sucesso',
            })
        else:
            return JsonResponse({
                'status': False,
                'message': form.errors.as_json(),
            })
    context = {'form': form}
    return render(request, 'accounts/user/register.html', context)
コード例 #17
0
def register(request):

    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        form.help_text = ''
        profileForm = UserProfileForm(request.POST)

        if form.is_valid() and profileForm.is_valid():
            user = form.save()
            profile = profileForm.save(commit=False)
            profile.user = user
            profile.save()
            messages.success(request, 'You are register can login in now')
            return redirect('login')
    else:
        form = CustomUserCreationForm()
        profileForm = UserProfileForm()
    context = {
        'form': form,
        'profileForm': profileForm,
    }
    return render(request, 'accounts/register.html', context)
コード例 #18
0
ファイル: views.py プロジェクト: nikmalviya/Event-Management
def signup(request):
    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            subject = 'Activate Your EventManagement Account'
            message = render_to_string(
                'registration/account_activation.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(
                        user.pk)).decode(),
                    'token': account_activation_token.make_token(user),
                })
            user.email_user(subject, message)
            return redirect('account_activation_sent')
    else:
        form = CustomUserCreationForm()
    return render(request, 'signup.html', {'form': form})
コード例 #19
0
ファイル: views.py プロジェクト: michaeldg7/LessonsOnVideo
def account_signup(request, template_name='accounts/signup.html'):
    """
    Displays a form that allows the users to signup.
    """
    form = CustomUserCreationForm()
    if request.method == "POST":
        form = CustomUserCreationForm(data=request.POST)
        if form.is_valid():
            new_user = form.save()
            # user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password1'])
            # if user is not None:
            #     if user.is_active:
            #         login(request, user)
            #         return HttpResponseRedirect(reverse("home"))
            token = generate_random_str()
            reg_token = RegistrationToken.objects.create(user=new_user, token=token)

            headers = {"From": "LessonsOnVideo"}
            subject = "LessonsOnVideo Registration Activation"
            sender = settings.EMAIL_FROM
            cont = {
                'user': new_user.email,
                'host': "http://%s" % request.get_host(),
                'link': reverse('registration-complete', args=(new_user.username, token))
            }
            email_content = render_to_string("accounts/email/activation_email.txt", cont)

            # send registration email
            #send_mail(subject, email_content, sender, [new_user.email], fail_silently=False)
            msg = EmailMessage(subject, email_content, sender, [new_user.email], headers=headers)
            msg.send()
            return HttpResponseRedirect(reverse('registration-confirm'))
    context = {
        "form": form
    }
    return render_to_response(template_name, context, RequestContext(request))