예제 #1
0
def frontpage(request):
    if request.user.is_authenticated:
        return redirect("/" + "profile.html" + "/")
    else:
        if request.method == "POST":
            if "signupform" in request.POST:
                signupform = SignupForm(data=request.POST) 
                signinform =  SigninForm()

                if signupform.is_valid():
                    username = signupform.cleaned_data["username"]
                    password = signupform.cleaned_data["password1"]
                    signupform.save()
                    user = authenticate(username=username, password=password)
                    login(request, user)
                    return redirect("/")
                else:
                    signinform = SigninForm(data=request.POST)
                    signupform = SigninForm()

                    if signinform.is_valid():
                        login(request, signinform.get_user())
                        return redirect("/")

            else:
                signupform = SigninForm()
                signinform = SigninForm()

            return render(request, "frontpage.html", {"signupform": signupform, "signinform": signinform})
예제 #2
0
    def post(self, request, encoded_email, encrypted_hash):
        encoded_email = encoded_email.replace("slash", "/")
        data = {}

        for key, value in request.POST.items():
            data[key] = value

        # disabled fields are ignored by django forms
        data["email"] = decode_data(
            config("SIGNUP_EMAIL_ENCODING_SECRET"), encoded_email
        ).decode("utf-8")
        form = SignupForm(data)

        if form.is_valid():
            form.save()
            username = form.cleaned_data.get("username")
            password = form.cleaned_data.get("password1")
            user = authenticate(username=username, password=password)
            login(request, user)
            return redirect("after_login")
        else:
            return render(
                request,
                self.template,
                {"form": form, "email": form.cleaned_data.get("email")},
            )
예제 #3
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        form.save()
        flash(u'Check your email to confirm registration.', 'success')
        return redirect(url_for('pages_app.index'))
    return render_template('accounts/signup.html', form=form)
예제 #4
0
    def post(self, request):
        form = SignupForm(request.POST)

        if form.is_valid():
            form.save()

            return redirect('home')

        return render(request, 'signup.html', {'form':form})
예제 #5
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        form.save()
        flash(
            u'Successfully registered',
            'success'
        )
        return redirect(url_for('accounts_app.login'))
    return render_template('accounts/signup.html', form=form)
예제 #6
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect(reverse('home'))
    else:
        form = SignupForm()
        args = {'form': form}
    return render(request, 'accounts/signup.html', args)
예제 #7
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        form.save()
        flash(
            u'Check your email to confirm registration.',
            'success'
        )
        return redirect(url_for('pages_app.index'))
    return render_template('accounts/signup.html', form=form)
예제 #8
0
파일: views.py 프로젝트: priyambansal/SIH
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/account/register')
    else:
        form = SignupForm()

        args = {'form': form}
        return render(request, 'accounts/signup_form.html', args)
예제 #9
0
파일: views.py 프로젝트: ctascy/askdjango
def signup(request):
    if request.method =="POST":
        form = SignupForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/')
    else:
        form = SignupForm()
    return render(request, 'accounts/signup.html',{
        'form':form
    })
예제 #10
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request, data=request.POST)
        if form.is_valid():
            form.save()
            return redirect('accounts.signup_done')
    else:
        form = SignupForm(request)
    return render(request, 'accounts/signup.j.html', {
        'form': form
    })
예제 #11
0
def signup(request):
    if request.method== 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect(settings.LOGIN_URL)
    else:
        form = SignupForm()
    return render(request, 'accounts/signup.html', {
        'form':form,
        })
예제 #12
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect(settings.LOGIN_URL)
    else:
        form = SignupForm()
    return render(request, 'accounts/signup.html', {
        'form': form,
    })
예제 #13
0
파일: views.py 프로젝트: lamiru/pystagram
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, 'Successfully registered!')
            next_url = request.GET.get('next', 'blog:index')
            return redirect(next_url)
    else:
        form = SignupForm()
    return render(request, 'form.html', {
        'form': form,
    })
예제 #14
0
def signup(request):
    template = 'signup.html'
    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('index')
    else:
        form = SignupForm
    return render(request, template, {'form':form})
예제 #15
0
def signup(request):
    if request.method == 'POST':
        signupField = SignupForm(request.POST)
        if signupField.is_valid():
            signupField.save()
            # next_url = request.GET.get('next', '')
            # return redirect(settings.LOGIN_URL + '?next=' + next_url)
            return redirect(reverse('blog:list') + '?complete')
    else:
        signupField = SignupForm()

    return render(request, 'accounts/signup.html', {
        'viewModel' : signupField,
    })
예제 #16
0
def signup(request):
    form = SignupForm(request.POST or None)
    if form.is_valid():
        form.save()
        username = form.cleaned_data.get('email')
        password = form.cleaned_data.get('password')
        user = auth.authenticate(username=username, password=password)
        redirect_url = 'login'
        if user:
            auth.login(request, user)
            redirect_url = settings.LOGIN_REDIRECT_URL
        return redirect(redirect_url)
    ctx = {'form': form}
    return TemplateResponse(request, 'accounts/signup.html', ctx)
예제 #17
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
#        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/')
            #return render(request, 'accounts/profile.html')
            #return render(request, 'accounts/login.html')
            #return render(request, '/index.html')
    else:
        form = SignupForm()
    return render(request, 'accounts/signup.html' , {'form': form,
    })
예제 #18
0
def register(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/accounts/login')
        else:
            print("did not work")
            form = SignupForm()
            args = {'form': form}
            return render(request, 'accounts/signup.html', args)
    else:
        form = SignupForm()
        args = {'form': form}
        return render(request, 'accounts/signup.html', args)
예제 #19
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            form.save()

            messages.success(request, '회원가입 되었습니다.')

            next_url = request.GET.get('next', 'blog:index') # url reverse 기능
            return redirect(next_url)
    else:
        form = SignupForm()
    return render(request, 'form.html', {
        'form': form,
    })
예제 #20
0
    def post(self, request):
        form = SignupForm(request.POST)

        if form.is_valid():
            form.save()

            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')

            user = authenticate(username=username, password=password)

            login(request, user)

            return redirect('home')
        else:
            return render(request, 'accounts/signup.html', {'form': form})
예제 #21
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save()

            # backend_cls = get_backends()[0].__class__
            # backend_path = backend_cls.__module__ + '.' + backend_cls.__name__
            # https://github.com/django/django/blob/1.9/django/contrib/auth/__init__.py#L81
            # user.backend = backend_path

            authenticated_user = authenticate(
                    username=form.cleaned_data['username'],
                    password=form.cleaned_data['password1'])

            auth_login(request, authenticated_user)

            messages.info(request, '환영합니다. ;)')
            return redirect(settings.LOGIN_REDIRECT_URL)

            # 회원가입 시에, 이메일 승인
            # user = form.save(commit=False)
            # user.is_active = False
            # user.save()
            # send_signup_confirm_email(request, user)
            # return redirect(settings.LOGIN_URL)
    else:
        form = SignupForm()
    return render(request, 'accounts/signup.html', {
        'form': form,
    })
예제 #22
0
파일: auth.py 프로젝트: bookpark/FC-Project
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 = '[Zinzi] 이메일 인증'
            html_message = render_to_string('user_activate.html', {
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': urlsafe_base64_encode(force_bytes(user.token)),
            })
            to_email = form.cleaned_data['email']
            email = EmailMultiAlternatives(
                mail_subject,
                html_message,
                to=[to_email],
            )
            email.attach_alternative(html_message, 'text/html')
            email.send()
            return HttpResponse('이메일 인증을 위해 이메일을 확인해주십시오.')
    else:
        form = SignupForm()
    return render(request, 'accounts/signup.html', {'form': form})
예제 #23
0
파일: views.py 프로젝트: ckdgus0204/site
def signup(request):
    """signup
    to register users
    """
    if request.method == "POST":
        signupform = SignupForm(request.POST)
        if signupform.is_valid():
            signupform.save()

            return redirect('home')
    elif request.method == "GET":
        signupform = SignupForm()

    return render(request, "signup.html", {
        "signupform": signupform,
    })
예제 #24
0
파일: views.py 프로젝트: jungkeuny/jklog
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, '회원가입 되었습니다.')

            # next_url = request.GET.get('next', 'blog.views.index')
            next_url = reverse("django.contrib.auth.views.login") + "?next="
            + request.GET.get("next", "")  # 가입 후 로그인 들렀다가 redirect
            return redirect(next_url)
    else:
        form = SignupForm()
    return render(request, 'form.html', {
        'form': form,
        })
예제 #25
0
def register(request):  # ou appeler  signin
    if request.method == 'POST':  # save
        form = SignupForm(request.POST)
        if form.is_valid():  # si valide  alors save
            user = form.save(commit=False)  # save le new user  mais sans login
            user.is_active = False
            user.save()
            site = get_current_site(request)
            mail_subject = 'confirmation message for foueds site '
            message = render_to_string(
                'accounts/registration/confirm_email.html', {
                    'user': user,
                    'domain': site.domain,
                    'uid': user.id,
                    'token': activation_token.make_token(user)
                })
            to_email = form.cleaned_data.get('email')
            to_list = [to_email]
            from_email = settings.EMAIL_HOST_USER
            recipient_list = [to_email]
            send_mail(mail_subject,
                      message,
                      from_email,
                      recipient_list,
                      fail_silently=True)
            return redirect('/accounts/register/activate_mail_sent')

    else:  # show form
        form = SignupForm()
    return render(request, 'accounts/registration/register.html',
                  {'form': form})
예제 #26
0
파일: views.py 프로젝트: sirkp/phdadmission
def signup(request):
    """
    backend for signup, sends activation mail to user
    This view is linked with phdadmission/accounts/templates/accounts/signup.html
    """
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user_email = request.POST['email']
            user = form.save(commit=False)
            user.is_active = False
            user.username = user_email
            user.save()
            current_site = get_current_site(request)
            message = render_to_string(
                'acc_active_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            mail_subject = 'Activate your IIT Ropar PhD Portal account.'
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()
            return HttpResponse(
                'Please confirm your email address to complete the registration. To login go back to  Homepage'
            )
    else:
        form = SignupForm()
    return render(request, 'accounts/signup.html', {'form': form})
예제 #27
0
def signup(request):
	regist_terms=Texts.objects.get(name="regist_terms")
	privacy_info_terms=Texts.objects.get(name="privacy_info_terms")
	if request.method=="POST":
		userform = SignupForm(request.POST)
		if userform.is_valid():
			user = userform.save(commit=False)
			user.username = userform.cleaned_data['username']
			user.save()
			profile = Profile(user=user)
			profile.save()
			return HttpResponseRedirect(reverse("signup_ok"))	
		return render(request, "accounts/signup.html", {
			'userform': userform,
			'message':'입력정보를 정확히 확인해주세요.',
			'regist_terms':regist_terms.contents,
			'privacy_info_terms':privacy_info_terms.contents,
		})
	elif request.method=="GET":
		userform = SignupForm()
		return render(request, "accounts/signup.html", {
			'userform':userform,
			'message':'첫 화면',
			'regist_terms':regist_terms.contents,
			'privacy_info_terms':privacy_info_terms.contents,
		})
예제 #28
0
def signup_view(request):
    if request.method == "POST":  # Check if it is a POST request
        form = SignupForm(request.POST)  # Pass the data from the POST request

        # Check if the form is valid
        if form.is_valid():
            # Save the user's data to the database
            user = form.save(
                commit=False)  # Wait until the user has confirmed their email
            user.last_login = timezone.now()  # Update the last login field
            user.is_active = False
            user.save()

            # Send a confirmation email to the user
            to_email = form.cleaned_data.get("email")
            csrf_token = get_token(request)

            current_site = get_current_site(request).domain
            path = str(reverse_lazy("accounts:send-activate-account-email"))
            confirm_email_url = "http://" + current_site + path

            try:
                requests.post(
                    confirm_email_url,
                    data={
                        "csrfmiddlewaretoken": csrf_token,
                        "to_email": to_email
                    },
                    cookies={
                        "csrftoken": csrf_token
                    })  # Sends a request to the confirmation email page
            except requests.exceptions.ConnectionError as e:
                if confirm_email_url[7:17] == "testserver":
                    # This is a test; ignore any errors that may arise
                    pass
                else:
                    raise e

            # Report to the log that a user has just signed up
            logger.info(
                f"A new user '{User.objects.get(email=to_email).username}' just signed up."
            )

            # Redirect user to the "please confirm your email" page
            return render(
                request, "accounts/webpages/account_activation.html", {
                    "page_type": "confirm email",
                    "confirm_email_url": confirm_email_url,
                    "email_address": to_email
                })

        else:
            logger.info("A person tried to sign up but checks failed.")

    else:  # This is a GET request
        form = SignupForm()  # Define a user creation form

    return render(request, "accounts/webpages/signup.html",
                  {"form": form})  # Send the form to the template
예제 #29
0
파일: views.py 프로젝트: sonhaechang/church
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST, request.FILES)
        if form.is_valid():
            user = form.save()
            django_login(request, user) # 로그인 처리
            return redirect(settings.LOGIN_URL)
    else:
        form = SignupForm()
    return render(request, 'accounts/signup_form.html', {'form': form,})
