def signup2(request): context = {} if request.method == 'POST': form = SignupForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] password1 = form.cleaned_data['password1'] password2 = form.cleaned_data['password2'] last_name = form.cleaned_data['last_name'] first_name = form.cleaned_data['first_name'] nickname = form.cleaned_data['nickname'] if password1 != password2: return HttpResponse('패스워드가 서로 다릅니다') user = MyUser.objects.create_user( email=email, last_name=last_name, first_name=first_name, nickname=nickname, password=password1, ) login(request, user) messages.info(request, '회원가입 되었습니다') return redirect('blog:post_list') else: context['form'] = form else: form = SignupForm() context['form'] = form return render(request, 'member/signup2.html', context)
def signup2(request): context = {} if request.method != 'POST': form = SignupForm() context['form'] = form return render(request, 'member/signup2.html', context) form = SignupForm(request.POST) if not form.is_valid(): context['form'] = form return render(request, 'member/signup2.html', context) email = form.cleaned_data['email'] password1 = form.cleaned_data['password1'] password2 = form.cleaned_data['password2'] last_name = form.cleaned_data['last_name'] first_name = form.cleaned_data['first_name'] nickname = form.cleaned_data['nickname'] if password1 != password2: return HttpResponse("패스워드가 다릅니다.") user = MyUser.objects.create_user( email=email, last_name=last_name, first_name=first_name, nickName=nickname, password=password1, ) login(request, user) # messages.info( request, "회원가입 성공") return redirect('post_list')
def signup(request): if request.method == "POST": form = SignupForm(request.POST) if form.is_valid(): email = request.POST['email'] password1 = request.POST['password1'] password2 = request.POST['password2'] last_name = request.POST['last_name'] first_name = request.POST['first_name'] nickname = request.POST['nickname'] if password1 != password2: messages.error(request, "패스워드가 다릅니다") return redirect('member:signup') user = MyUser.objects.create_user( email=email, password=password1, last_name=last_name, first_name=first_name, nickname=nickname, ) auth_login(request, user) messages.success(request, "회원가입 성공") return redirect('blog:post_list') else: pass else: form = SignupForm() return render(request, 'member/signup.html', {'form': form})
def signup(request): if request.method == 'POST': form = SignupForm(request.POST, request.FILES) if form.is_valid(): user = form.save() login(request, user, backend='django.contrib.auth.backends.ModelBackend') return redirect('post:post_list') else: form = SignupForm context = { 'form': form, } return render(request, 'member/signup.html', context)
def signup(request): if request.method == 'POST': # (기본) # username = request.POST.get('username') # password = request.POST.get('password') # (기본) form = SignupForm(request.POST, request.FILES) # (기본) # if username and password: # (기본) if form.is_valid(): # 주어진 username의 User가 존재하는지 검사 # if User.objects.filter(username=username).exists(): # return HttpResponse(f'Username {username} is already exist') # 없으면 User 생성 user = form.save() # user = form.signup() dj_login(request, user) return redirect('main') else: form = SignupForm() context = { 'form': form, } return render(request, 'member/signup.html', context) # def user_post(request): # post = Post.objects.filter(author=request.user)
def signup(request): if request.method == 'POST': form = SignupForm(data=request.POST) if form.is_valid(): user = form.create_user() django_login(request, user) return redirect('member:main') else: form = SignupForm() context = { 'form': form, } return render(request, 'member/signup.html', context)
def signup_view(request): if request.method == 'POST': form = SignupForm(request.POST) if form.is_valid(): user = form.save() login(request, user) return redirect('posts:post-list') else: form = SignupForm() context = { 'form': form, } return render(request, 'members/signup.html', context)
def signup(request): # member/signup.html을 사용 # 1. username, password1, passwords2를 받아 회원가입. # 2. 기존에 존재하는 유저인지 검사 # 3. password1, 2가 일치하는지 검사 # 4. 각각의 경우를 검사해서 틀릴 경우 오류메시지 리턴 # 5. 가입성공시 로그인시키고 post_list로 redirect if request.method == "POST": ### Form을 사용하지 않는 경우 # form = SignupForm(data=request.POST) # username = request.POST['username'] # password1 = request.POST['password1'] # password2 = request.POST['password2'] # if User.objects.filter(username=username).exists(): # return HttpResponse('Username is already exists') # elif password1 != password2: # return HttpResponse('패스워드가 다릅니다.'.format(username)) # # user = User.objects.create_user(username=username, password=password1) ### Form을 사용한 경우 form = SignupForm(data=request.POST) if form.is_valid(): user = form.create_user() print("유저 누구? ", user) # 위에서 생성한 유저를 로그인 시킨 후, post_list뷰로 이동 django_login(request, user) return redirect("posts:post_list") else: form = SignupForm() context = { 'form': form } return render(request, 'member/signup.html', context)
def signup(request): if request.method == 'POST': form = SignupForm(request.POST) if form.is_valid(): user = form.create_user() current_site = get_current_site(request) message = render_to_string( 'acc_activate_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 = 'Hello! Welcome to WeatherSound. Please activate your 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' ) else: form = SignupForm() return render(request, 'signup.html', {'form': form})
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 = 'Activate your account.' message = render_to_string('registration/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), }) to_email = form.cleaned_data.get('email') email = EmailMessage( mail_subject, message, to=[to_email] ) email.send() return render(request, 'registration/notice-page.html') else: form = SignupForm() return render(request, 'registration/signup.html', {'form': form})