예제 #1
0
def register(request):
    if(request.method == "POST"):
        form = SignUpForm(request.POST)
        
        if form.is_valid():
            form.save()
            print('SAVE already')
            u = User.objects.get(username=request.POST['username'])
            u.is_staff = True
            perms = get_permission(request.POST['perm'])
            print(perms)
            for perm in perms:
                permission = Permission.objects.get(codename=perm)
                u.user_permissions.add(permission)
            print('update permission already')

        else:
            print('testetewtew')
            return render(request, 'account/failformRegis.html')
    elif(request.method == "GET"):
        print("regisForm")
        form = SignUpForm()
        permission = ['add_blog','change_blog','delete_blog','add_comment','change_comment','delete_comment']
        return render(request, 'account/regisForm.html', {'form':form ,'permission': permission})

    return HttpResponseRedirect(reverse('blog:index'))
예제 #2
0
def register(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            #form.setdefault('is_staff', True)
            form.is_superuser = True
            form.is_active = True
            form.is_staff = True
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            if user is not None:

                if user.is_active:
                    login(request,user)
                    return redirect('/home')
                    return HttpResponse("login successful")
                else:
                    return HttpResponse("disabled account")
            else:
                return HttpResponse("invalid login")

            #login(request, user)
            
    else:
        form = SignUpForm()

    return render(request, 'account/index3.html', {'form': form})	
예제 #3
0
def test_sign_up_form_clear():
    form = SignUpForm()
    form.cleaned_data = {
        'password': '******',
        'password2': 'password',
        'phone': ''.join(i for i in FAKE.phone_number() if i.isdigit())[:10]
    }
    form.clean()
    form.save()
예제 #4
0
def signup_view(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('sendText:index')
    else:
        form = SignUpForm()
    return render(request, 'account/signup.html', {'form': form})
예제 #5
0
파일: views.py 프로젝트: sirakej/channels
def signup(request):
    print(request)
    if request.method == 'POST':
        print("passed")
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/accounts/login')
    else:
        print("failed")
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
예제 #6
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(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('/account/profile')
    else:
        form = SignUpForm()
    return render(request, 'registration/signup.html', {'form': form})
예제 #7
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = form.save()
            login(request,
                  user,
                  backend='django.contrib.auth.backends.ModelBackend')
            return redirect('main')
    else:
        form = SignUpForm()
    return render(request, 'account/index.html', {'form': form})
예제 #8
0
def edit(request, pk, template_name='home_data_user_edit.html'):
    data = get_object_or_404(User, pk=pk)
    form = SignUpForm(request.POST or None, instance=data)

    if form.is_valid():
        if form.cleaned_data.get('password1') == form.cleaned_data.get(
                'password2'):
            user = form.save()
            user.refresh_from_db()
            user.username = form.cleaned_data.get('username')
            user.first_name = form.cleaned_data.get('first_name')
            user.last_name = form.cleaned_data.get('last_name')
            user.email = form.cleaned_data.get('email')

            if form.cleaned_data.get('is_staff') == 'True':
                user.is_superuser = True
                user.is_staff = False
            else:
                user.is_superuser = False
                user.is_staff = True

            user.save()

        return redirect('home:data-user')

    return render(request, template_name, {'form': form})
예제 #9
0
def create(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)

        if form.is_valid():
            if form.cleaned_data.get('password1') == form.cleaned_data.get(
                    'password2'):
                user = form.save()
                user.refresh_from_db()
                user.username = form.cleaned_data.get('username')
                user.first_name = form.cleaned_data.get('first_name')
                user.last_name = form.cleaned_data.get('last_name')
                user.email = form.cleaned_data.get('email')

                if form.cleaned_data.get('is_staff') == 'True':
                    user.is_superuser = True
                    user.is_staff = False
                else:
                    user.is_superuser = False
                    user.is_staff = True

                user.save()

                return redirect('home:data-user')

    form = SignUpForm()
    return render(request, 'home_data_user_create.html', {'form': form})
예제 #10
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            mail_subject = 'فعالسازی حساب کاربری'
            message = render_to_string(
                'registration/activate_account.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()
            return render(request, 'registration/activation_confirm.html')
    else:
        form = SignUpForm()

    if request.user.is_authenticated:
        print(check_password('m1419844322', request.user.password))

    return render(request, 'registration/register.html', {'form': form})
예제 #11
0
def signup(request):
    status = False
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = status
            user.save()
            if status == False:  #IF ACTIVE STATUS FALSE IT WILL SEND MAIL TO THE USER TO ACTIVATE

                current_site = get_current_site(request)
                subject = 'Activate Your MySite Account'
                message = render_to_string(
                    'account/account_activation_email.html', {
                        'user': user,
                        'domain': current_site.domain,
                        'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                        'token': account_activation_token.make_token(user),
                    })
                user.email_user(subject, message)  #MAIL SEND HERE
                return render(request, 'account/account_activation_sent.html',
                              {'Title': 'Activate Account'})
            else:
                messages.success(request,
                                 "Your account is Created sucessfully..!")
                return redirect('login')
    else:  # redirect signup form
        form = SignUpForm()
    return render(request, 'account/signup.html', {
        'form': form,
        'Title': 'Sign up'
    })
예제 #12
0
파일: views.py 프로젝트: linckon/djangoblog
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(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)
            #add_blog_permission = Permission.objects.get(name='Can add blog post')
            #change_blog_permission = Permission.objects.get(name='Can change blog post')
            #user.user_permissions.add(add_blog_permission)
            #user.user_permissions.add(change_blog_permission)
            login(request, user)
            return redirect('/')
    else:
        form = SignUpForm()
    return render(request, 'account/signup.html', {'form': form})
예제 #13
0
def signup_view(request):
    context = {}
    if request.POST:
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            email = form.cleaned_data.get('email')
            raw_password = form.cleaned_data.get('password1')
            account = authenticate(email=email, password=raw_password)
            login(request, account)
            return redirect('home')
        else:
            context['signup_form'] = form
    else:
        form = SignUpForm()
        context['signup_form'] = form
    return render(request, 'account/signup.html', context)
예제 #14
0
파일: views.py 프로젝트: lazywhite/python
def signup(request):
    if request.method == 'POST':
        form1 = SignUpForm(request.POST)
        form2 = UserProfileForm(request.POST)
        if form1.is_valid() and form2.is_valid():
            form1.save()
            username = form1.cleaned_data.get('username')
            raw_password = form1.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            profile = form2.save(commit=False)
            profile.user = user
            profile.save()
            return redirect('account:profile')
    else:
        form1 = SignUpForm()
        form2 = UserProfileForm()
    return render(request, 'account/signup.html', {'form1': form1, 'form2':form2})
예제 #15
0
def register(request):
    form = SignUpForm()
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            user = authenticate(request, username=username, password=password)

            messages.success(
                request, f'Account created for {username}! You can now login.')
            login(request, user)
            return HttpResponseRedirect('/')

    context = {'form': form}

    return render(request, 'account/registration.html', context)
예제 #16
0
def signup(request):
    context = {"message": "You have reached the Sign up page."}
    context['form'] = SignUpForm()
    if request.method == "POST":
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            if user:
                login(request, user)
                return redirect("home")
        elif form.errors:
            context["errors"] = form.error_messages
            print(form.errors)
            print(form.error_messages)
    return render(request, 'signup.html', context)
예제 #17
0
def register(request):

    if request.method == 'POST':
        form = SignUpForm(request.POST)

        if form.is_valid():
            form.save()
            email = form.cleaned_data.get('email')
            raw_password = form.cleaned_data.get('password')
            user = authenticate(email='email', password='******')
            login(request, user)

            return redirect('/post')

    else:
        form = SignUpForm()

    return render(request, 'account/register.html', {'form': form})
예제 #18
0
def signup_view(request):
    login_form = AuthenticationForm()
    signup_form = SignUpForm()
    _form = request.POST.get('form_name')
    if _form == 'login_form':
        # Loging in user
        login_form = AuthenticationForm(request, request.POST)
        if login_form.is_valid():
            username = login_form.cleaned_data.get('username')
            password = login_form.cleaned_data.get('password')
            user = authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
                messages.success(request, f'User {user} is logged in .')
                return redirect('home')
        else:
            messages.warning(
                request,
                f'Invalid credentials!...Correct the errors on the form')
    if _form == 'signup_form':
        # Signing up user
        signup_form = SignUpForm(request.POST, request.FILES)
        if signup_form.is_valid():
            user = signup_form.save()
            user.category = request.POST.get('Catgy')
            user.student = request.POST.get('Std_cat')
            user.regNo = request.POST.get('Reg')
            user.lecturer = request.POST.get('Lect_cat')
            user.staffId = request.POST.get('Staff')
            user.college_council = request.POST.get('Col_council_cat')
            user.academic_council = request.POST.get('Acad_council_cat')
            user.school_council = request.POST.get('Skl_council_cat')
            user.department_council = request.POST.get('Dep_council_cat')
            user.school = request.POST.get('Skl')
            user.department = request.POST.get('Depart')
            user.level = request.POST.get('Lv')
            user.save()
            username = signup_form.cleaned_data.get('username')
            password = signup_form.cleaned_data.get('password1')
            user = authenticate(username=username, password=password)
            login(request, user)
            messages.success(request,
                             f'Account created succesfully for {username}')
            return redirect('home')
        else:
            messages.warning(
                request, f'User not created!...Correct the errors on the form')

    context = {
        'categories': Category.objects.all(),
        'signup_form': signup_form,
        'login_form': login_form
    }
    return render(request, 'signup.html', context)
예제 #19
0
def register(request):
    if (request.method == 'POST'):
        form = SignUpForm(request.POST)
        if (form.is_valid()):
            user = form.save()
            login(request, user)
            return redirect('/')
        else:
            return render(request, 'register.html', {'form': form})
    else:
        form = SignUpForm()
        return render(request, 'register.html', {'form': form})
예제 #20
0
def signup(request):
    if (request.user.is_authenticated):
        return redirect('home')
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            auth_login(request, user)
            return redirect('home')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
예제 #21
0
def signup(request):
    """ simple signup for users """
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            username, password = form.save()
            novice = authenticate(username=username, password=password)
            login(request, novice)
            return HttpResponseRedirect("/document/")
    else:
        form = SignUpForm()

    return render(request, "account/signup.html", {'form': form})
예제 #22
0
def signupadminview(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            messages.success(request,
                             'Congratulations...!! You have became an Admin')
            user = form.save()
            group = Group.objects.get(name='Admin')
            user.groups.add(group)
            return HttpResponseRedirect('/accounts/login')
    else:
        form = SignUpForm()
    context = {'form': form}
    return render(request, 'accounts/signupadmin.html', context)
예제 #23
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()
            user.grad_year = form.cleaned_data.get('grad_year')
            user.save()
            user.email_user(EMAIL_SUBJECT, EMAIL_CONTENT)
            account_login(request, user)
            return redirect('home')
    else:
        form = SignUpForm()
    return render(request, 'registration/signup.html', {'form': form})
예제 #24
0
파일: views.py 프로젝트: kis1992/aukcion2.0
 def post(self, request):
     print('user creation')
     queryset = models.BaseUser.objects.all()
     serializer_class = serializers.AccountSerializers
     renderer_classes = [TemplateHTMLRenderer]
     form = SignUpForm(request.POST)
     if form.is_valid():
         new_user = form.save()
         return Response({'new_user': new_user},
                         template_name='after_first_registration.html')
     else:
         print('user creation is failed')
         form = SignUpForm()
     return Response({'form': form}, template_name='registration.html')
예제 #25
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_form_db()
            user.profile.birth_date = form.cleaned_data_get('birth_date')
            user.save()
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=user.username, password=raw_password)
            login(request, user)
            return redirect('home')
    else:
        form = SignUpForm()
    return render(request, 'account/signup.html', {'form': form})
예제 #26
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db(
            )  # load the profile instance created by the signal
            user.save()
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=user.username, password=raw_password)
            login(request, user)
            return redirect('/books')
    else:
        form = SignUpForm
    return render(request, 'account/signup.html', {'form': form})
예제 #27
0
def signup_view(request):
    context = {}
    if request.POST:
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request,
                  user,
                  backend='django.contrib.auth.backends.ModelBackend')
            return redirect('home')
        else:
            context['form'] = form
    else:
        context['form'] = SignUpForm()
    return render(request, 'signup.html', context)
예제 #28
0
파일: views.py 프로젝트: yang121/PMDesk_web
def sign_up(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            return redirect('/index.html')

    else:
        form = SignUpForm()

    context = {
        'form': form,
    }

    return render(request, 'account/sign-up.html', context)
예제 #29
0
def signup(request):
    template_name = 'signup.html'
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()
            user.profile.phone = form.cleaned_data.get('phone')
            user.profile.token = account.verify.send_activation_email(
                request=request, user=user)
            user.save()
            return redirect('sign_up_success')
    else:
        form = SignUpForm()

    return render(request, template_name, {'form': form})
예제 #30
0
 def signup(request):
     form = None
     if request.method == 'POST':
         form = SignUpForm(request.POST)
         if form.is_valid():
             form_user = form.save(commit=False)
             user = User.objects.create_user(
                 username=form_user.username,
                 email=form_user.email,
                 password=form_user.password,
             )
             user.first_name = form_user.first_name
             user.last_name = form_user.last_name
             user.save()
             account = Account(user=user)
             account.save()
     return render(request, 'index.html', {'formSignUp': form})
예제 #31
0
def register(request):
    """Регистрация"""
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            if User.objects.filter(email=email).exists():
                messages.error(request,
                               'Пользователь с таким адресом уже существует')
            else:
                user = form.save()
                user.is_active = False
                current_site = get_current_site(request)
                mail_subject = 'Подтвердите регистрацию на ' + current_site.domain
                mail_from = base.EMAIL_HOST_USER
                mail_to = form.cleaned_data.get('email')
                template = os.path.join(
                    BASE_DIR, 'templates/registration/account_activate.html')
                html_message = render_to_string(
                    template, {
                        'user': user,
                        'domain': current_site.domain,
                        'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                        'token': account_activation_token.make_token(user),
                    })
                plain_message = strip_tags(html_message)
                send_mail(
                    mail_subject,
                    plain_message,
                    mail_from,
                    [mail_to],
                    html_message=html_message,
                )
                user.save()
                messages.success(
                    request,
                    'Вы успешно зарегестрировались. Вам осталось только подтвердить почту'
                )
                return redirect('/')
    else:
        form = SignUpForm
    template = os.path.join(BASE_DIR, 'templates/registration/signup.html')
    context = {'form': form}
    return render(request, template, context)