예제 #30
0
def signup_view(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            return redirect('index')
    else:
        form = SignupForm()
    return render(request, 'accounts/signup.html', {'form': form})
예제 #31
0
파일: views.py 프로젝트: shubham11o7/Weblog
def signup(request):
    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})
def signup(request):
    form = SignupForm(request.POST)
    if form.is_valid():
        user = form.save()
        profile = user.get_profile()
        profile.nickname = request.POST.get('nickname')
        profile.save()
        user_dict = model_to_dict(user, fields=['id', 'username'])
        return JsonResponse(user_dict)
    return JsonResponse(form.errors)
예제 #33
0
def signup(request):
    """ User signup view that uses the SignupForm with the location field. """
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save()
            auth_login(request, user)
            return redirect('dashboard')
    else:
        form = SignupForm()
    return render(request, 'open-pages/signup.html', {'form': form})
예제 #34
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST, request.FILES)
        if form.is_valid():
            user = form.save()
            return redirect(setting.LOGIN_URL) #TODO
    else:
        form = SignupForm()
    return render(request, 'accounts/signup_form.html',{
            'form' : form
        })
예제 #35
0
파일: views.py 프로젝트: fingul/Comment
def signup_view(request):
    if request.method == 'POST':
        signupform = SignupForm(request.POST)
        if signupform.is_valid():      
            user = signupform.save()
            login(request, user)
            return redirect('post:postlist')
    else:
        signupform = SignupForm()
    context = {'form': signupform}
    return render(request, 'accounts/signup.html', context)
예제 #36
0
 def test_able_to_signup(self):
     # print(User.objects.all())
     form = SignupForm(data={
         'email': '*****@*****.**',
         'password': '******',
         'password2': 'aloc'
     })
     # print(form)
     self.assertTrue(form.is_valid())
     user = form.save()
     self.assertIn(user, User.objects.all())
예제 #37
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save()
            return redirect(settings.LOGIN_URL)  # default : "/accounts/login/"
    else:
        form = SignupForm()
    return render(request, 'accounts/signup_form.html', {
        'form': form,
    })
예제 #38
0
def signup(request):
    form = SignupForm()
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save()
            # make user login
            auth_login(request, user)

            # move to HOME page
            return redirect('home')
    return render(request, 'signup.html', {'form': form})
예제 #39
0
def signup(request):
	if request.method =='POST':
		form = SignupForm(request.POST)
		if form.is_valid():
			user = form.save()
			login(request, user)
			return redirect ('index')

	else:
		form = SignupForm()
	context  = {'form' :form}
	return render(request, 'boards/signup.html', context)
예제 #40
0
def signup(request):
    form = SignupForm(request.POST)
    if form.is_valid():
        user = form.save(commit=False)
        user.first_name = form.cleaned_data.get('first_name')
        user.last_name = form.cleaned_data.get('last_name')
        user.save()
        auth_login(request, user)
        return redirect('home')
    else:
        form = SignupForm()
    return render(request, 'signup.html', {'form': form})
예제 #41
0
파일: views.py 프로젝트: dlkorea/my_issue
def signup(request):
    uform = SignupForm(request.POST or None, request.FILES or None)
    if uform.is_valid():
        user = uform.save()

        user.backend = "django.contrib.auth.backends.ModelBackend"
        auth_login(request, user)

        next_url = request.GET.get("next", "/timeline")
        return redirect(next_url)
    else:
        params = {"uform": uform}
        return render(request, "accounts/signup.html", params)
