Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. $.post/("https://starter-vicks9985.firebaseapp.com/main.rb",
  2. {
  3. "name": "admin",
  4. "email": "admin@example.com",
  5. "password": "secret",
  6. "admin": true,
  7. "role-value": 99,
  8. }
  9. ), console.log("success");
  10.  
  11. {
  12. "rules": {
  13. ".read": true,
  14. "users": {
  15. "$user": {
  16. //can add a message if authenticated
  17. ".write": "auth.uid === $user"
  18. }
  19. },
  20. "rooms": {
  21. "$room": {
  22. "users": {
  23. // can write to the users list only if ADMINISTRATOR
  24. "$user": {
  25. "write":"newData.parent().child(auth.uid).val() === 99"
  26. }
  27. }
  28. }
  29. },
  30. "messages": {
  31. "$room": {
  32. "$message": {
  33. //can add a message if they are a MEMBER (if there was message/chat capability)
  34. ".write": "(!data.exists() && newData.exists() && root.child('rooms/' + $room + '/users/' + auth.uid).val() >= 10)"
  35. }
  36. }
  37. }
  38. }
  39. }
  40.  
  41. $(document).ready(function() {
  42.  
  43. /**
  44. *Set initial firebase ref. Use set to write in first admin user.
  45. */
  46.  
  47. var ref = new Firebase("https://starter-vicks9985.firebaseio.com/");
  48. ref.set({
  49. "name": "Admin",
  50. "email": "admin@example.com",
  51. "password": "secret",
  52. "admin": true
  53. });
  54.  
  55. /** Get email address from loginform, format email, get password
  56. * Firebase keys cannot have a period (.) in them, so this converts the emails to valid keys
  57. */
  58. var emailAddress = function emailToKey(emailAddress){
  59. return btoa(emailAddress);
  60. };
  61. var password = document.getElementById('password');
  62. /**
  63. * Authorize user with email and password, passing in values from form.
  64. */
  65. ref.authWithPassword({
  66. email : emailAddress,
  67. password : password,
  68. }, function(error, authData) {
  69. if (error) {
  70. console.log("Login Failed!", error);
  71. } else {
  72. return authData;
  73. }
  74. });
  75.  
  76. /**
  77. * If user is logged in (valid), redirect to user profile
  78. */
  79.  
  80. ref.onAuth(function(authData) {
  81. window.open="https://starter-vicks9985.firebaseio.com/userprofile/userprofile.html";
  82.  
  83. })
  84.  
  85. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement