def register(request): if request.method == 'POST': form = RegisterForm(request.POST or None) form.need_confirm = False if form.is_valid(): clean_data = form.cleaned_data email = clean_data.get('email', None) password = clean_data.get('password', None) validate_code = clean_data.get('validate_code', None) invite_code = clean_data.get('invite_code', None) user = UserModel.objects.filter(email=email) if user: return Response(status=status.HTTP_409_CONFLICT) else: user = UserModel() user.email = email encode_password = make_password(password) user.password = encode_password records = MailCodeModel.objects.filter(code=validate_code) if records: user.active = True invitation = InvitationCodeModel.objects.filter( code=invite_code, active=False) if invitation: invitation.active = True user.invite = True invitation.save() user.save() return Response(status=status.HTTP_200_OK) return Response(status=status.HTTP_400_BAD_REQUEST)
def sign_up(request): form = RegisterForm(request.POST or None) if request.method == 'POST' and form.is_valid(): clean_data = form.cleaned_data email = clean_data.get('email', None) password = clean_data.get('password', None) validate_code = clean_data.get('validate_code', None) invite_code = clean_data.get('invite_code', None) user = UserModel.objects.filter(email=email) if user: form.add_error(None, '邮箱已注册') else: user = UserModel() user.email = email encode_password = make_password( password ) user.password = encode_password records = MailCodeModel.objects.filter(code=validate_code) if records: user.active = True invitation = InvitationCodeModel.objects.filter(code=invite_code, active=False) if invitation: invitation.active = True user.invite = True invitation.save() user.save() if request.session.test_cookie_worked(): request.session.delete_test_cookie() request.session['user_id'] = user.id return HttpResponseRedirect(reverse('image_browser:home')) return render(request, 'register.html', {'form': form})