Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.post/("https://starter-vicks9985.firebaseapp.com/main.rb",
- {
- "name": "admin",
- "email": "admin@example.com",
- "password": "secret",
- "admin": true,
- "role-value": 99,
- }
- ), console.log("success");
- {
- "rules": {
- ".read": true,
- "users": {
- "$user": {
- //can add a message if authenticated
- ".write": "auth.uid === $user"
- }
- },
- "rooms": {
- "$room": {
- "users": {
- // can write to the users list only if ADMINISTRATOR
- "$user": {
- "write":"newData.parent().child(auth.uid).val() === 99"
- }
- }
- }
- },
- "messages": {
- "$room": {
- "$message": {
- //can add a message if they are a MEMBER (if there was message/chat capability)
- ".write": "(!data.exists() && newData.exists() && root.child('rooms/' + $room + '/users/' + auth.uid).val() >= 10)"
- }
- }
- }
- }
- }
- $(document).ready(function() {
- /**
- *Set initial firebase ref. Use set to write in first admin user.
- */
- var ref = new Firebase("https://starter-vicks9985.firebaseio.com/");
- ref.set({
- "name": "Admin",
- "email": "admin@example.com",
- "password": "secret",
- "admin": true
- });
- /** Get email address from loginform, format email, get password
- * Firebase keys cannot have a period (.) in them, so this converts the emails to valid keys
- */
- var emailAddress = function emailToKey(emailAddress){
- return btoa(emailAddress);
- };
- var password = document.getElementById('password');
- /**
- * Authorize user with email and password, passing in values from form.
- */
- ref.authWithPassword({
- email : emailAddress,
- password : password,
- }, function(error, authData) {
- if (error) {
- console.log("Login Failed!", error);
- } else {
- return authData;
- }
- });
- /**
- * If user is logged in (valid), redirect to user profile
- */
- ref.onAuth(function(authData) {
- window.open="https://starter-vicks9985.firebaseio.com/userprofile/userprofile.html";
- })
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement