Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="pt-br">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>FindProfessionals</title>
- <script src="https://www.gstatic.com/firebasejs/5.7.0/firebase.js"></script>
- <script>
- // Initialize Firebase
- var config = {
- apiKey: "AIzaSyCCDh8XA_LXZA5mvq5ffmJWxc2o6fG8THQ",
- authDomain: "findprofessionals-63377.firebaseapp.com",
- databaseURL: "https://findprofessionals-63377.firebaseio.com",
- projectId: "findprofessionals-63377",
- storageBucket: "findprofessionals-63377.appspot.com",
- messagingSenderId: "281081068714"
- };
- firebase.initializeApp(config);
- </script>
- </head>
- <body>
- <p>cadastro</p>
- <input type="email" name="email" id="e" required>
- <input type="password" name="password" id="p" required>
- <button onclick="cadastro();">cadastrar</button>
- <p>login</p>
- <input type="email" name="email" id="eL" required>
- <input type="password" name="password" id="pL" required>
- <button onclick="login();">Acessar</button>
- <button onclick="logout();">Logout</button>
- <p>insercao de dados</p>
- <button onclick="recuperarDados('dawid');">listar</button>
- <script>
- function login(){
- firebase.auth().signInWithEmailAndPassword(document.getElementById('eL').value.toString(), document.getElementById('pL').value.toString()).catch(function(error) {
- // Handle Errors here.
- var errorCode = error.code;
- var errorMessage = error.message;
- // ...
- });
- }
- function insercao(userID,username,prof,tel){
- firebase.database().ref('users/'+userID).set({
- "name": `${username}`,
- "prof": `${prof}`,
- "tel" : `${tel}`
- }, function(error) {
- if (error) {
- // The write failed...
- alert('falhou!')
- } else {
- // Data saved successfully!
- alert('inserido!')
- }
- });
- }
- function recuperarDados(userID){
- var dados = firebase.database().ref('users/' + userID);
- dados.on('value', function(snapshot) {
- document.write(snapshot.val().name);
- document.write(snapshot.val().tel);
- document.write(snapshot.val().prof);
- });
- }
- function cadastro(){
- firebase.auth().createUserWithEmailAndPassword(document.getElementById('e').value.toString(), document.getElementById('p').value.toString()).catch(function(error) {
- var errorCode = error.code;
- var errorMessage = error.message;
- });
- }
- function verificarLog(){
- firebase.auth().onAuthStateChanged(function(user) {
- if (user) {
- alert('logado')
- } else {
- // No user is signed in.
- alert('n logado')
- }
- });
- }
- function logout(){
- firebase.auth().signOut().then(function() {
- alert('tchau')
- }).catch(function(error) {
- alert(error.message)
- });
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement