Example #1
0
def signin(request):
	error = False    
	form = LoginForm(request.POST)
	if form.is_valid():
		username = form.cleaned_data["username"]  # Nous récupérons le nom d'utilisateur
		password = form.cleaned_data["password"]  # … et le mot de passe
		user = authenticate(username=username, password=password)  #Nous vérifions si les données sont correctes
		if user:  # Si l'objet renvoyé n'est pas None
			login(request, user)  # nous connectons l'utilisateur
			if not Trader.objects.filter(user=user):
				trader=Trader(user=user)
				trader.save()
		else: #sinon une erreur sera affichée
			error = True
	return redirect('markets.views.home')
Example #2
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())	
Example #3
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())