Exemple #1
0
def login():
    form = FormLogin()

    if request.method == 'GET':
        if not current_user.is_authenticated:
            return render_template('login.html', form=form)
        else:
            return redirect(url_for('usuarios'))

    if request.method == 'POST':
        if form.validate_on_submit():
            form = FormUser(request.form)
            username = form.username.data
            password = form.password.data

            try:
                user = Administrator.query.filter_by(user=username).first()

                dbuser = user.user
                dbpass = user.password

                if username == dbuser and sha256_crypt.verify(
                        password, dbpass):
                    login_user(user)
                    return redirect(url_for('usuarios'))
                else:
                    flash('Usuário ou senha inválida',
                          'notification is-danger')

            except:
                flash('Usuário ou senha inválida', 'notification is-danger')

        return render_template('login.html', form=form)
Exemple #2
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = FormLogin()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.user.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Usuário ou senha inválidos!', 'danger')
            return redirect(url_for('login'))
        login_user(user, remember=True)
        flash('Bem vindo {}!'.format(current_user.username), 'success')
        return redirect(url_for('index'))
    return render_template('login.html', form=form)
Exemple #3
0
def login_user(request):
    if request.POST:
        form = FormLogin(request.POST)
        if form.is_valid:
            username = request.POST['username']
            key = request.POST['password']
            access = authenticate(username=username, password=key)
            if access is not None:
                login(request, access)
                url = request.GET.get('next') or reverse('inicio')
                return redirect(url)
            else:
                messages.error(request, 'Usuario o contraseñas no validos')

    elif request.user.is_authenticated():
        return redirect('/')
    else:
        form = FormLogin()
    return render(request, 'login.html', {'form': form})
def login(request):
    """ 
    Página para login, site, face e twitter

    """
		
    esquema = FormLogin().bind(request=request)
    esquema.title = "Login"
	#botoes nao aceitam frases como label = "esqueci a senha"
    form = deform.Form(esquema, buttons=('Entrar', 'Esqueci a senha'))
    #form = deform.Form(esquema, buttons=('Entrar', 'Esqueci'))
    if authenticated_userid(request):
       request.session.flash(u"Usuário já está logado, caso queira entrar com usuário diferente, faça o logout.")	
       return HTTPFound(location=request.route_url('usuario'))	   
    if 'Entrar' in request.POST:
        try:
            form.validate(request.POST.items())		
        except deform.ValidationFailure as e:
            return {'form': e.render()}

        email = request.POST.get("email")
        senha = request.POST.get("senha")
        if email in request.db["usrTree"]:
            cidadao = Cidadao("","")
            cidadao = request.db["usrTree"][email]
            if cidadao.senha == senha:
                headers = remember(request, email)
                next = request.route_url('usuario')
                request.session.flash(u"Usuário logado")				
                return HTTPFound(location=next, headers=headers)					
            else:
                request.session.flash(u"Email ou senha inválidos")			
        else:
            request.session.flash(u"Email ou senha inválidos")		
        return {'form': form.render()}
    #não entra nesse elif
    #elif 'Esqueci' in request.POST:  
    elif 'Esqueci_a_senha' in request.POST:  
        return HTTPFound(location=request.route_url('r_senha'))
    else:
        return {'form': form.render()}
Exemple #5
0
def user_login():
    form = FormLogin()
    if form.validate_on_submit():
        if request.method == "POST":
            member_exists = mongo.db.members.find_one(
                {"email": request.form.get("email").lower()})

            # Check if member exists in database
            if member_exists:
                if check_password_hash(member_exists["password"],
                                       request.form.get("password")):
                    session["member"] = request.form.get("email").lower()
                    flash(
                        "Welcome {}, You are logged in.".format(
                            request.form.get("email")), 'green-bg')
                    return redirect(
                        url_for("my_profile", email=session["member"]))
                else:
                    flash("Invalid email/password combination", 'red-bg')
                    return redirect(url_for("user_login"))
            else:
                flash("Invalid email/password combination", 'red-bg')
                return redirect(url_for("user_login"))
    return render_template("user-login.html", title="Login Page", form=form)
Exemple #6
0
def Index(request):
	if request.method == "POST":
		requestform = request.POST.get('identificadorform')

		if requestform == 'form_login':
			if request.user.is_authenticated():
				auth.logout(request)
				return HttpResponseRedirect("/huevos/")
			else:
				form_register = FormRegisterLogin()
				if request.user.is_authenticated():
					return HttpResponseRedirect("/huevos/")
				else:			
					form_login = FormLogin(request.POST)				

					if(form_login.is_valid()):				
						username = form_login.cleaned_data('username_login')
						password = form_login.cleaned_data('password_login')			

						user_authenticated = auth.authenticate(username=username,password=password)

						if user_authenticated is not None:
							auth.login(request,user_authenticated)
							return HttpResponseRedirect("/huevos/")
						else:
							return HttpResponseRedirect("/error/") 		

		elif requestform == 'form_registro':
			form_login = FormLogin()

			if request.user.is_authenticated():
				auth.logout(request)
				return HttpResponseRedirect("/huevos/")
			else:						
				form_register = FormRegisterLogin(request.POST)
				
				if(form_register.is_valid()):
					username=form_register.cleaned_data.get('username')
					email=form_register.cleaned_data.get('email')
					password=form_register.cleaned_data.get('password')
					password2=form_register.cleaned_data.get('password2')							

					new_user = User.objects.create_user(username=username,
						email=email,
						password=password)

					new_user.is_staff = True
					new_user.save()

					return HttpResponseRedirect("/huevos/")		
		else:
			form_login = FormLogin()
			form_register = FormRegisterLogin()

	else:
		form_login = FormLogin()
		form_register = FormRegisterLogin()

	return render(request,'organizarte_home.html',{
			'form_login': form_login,
			'form_register':form_register,
			})