コード例 #1
0
def business_signup(request):
    if request.user.is_authenticated():
        return redirect("home")
    else:
        form = RegisterForm(request.POST or None)
        next_url = request.POST.get('next')

        if form.is_valid():
            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            password = form.cleaned_data['password2']
            new_user = MyUser()
            new_user.username = username
            new_user.email = email
            new_user.set_password(password)
            new_user.save()
            user = authenticate(username=username, password=password)
            if user is not None:
                new_advertiser, created = Advertiser.objects.get_or_create(
                    user=user)
                new_advertiser.save()
                login(request, user)

                if next_url is not None:
                    return HttpResponseRedirect(next_url)
                return HttpResponseRedirect(reverse("home"))
        context = {
            "form": form,
            "action_url": reverse("contact:business_signup"),
        }
        return render(request, 'advertisers/business_signup.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: rogilesor/myBlog
def register(request):

	form = RegisterForm(request.POST or None)
	if form.is_valid():
		username = form.cleaned_data['username']
		email = form.cleaned_data['email']
		password = form.cleaned_data['password2']
		#MyUser.objects.create_user(username=username, email=email, password=password)
		new_user = MyUser()
		new_user.username = username
		new_user.email = email
		new_user.is_active = False
		messages.success(request, "Enregistrement terminé. Votre compte est maintenant en attente d'activation")
		#new_user.password = password #WRONG
		new_user.set_password(password) #RIGHT
		new_user.save()

	action_url = reverse("register")
	title = "Register"
	submit_btn = "Create free account"

	context = {
		"form": form,
		"action_url": action_url,
		"title": title,
		"submit_btn": submit_btn
		}
	return render(request, "registration/registration_form.html", context)
コード例 #3
0
def register(request):
    if request.method == 'POST':
        username = request.POST['usr_name']
        usr_paaaword = request.POST['usr_password']
        usr_password_check = request.POST['usr_password_check']
        usr_email = request.POST['usr_email']
        xieyi = request.POST.getlist('xieyi')
        re_email = r"[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?"
        url_jump = request.get_full_path()
        # 判断是否输入用户名
        if not username:
            tips = '用户名不能为空'
            return render(request, 'accounts/jump.html', locals())
        # 判断用户名个是否已存在
        if MyUser.objects.filter(username=username):
            tips = '用户名已存在'
            return render(request, 'accounts/jump.html', locals())
        # 判断密码是否为正确长度
        if 6 > len(usr_paaaword) or len(usr_paaaword) > 20:
            tips = '请输入正确的密码长度'
            return render(request, 'accounts/jump.html', locals())
        # 判断两次密码是否相同
        if usr_paaaword != usr_password_check:
            tips = '两次密码不同'
            return render(request, 'accounts/jump.html', locals())
        # 判断是否同意协议
        if not xieyi:
            tips = '未同意协议'
            return render(request, 'accounts/jump.html', locals())
        # 判断是否输入了正确的邮箱
        if not search(re_email, usr_email):
            tips = '未请输入正确的邮箱'
            return render(request, 'accounts/jump.html', locals())
        # 判断邮箱是否存在
        if MyUser.objects.filter(email=usr_email):
            tips = '邮箱已存在'
            return render(request, 'accounts/jump.html', locals())
        # 注册成功
        tips = '注册成功'
        url_jump = request.POST['next_url']
        user = MyUser()  # 创建用户对象
        user.username = username
        user.password = make_password(usr_paaaword)
        user.email = usr_email
        # user.is_staff = True    # 允许用户登录后台
        user.save()
        user = MyUser.objects.get(username=username)
        group = Group.objects.get(name='注册会员')
        user.groups.add(group)
        return render(request, 'accounts/jump.html', locals())
    else:
        next_url = request.GET.get('next', '/accounts/login')
        return render(request, 'accounts/register.html', locals())
コード例 #4
0
ファイル: views.py プロジェクト: fesp21/srvup-membership
def home(request):

	form = RegisterForm(request.POST or None)
	if form.is_valid():
		username = form.cleaned_data['username']
		email = form.cleaned_data['email']
		password = form.cleaned_data['password2']
		#MyUser.objects.create_user(username=username, email=email, password=password)
		new_user = MyUser()
		new_user.username = username
		new_user.email = email
		#new_user.password = password #WRONG
		new_user.set_password(password) #RIGHT
		new_user.save()

		#ADD MESSAGE for success.
		return redirect('login')
		#return HttpResponseRedirect(reverse('login'))
		



	# name = "Justin"
	# videos = Video.objects.all()
	# embeds = []

	# for vid in videos:
	# 	code = mark_safe(vid.embed_code)
	# 	embeds.append("%s" %(code))

	context = {
		"form": form,
		"action_value": "",
		"submit_btn_value": "Register",
		# "the_name": name,
		# "number": videos.count(),
		# "videos": videos,
		# "the_embeds": embeds,
		# "a_code": mark_safe(videos[0].embed_code)
	}
	return render(request, "form.html", context)
コード例 #5
0
ファイル: views.py プロジェクト: rah1096/video_now
def home(request):

    form = RegistrationForm(request.POST or None)
    if form.is_valid():
        username = form.cleaned_data['username']
        email = form.cleaned_data['email']
        password = form.cleaned_data['password2']
        # MyUser.objects.create_user(username=username, email=email, password=password)
        new_user = MyUser()
        new_user.username = username
        new_user.email = email
        # new_user.password = password #WRONG
        new_user.set_password(password) #RIGHT
        new_user.save()

        #ADD MESSAGE fpr success.
        return redirect('login')
        #return HttpResponseRedirect(reverse('login'))

    # name = "Tim"
    # videos = Video.objects.all()
    # embeds = []

    # for vid in videos:
    #     code = mark_safe(vid.embed_code)
    #     embeds.append("%s" %(code))

    context = {
        "form": form,
        "action_value": "",
        "submit_btn_value": "Register",
        # "the_name": name,
    #     "number": videos.count(),
    #     "videos": videos,
    #     "embeds": embeds,
    #     "a_code": videos[0].embed_code
    }
    return render(request, "home.html", context)
コード例 #6
0
ファイル: views.py プロジェクト: summerbt/srvup_dance
def home (request):
	form = RegistrationForm(request.POST or None)
	if form.is_valid():
		username = form.cleaned_data['username']
		email = form.cleaned_data['email']
		password = form.cleaned_data['password1']
		#MyUser.objects.create_user(username=username, email=email, password=password)
		new_user = MyUser()
		new_user.username = username
		new_user.email = email
		new_user.set_password(password)
		new_user.save()

		#Add message for success
		return redirect('login')


		print username, email, password



	# name = "Summer"
	# videos = Video.objects.all()
	# embeds = []
	# for vid in videos:
	# 	code = mark_safe(vid.embed_code)
	# 	embeds.append("%s" % code)
	context = {
	"form":form,
	"action_value":"",
	"submit_btn_value":"Register"
	# "the_name":name,
	# "number" :videos.count(),
	# "videos" :videos,
	# "embeds" :embeds,
	# "a_code" :mark_safe(videos[0].embed_code)
	}
	return render(request, "form.html", context)
コード例 #7
0
def register_view(request):
	print (request.user.is_authenticated())
	if request.user.is_authenticated():
		raise Http404
	next = request.GET.get('next')
	title = "Register"
	form = UserRegisterForm(request.POST or None)
	if form.is_valid():
		#MyUser = form.save(commit=False)
		username = form.cleaned_data.get('username')
		email = form.cleaned_data.get('email')
		password2 = form.cleaned_data.get('password2')

		#MyUser.objects.create_user(username=username, email=email, password=password)
		new_user = MyUser()
		new_user.username = username
		new_user.email = email
		new_user.set_password(password2) #RIGHT
		new_user.save()

		new_user = authenticate(username=username, password=password2)
		login(request, new_user)
		#return redirect("login")
		if next:
			return redirect(next)
		# Add message for success
		#return something good
		return redirect('/home')
		#return HttpResponseRedirect(reverse('/'))

	#action_url = reverse("register")

	context = {
		'form':form,
		'title':title,
	}
	return render(request, "form.html", context)