def singup(self): if self.method == 'POST': form = UserCreationForm(self.POST) if form.is_valid(): email = form.cleaned_data.get('email') username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password') digits = "".join([ random.choice(string.digits + string.ascii_letters) for i in range(10) ]) email = EmailMessage( 'Hello', 'http://*****:*****@gmail.com']) # fill this param email.send() form.link = digits form.save() user = authenticate(username=username, password=raw_password) # login(self, user) # user.save() return HttpResponseRedirect('/accounts/login') else: form = UserCreationForm() return render(self, 'account/signup.html', {'form': form})
def signup(request): # 이미 로그인한 상태 -> redirect if request.user.is_anonymous: pass elif request.user: return HttpResponseRedirect('/') template = 'account/signup.html' signup_form = UserCreationForm() message = "" # form 작성 후 post 액션 시 if request.method == "POST": signup_form = UserCreationForm(request.POST, request.FILES or None) if signup_form.is_valid(): user = signup_form.save(commit=False) user.save() # 계정 활성화 과정 필요 # return HttpResponse('Please confirm your email address to complete the registration') # return HttpResponse('회원가입 성공!') context = {"message": '회원가입 성공!'} return render(request, 'account/signup_success.html', context) else: message = "비밀번호 미일치" elif request.method == "GET": pass context = {"signupForm": signup_form, "message": message} return render(request, template, context)
def sign_up(request): form = UserCreationForm() if request.POST: form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() login(request, user) return redirect("home") return render(request, "account/sign_up.html", {"form": form})
def signup(request): # 기로그인 -> redirect if request.user.is_anonymous: pass elif request.user: # return HttpResponseRedirect('/portfolios/') return HttpResponseRedirect('/') template = 'registration/signup.html' signupForm = UserCreationForm() message = "" # form 작성 후 post 액션 시 if request.method == "POST": signupForm = UserCreationForm(request.POST, request.FILES or None) if signupForm.is_valid(): user = signupForm.save(commit=False) user.save() """Create a portfolio for this user""" Portfolio.make_portfolio(user) # 계정 활성화를 위한 이메일 인증 current_site = get_current_site(request) mail_subject = render_to_string( 'registration/activation_email_subject.txt') mail_message = render_to_string( 'registration/activation_email.html', { 'user': user, 'domain': current_site.domain, 'uid': urlsafe_base64_encode(force_bytes(user.pk)), 'token': account_activation_token.make_token(user), 'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS, }) to_email = signupForm.cleaned_data.get('email') email = EmailMessage(mail_subject, mail_message, to=[to_email]) email.send() return HttpResponse( 'Please confirm your email address to complete the registration' ) else: message = "패스워드 미일치" elif request.method == "GET": pass context = {"signupForm": signupForm, "message": message} return render(request, template, context)
def signup(request): if request.method == 'POST': data = request.POST.copy() form = UserCreationForm(data) if form.is_valid(): user = form.save() email = form.cleaned_data.get('email') raw_password = form.cleaned_data.get('password1') user = authenticate(email=email, password=raw_password) auth_login(request, user) return redirect('/') else: form = UserCreationForm() return render(request, 'account/signup.html', {'form': form})
def sign_up(request): form = UserCreationForm(request.POST) if form.is_valid(): user = User.objects.create_user( username=form.cleaned_data.get('username'), email=form.cleaned_data.get('email'), password=form.cleaned_data.get('password2')) setup_new_user(user) login(request, user) return JsonResponse(user.to_user()) else: return JsonResponse(form.errors, status=400)
def signup(request): template_name = 'system/signup.html' form = UserCreationForm(request.POST or None) if form.is_valid(): form.save() print("hi from form sis valid") return redirect('system:userlogin') else: print("hi from form is not valid") context = { 'title': 'sign up', 'forms': form, } return render(request, template_name, context)