Advertisement
Guest User

Untitled

a guest
Aug 4th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. <div class="col l7" id="signup">
  2. <h4>Signup</h4>
  3. <div class="form card">
  4. <br>
  5. <div class="switch">
  6. <label>
  7. Student
  8. <input name="student_" id="student_" type="checkbox">
  9. <span class="lever"></span>
  10. Staff
  11. </label>
  12. </div>
  13. <div class="container">
  14. <input type="text" placeholder="Name" id="signup_fullname">
  15. <!--student/staff-->
  16. <input type="text" placeholder="Matric Number/Staff no." id="signup_matric">
  17. <input type="email" placeholder="Email" id="signup_email">
  18. <div class="input-field col s12">
  19. <select id="signup_dept">
  20. <option value="" disabled selected>Select your department</option>
  21. <option value="ics">ICS</option>
  22. <option value="masscomm">Mass Comm.</option>
  23. <option value="lis">Library Science</option>
  24. <option value="tcs">Telecomm Science</option>
  25. <option value="csc">Computer Science</option>
  26. </select>
  27. </div>
  28. <div class="input-field col s12">
  29. <select id="signup_level">
  30. <option value="" disabled selected>Select your Level</option>
  31. <option value="100">100 Level</option>
  32. <option value="200">200 Level</option>
  33. <option value="300">300 Level</option>
  34. <option value="400">400 Level</option>
  35. <option value="500">500 Level</option>
  36. </select>
  37. </div>
  38. <div class="input-field col s12">
  39. <select id="signup_religion">
  40. <option value="" disabled selected>Select your religion</option>
  41. <option value="1">Islam</option>
  42. <option value="2">Christianity</option>
  43. </select>
  44. </div>
  45. <input type="password" placeholder="password" id="signup_password">
  46. <!--<input type="password" placeholder="Confirm password" id="signup_confirm_password">-->
  47. <button class="btn-large second-color" id="btnSignUp">signup</button></a>
  48. </div>
  49. </div>
  50. <br>
  51. </div>
  52.  
  53. readystatemode = false;
  54. (function () {
  55. var config = {
  56. apiKey: "<my API key>",
  57. authDomain: "<my auth domain>",
  58. databaseURL: "<my database url>",
  59. storageBucket: "<my storage bucket url>",
  60. };
  61. firebase.initializeApp(config);
  62.  
  63. // Get Elements
  64. var student_ = document.getElementById('student_'); // check whether is a student or staff; expect on or off
  65. var student__;
  66. if (student_.value == "on") {
  67. student__ = "student";
  68. } else {
  69. student__ = "staff";
  70. }
  71. var signup_fullname = document.getElementById('signup_fullname');
  72. var signup_matric = document.getElementById('signup_matric');
  73. var signup_email = document.getElementById('signup_email');
  74. var signup_dept = document.getElementById('signup_dept');
  75. var signup_level = document.getElementById('signup_level');
  76. var signup_religion = document.getElementById('signup_religion');
  77. var signup_password = document.getElementById('signup_password');
  78. var login_email = document.getElementById('login_email');
  79. var login_password = document.getElementById('login_password');
  80. // buttons
  81. var btnLogin = document.getElementById("btnLogin");
  82. var btnSignUp = document.getElementById("btnSignUp");
  83.  
  84. // signup event
  85. btnSignUp.addEventListener('click', e => {
  86. // Get Email and pass
  87. //TODO: check for real emails
  88. console.log("just clicked the signup button");
  89.  
  90. var email = signup_email.value;
  91. var pass = signup_password.value;
  92. var auth = firebase.auth();
  93. // sign up
  94. const promise = auth.createUserWithEmailAndPassword(email, pass);
  95. promise
  96. .catch(e => console.log(e.message));
  97.  
  98. if (auth.currentUser != null) {
  99. auth.currentUser.updateProfile({
  100. displayName: signup_fullname,
  101. userCategory: student__,
  102. matric: signup_matric,
  103. department: signup_dept,
  104. level: signup_level,
  105. religion: signup_religion
  106. }).then(function () {
  107. console.log("update successful");
  108. window.readystatemode = true;
  109. }, function (error) {
  110. console.log("update failed");
  111. });
  112. }
  113. });
  114.  
  115. firebase.auth().onAuthStateChanged(firebaseUser => {
  116. if (firebaseUser && window.readystatemode) {
  117. console.log(firebaseUser);
  118. btnLogout.classList.remove('hide');
  119. window.location('./dashboard.html');
  120. } else {
  121. console.log("not logged in");
  122. btnLogout.classList.add('hide');
  123. }
  124. });
  125.  
  126. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement