Recommend this page to a friend! |
Download |
Info | Example | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2023-12-05 (10 months ago) | Not enough user ratings | Total: 135 | All time: 9,286 This week: 44 |
Version | License | PHP version | Categories | |||
ajax-login 1.0.0 | MIT/X Consortium ... | 7 | HTTP, Cryptography, User Management, W..., S..., A..., P... |
<?php |
Sistema de autenticação simples utilizando JSON Web Tokens (JWT).
Clone o repositório depois instale a dependencia abaixo Instale a biblioteca via composer:
composer require firebase/php-jwt
composer require bramus/router
composer update
Após a instalçao das dependências acima mencionadas, uma para gerenciar a criação e validação do token, a outra é para gerenciar rotas semelhante o que acontece com os principais frameworks, onde é capturado o metodo e o recurso e direciona para a função no contralador especifico.
Ao realizar o login, um token JWT é gerado para o usuário com base em suas credenciais. o frontend recebe o token caso a autenticação seja bem sucedida, e o javascript "x.js" a cada 1 minuto faz uma requisição para verificar o token e verificar as telas autorizadas pela passoa logada.
$key = "YOUR_SECRET_KEY";
$payload = [
"iss" => "localhost",
"aud" => "localhost",
"iat" => time(),
"exp" => time() + 3600, // Expira em 1 hora
"sub" => "user@email.com"
];
$jwt = JWT::encode($payload, $key);
Validação de Token Para validar o token recebido em requisições subsequentes:
$key = "YOUR_SECRET_KEY";
try {
$decoded = JWT::decode($token, $key, ['HS256']);
// Token é válido
} catch(Exception $e) {
// Token inválido
}
backend/Controller/UsuarioController.php: Contém a lógica para gerar e validar o JWT. backend/Router/: Roteamento e processamento das requisições HTTP.
const response = await fetch(urlBase+'backend/Router/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ email, senha: password,lembrar })
});
const data = await response.json();
if (data.status) {
sessionStorage.setItem('token', data.token);
window.location.href = "index.html";
}
Files (154) |
File | Role | Description | ||
---|---|---|---|---|
backend (2 files, 5 directories) | ||||
css (2 files) | ||||
img (7 files) | ||||
js (8 files, 1 directory) | ||||
sql (1 file) | ||||
vendor (1 file, 4 directories) | ||||
composer.json | Data | Auxiliary data | ||
composer.lock | Data | Auxiliary data | ||
esqueci.html | Data | HTML page | ||
index.html | Data | HTML page | ||
login.html | Data | HTML page | ||
pessoas.html | Data | HTML page | ||
projetos.html | Data | HTML page | ||
readme.md | Doc. | Documentation | ||
registrar.html | Data | HTML page |
Files (154) | / | backend |
File | Role | Description | ||
---|---|---|---|---|
Controller (4 files) | ||||
Cryptonita (1 file) | ||||
Database (5 files) | ||||
Model (3 files) | ||||
Router (5 files) | ||||
.htaccess | Data | Auxiliary data | ||
index.php | Example | Example script |
Files (154) | / | backend | / | Controller |
File | Role | Description |
---|---|---|
EnviaEmail.php | Class | Class source |
PerfilPermissaoController.php | Class | Class source |
PermissaoController.php | Class | Class source |
UsuarioController.php | Class | Class source |
Files (154) | / | backend | / | Database |
File | Role | Description |
---|---|---|
banco_x.sqbpro | Data | Auxiliary data |
config.php | Aux. | Auxiliary script |
configEmail.php | Aux. | Auxiliary script |
Connection.php | Class | Class source |
Crud.php | Class | Class source |
Files (154) | / | backend | / | Model |
File | Role | Description |
---|---|---|
Perfil.php | Class | Class source |
Permissao.php | Class | Class source |
Usuario.php | Class | Class source |
Files (154) | / | backend | / | Router |
File | Role | Description |
---|---|---|
index.php | Example | Example script |
LoginRouter.php | Example | Example script |
PerfilPermissaoRouter.php | Example | Example script |
PermissaoRouter.php | Example | Example script |
UsuarioRouter.php | Example | Example script |
Files (154) | / | css |
File | Role | Description |
---|---|---|
styleaTime.css | Data | Auxiliary data |
w3.css | Data | Auxiliary data |
Files (154) | / | img |
Files (154) | / | js |
File | Role | Description | ||
---|---|---|---|---|
json (2 files) | ||||
cards.js | Data | Auxiliary data | ||
esqueci.js | Data | Auxiliary data | ||
gerenciar.js | Data | Auxiliary data | ||
getUsers.js | Data | Auxiliary data | ||
login.js | Data | Auxiliary data | ||
registrar.js | Data | Auxiliary data | ||
times.js | Data | Auxiliary data | ||
token.js | Data | Auxiliary data |
Files (154) | / | js | / | json |
File | Role | Description |
---|---|---|
cards.json | Data | Auxiliary data |
times.json | Data | Auxiliary data |
Files (154) | / | vendor |
File | Role | Description | ||
---|---|---|---|---|
bramus (1 directory) | ||||
composer (11 files) | ||||
firebase (1 directory) | ||||
phpmailer (1 directory) | ||||
autoload.php | Aux. | Auxiliary script |
Files (154) | / | vendor | / | bramus | / | router |
File | Role | Description | ||
---|---|---|---|---|
.github (1 directory) | ||||
demo-multilang (2 files) | ||||
demo (2 files) | ||||
src (1 directory) | ||||
tests (2 files) | ||||
.php_cs.dist | Example | Example script | ||
CHANGELOG.md | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpunit.xml.dist | Data | Auxiliary data | ||
README.md | Doc. | Documentation |
Files (154) | / | vendor | / | bramus | / | router | / | .github | / | workflows |
File | Role | Description |
---|---|---|
CI.yml | Data | Auxiliary data |
Files (154) | / | vendor | / | bramus | / | router | / | demo-multilang |
Files (154) | / | vendor | / | bramus | / | router | / | demo |
Files (154) | / | vendor | / | bramus | / | router | / | src | / | Bramus | / | Router |
File | Role | Description |
---|---|---|
Router.php | Class | Class source |
Files (154) | / | vendor | / | bramus | / | router | / | tests |
File | Role | Description |
---|---|---|
bootstrap.php | Aux. | Auxiliary script |
RouterTest.php | Class | Class source |
Files (154) | / | vendor | / | composer |
File | Role | Description |
---|---|---|
autoload_classmap.php | Aux. | Auxiliary script |
autoload_namespaces.php | Aux. | Auxiliary script |
autoload_psr4.php | Aux. | Auxiliary script |
autoload_real.php | Class | Class source |
autoload_static.php | Class | Class source |
ClassLoader.php | Class | Class source |
installed.json | Data | Auxiliary data |
installed.php | Aux. | Auxiliary script |
InstalledVersions.php | Class | Class source |
LICENSE | Lic. | License text |
platform_check.php | Aux. | Auxiliary script |
Files (154) | / | vendor | / | firebase | / | php-jwt |
File | Role | Description | ||
---|---|---|---|---|
src (8 files) | ||||
CHANGELOG.md | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files (154) | / | vendor | / | firebase | / | php-jwt | / | src |
File | Role | Description |
---|---|---|
BeforeValidException.php | Class | Class source |
CachedKeySet.php | Class | Class source |
ExpiredException.php | Class | Class source |
JWK.php | Class | Class source |
JWT.php | Class | Class source |
JWTExceptionWithPayloadInterface.php | Class | Class source |
Key.php | Class | Class source |
SignatureInvalidException.php | Class | Class source |
Files (154) | / | vendor | / | phpmailer | / | phpmailer |
File | Role | Description | ||
---|---|---|---|---|
language (53 files) | ||||
src (7 files) | ||||
COMMITMENT | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
get_oauth_token.php | Example | Example script | ||
LICENSE | Lic. | License text | ||
README.md | Example | Example script | ||
SECURITY.md | Data | Auxiliary data | ||
VERSION | Data | Auxiliary data |
Files (154) | / | vendor | / | phpmailer | / | phpmailer | / | language |
File | Role | Description |
---|---|---|
phpmailer.lang-af.php | Aux. | Auxiliary script |
phpmailer.lang-ar.php | Aux. | Auxiliary script |
phpmailer.lang-az.php | Aux. | Auxiliary script |
phpmailer.lang-ba.php | Aux. | Auxiliary script |
phpmailer.lang-be.php | Aux. | Auxiliary script |
phpmailer.lang-bg.php | Aux. | Auxiliary script |
phpmailer.lang-ca.php | Aux. | Auxiliary script |
phpmailer.lang-cs.php | Aux. | Auxiliary script |
phpmailer.lang-da.php | Aux. | Auxiliary script |
phpmailer.lang-de.php | Aux. | Auxiliary script |
phpmailer.lang-el.php | Aux. | Auxiliary script |
phpmailer.lang-eo.php | Aux. | Auxiliary script |
phpmailer.lang-es.php | Aux. | Auxiliary script |
phpmailer.lang-et.php | Aux. | Auxiliary script |
phpmailer.lang-fa.php | Aux. | Auxiliary script |
phpmailer.lang-fi.php | Aux. | Auxiliary script |
phpmailer.lang-fo.php | Aux. | Auxiliary script |
phpmailer.lang-fr.php | Aux. | Auxiliary script |
phpmailer.lang-gl.php | Aux. | Auxiliary script |
phpmailer.lang-he.php | Aux. | Auxiliary script |
phpmailer.lang-hi.php | Aux. | Auxiliary script |
phpmailer.lang-hr.php | Aux. | Auxiliary script |
phpmailer.lang-hu.php | Aux. | Auxiliary script |
phpmailer.lang-hy.php | Aux. | Auxiliary script |
phpmailer.lang-id.php | Aux. | Auxiliary script |
phpmailer.lang-it.php | Aux. | Auxiliary script |
phpmailer.lang-ja.php | Aux. | Auxiliary script |
phpmailer.lang-ka.php | Aux. | Auxiliary script |
phpmailer.lang-ko.php | Aux. | Auxiliary script |
phpmailer.lang-lt.php | Aux. | Auxiliary script |
phpmailer.lang-lv.php | Aux. | Auxiliary script |
phpmailer.lang-mg.php | Aux. | Auxiliary script |
phpmailer.lang-mn.php | Aux. | Auxiliary script |
phpmailer.lang-ms.php | Aux. | Auxiliary script |
phpmailer.lang-nb.php | Aux. | Auxiliary script |
phpmailer.lang-nl.php | Aux. | Auxiliary script |
phpmailer.lang-pl.php | Aux. | Auxiliary script |
phpmailer.lang-pt.php | Aux. | Auxiliary script |
phpmailer.lang-pt_br.php | Aux. | Auxiliary script |
phpmailer.lang-ro.php | Aux. | Auxiliary script |
phpmailer.lang-ru.php | Aux. | Auxiliary script |
phpmailer.lang-si.php | Aux. | Auxiliary script |
phpmailer.lang-sk.php | Aux. | Auxiliary script |
phpmailer.lang-sl.php | Aux. | Auxiliary script |
phpmailer.lang-sr.php | Aux. | Auxiliary script |
phpmailer.lang-sr_latn.php | Aux. | Auxiliary script |
phpmailer.lang-sv.php | Aux. | Auxiliary script |
phpmailer.lang-tl.php | Aux. | Auxiliary script |
phpmailer.lang-tr.php | Aux. | Auxiliary script |
phpmailer.lang-uk.php | Aux. | Auxiliary script |
phpmailer.lang-vi.php | Aux. | Auxiliary script |
phpmailer.lang-zh.php | Aux. | Auxiliary script |
phpmailer.lang-zh_cn.php | Aux. | Auxiliary script |
Files (154) | / | vendor | / | phpmailer | / | phpmailer | / | src |
File | Role | Description |
---|---|---|
DSNConfigurator.php | Class | Class source |
Exception.php | Class | Class source |
OAuth.php | Class | Class source |
OAuthTokenProvider.php | Class | Class source |
PHPMailer.php | Class | Class source |
POP3.php | Class | Class source |
SMTP.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.