SHARE
TWEET

Untitled

a guest Dec 13th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="pt-br">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7.     <title>FindProfessionals</title>
  8.     <script src="https://www.gstatic.com/firebasejs/5.7.0/firebase.js"></script>
  9. <script>
  10.   // Initialize Firebase
  11.   var config = {
  12.     apiKey: "AIzaSyCCDh8XA_LXZA5mvq5ffmJWxc2o6fG8THQ",
  13.     authDomain: "findprofessionals-63377.firebaseapp.com",
  14.     databaseURL: "https://findprofessionals-63377.firebaseio.com",
  15.     projectId: "findprofessionals-63377",
  16.     storageBucket: "findprofessionals-63377.appspot.com",
  17.     messagingSenderId: "281081068714"
  18.   };
  19.   firebase.initializeApp(config);
  20. </script>
  21. </head>
  22. <body>
  23.  
  24.   <p>cadastro</p>
  25.  
  26.   <input type="email" name="email" id="e" required>
  27.   <input type="password" name="password" id="p" required>
  28.   <button onclick="cadastro();">cadastrar</button>
  29.  
  30.   <p>login</p>
  31.  
  32.   <input type="email" name="email" id="eL" required>
  33.   <input type="password" name="password" id="pL" required>
  34.   <button onclick="login();">Acessar</button>
  35.  
  36.   <button onclick="logout();">Logout</button>
  37.  
  38.   <p>insercao de dados</p>
  39.  
  40.   <button onclick="recuperarDados('dawid');">listar</button>
  41.  
  42.  
  43.   <script>
  44.  
  45.     function login(){
  46.       firebase.auth().signInWithEmailAndPassword(document.getElementById('eL').value.toString(), document.getElementById('pL').value.toString()).catch(function(error) {
  47.         // Handle Errors here.
  48.         var errorCode = error.code;
  49.         var errorMessage = error.message;
  50.         // ...
  51.       });
  52.     }
  53.    
  54.     function insercao(userID,username,prof,tel){
  55.       firebase.database().ref('users/'+userID).set({
  56.       "name": `${username}`,
  57.       "prof": `${prof}`,
  58.       "tel" : `${tel}`
  59.       }, function(error) {
  60.       if (error) {
  61.         // The write failed...
  62.         alert('falhou!')
  63.       } else {
  64.         // Data saved successfully!
  65.         alert('inserido!')
  66.       }
  67.       });
  68.     }
  69.  
  70.     function recuperarDados(userID){
  71.       var dados = firebase.database().ref('users/' + userID);
  72.       dados.on('value', function(snapshot) {
  73.         document.write(snapshot.val().name);
  74.         document.write(snapshot.val().tel);
  75.         document.write(snapshot.val().prof);
  76.       });
  77.     }
  78.  
  79.     function cadastro(){
  80.       firebase.auth().createUserWithEmailAndPassword(document.getElementById('e').value.toString(), document.getElementById('p').value.toString()).catch(function(error) {
  81.         var errorCode = error.code;
  82.         var errorMessage = error.message;
  83.        
  84.       });
  85.     }
  86.  
  87.     function verificarLog(){
  88.       firebase.auth().onAuthStateChanged(function(user) {
  89.         if (user) {
  90.           alert('logado')
  91.         } else {
  92.           // No user is signed in.
  93.           alert('n logado')
  94.         }
  95.       });
  96.     }
  97.  
  98.     function logout(){
  99.       firebase.auth().signOut().then(function() {
  100.         alert('tchau')
  101.       }).catch(function(error) {
  102.         alert(error.message)
  103.       });
  104.     }
  105.    
  106.   </script>
  107.  
  108.  
  109. </body>
  110. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top