Exemple #1
0
def signup(request):
	if request.method == "POST":   
		form = SignupForm(request.POST)
		if form.is_valid():
			user=User()
			user.username = form.cleaned_data['username']
			user.email = form.cleaned_data['email']
			user.set_password(form.cleaned_data['password'])
			user.save()
			trader=Trader(user=user)
			trader.save()
			user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password'])  #Nous vérifions si les données sont correctes
			login(request, user)
			#return redirect('posts.views.user', id_user=user.id)
			return redirect('markets.views.home')
	else:
		form2 = LoginForm()
		form = SignupForm()	
	return render(request, 'markets/signup.html', locals())	
Exemple #2
0
def signup(request):
	if request.method == "POST":   
		form = SignupForm(request.POST)
		if form.is_valid():
			try:
				code = Code.objects.get(code=form.cleaned_data['code'])
			except:
				code=''
			if code!='':
				if code.active==True:
					code.active=False
					code.save()
					user=User()
					user.username = form.cleaned_data['username']
					user.email = form.cleaned_data['email']
					user.set_password(form.cleaned_data['password'])
					user.save()
					trader=Trader(user=user)
					trader.save()
					transfer=Transfer()
					transfer.trader=trader
					transfer.type=1
					transfer.volume=100
					transfer.save()			
					user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password'])  #Nous vérifions si les données sont correctes
					login(request, user)
					#return redirect('posts.views.user', id_user=user.id)
					return redirect('markets.views.home')
				else:
					form.non_field_errors="Wrong code"
					form2 = LoginForm()
			else:
				form.non_field_errors="Wrong code"
				form2 = LoginForm()
	else:
		form2 = LoginForm()
		form = SignupForm()	
	return render(request, 'markets/signup.html', locals())