예제 #42
0
def signup(request):
    """
    회원가입을 위한 뷰.
    Login 되어 있을 시에는 회원가입 페이지에 접근하지 못하도록 함.
    """
    if request.user.is_authenticated:
        messages.error(request, "이미 로그인 됨")
        context = {}
        return render(request, 'global/error_page.html', context=context)
    else:
        if request.method == "POST":
            form = SignupForm(request.POST)
            if form.is_valid():
                user = form.save()
                user.refresh_from_db()

                # set profile data
                profile = user.profile
                profile.name = form.cleaned_data.get('name')
                profile.id_number = form.cleaned_data.get('id_number')
                profile.role = form.cleaned_data.get('role')
                form.save()

                username = form.cleaned_data.get('username')
                raw_pass = form.cleaned_data.get('password1')

                user = authenticate(request, username=username, password=raw_pass)
                login(request, user, )
                return redirect('accounts:view_profile')
            else:
                messages.error(request, "회원가입 실패!")
        else:
            form = SignupForm()
        context = {
            "user_form": form,
            "user": request.user,
        }

        return render(request, 'accounts/signup.html', context=context)
예제 #43
0
def signup(request):
    if request.method == "POST":
        form = SignupForm(request.POST)
        if form.is_valid():
            form.save()

            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            token = str(uuid4())
            key_expires = datetime.datetime.today() + datetime.timedelta(2)

            User = get_user_model()

            user = User.objects.get(username=username)
            email_token = UserProfile(user=user, token=token, key_expires=key_expires)

            email_token.save()


            email_subject = 'Account confirmation'
            email_body = "Hey %s, thanks for signing up. To activate your account, click this link within \48hours http://127.0.0.1:8000/accounts/confirm/%s" % (username, token)

            send_mail(email_subject, email_body, '*****@*****.**', [email], fail_silently=False)

            messages.success(request, '이메일이 전송되었습니다. 이메일 인증 후 아이디 사용이 가능합니다.')

            return HttpResponseRedirect('/accounts/signup/complete')
            # return HttpResponseRedirect('/')

            # return redirect(settings.LOGIN_URL)
    else:
        form = SignupForm()

    tokens= {}
    tokens.update(csrf(request))
    tokens['form'] = form

    return render(request, 'accounts/signup.html', tokens)
예제 #44
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save()
            backend_cls = get_backends()[0].__class__
            backend_path = backend_cls.__module__+ '.' + backend_cls.__name__
            user.backend = backend_path
            auth_login(request, user)
            messages.info(request, '환영합니다.')
            return redirect(settings.LOGIN_REDIRECT_URL)
    else:
        form = SignupForm()
    return render(request, 'accounts/signup.html', {'form': form,})
예제 #45
0
def signup(request):
    if request.method == "POST":
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save()

            user.backend = "django.contrib.auth.backends.ModelBackend"
            auth_login(request, user)

            messages.success(request, "{} 님. 이메일을 확인해주세요.".format(user))
            next_url = request.GET.get("next", "/")
            return redirect(next_url)
    else:
        form = SignupForm()
    return render(request, "accounts/go.html", {"form": form})
예제 #46
0
def signup(request, template_name='accounts/signup.html'):

    signup_form = SignupForm(request.POST or None)
    user_profile_signup_form = UserProfileSignupForm(request.POST or None, request.FILES or None)

    if request.method == 'POST':
        if signup_form.is_valid() and user_profile_signup_form.is_valid():
            with transaction.atomic():
                user = signup_form.save()
                user_profile = user_profile_signup_form.save(commit=False)
                user_profile.user = user
                user_profile.save()

                redirect_to = reverse('accounts:user_list')
                return HttpResponseRedirect(redirect_to)

    context = {
        'signup_form': signup_form,
        'user_profile_signup_form': user_profile_signup_form
    }

    return TemplateResponse(request, template_name, context)
예제 #47
0
파일: views.py 프로젝트: zyzone03/dearyou
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()
            # send_signup_confirm_email(request, user)
            # return redirect(settings.LOGIN_URL)
            user = form.save()
            backend_cls = get_backends()[0].__class__
            backend_path = backend_cls.__module__ + "." + backend_cls.__name__
            user.backend = backend_path
            auth_login(request, user)
            messages.info(request, "Welcome")
            return redirect(settings.LOGIN_REDIRECT_URL)

    else:

        form = SignupForm()
    return render(request, "accounts/signup.html", {"form": form})