From 355c6668a44c54616bb377f526e664e7fd486c2b Mon Sep 17 00:00:00 2001 From: irene024081 Date: Wed, 29 Nov 2017 10:20:48 -0500 Subject: [PATCH 1/2] User Comment Added: Facebook login, email/password signup, email/password login, log out, edit blog, add comment --- braincradleapp/.DS_Store | Bin 10244 -> 10244 bytes braincradleapp/app.js | 2 + braincradleapp/components/auth/auth.js | 116 ++++++++++++++++--- braincradleapp/components/auth/login.html | 14 +++ braincradleapp/components/auth/register.html | 1 + braincradleapp/components/blogs/blogs.css | 15 +++ braincradleapp/components/blogs/blogs.html | 79 ++++++++++++- braincradleapp/components/blogs/blogs.js | 65 ++++++++++- braincradleapp/components/navbar/header.html | 1 + braincradleapp/components/navbar/navbar.js | 10 ++ braincradleapp/index.html | 1 + 11 files changed, 281 insertions(+), 23 deletions(-) diff --git a/braincradleapp/.DS_Store b/braincradleapp/.DS_Store index 2b0a0b9a77c93df8d29e4502847c4984cfbcbdbf..5b2275c3ab1269cd0f5ed4b5e04daaac12ec2dff 100644 GIT binary patch delta 28 kcmZn(XbG6$&nUbxU^hRb@Ma!?THcK%bxfPt75=gV0EyxWR{#J2 delta 154 zcmZn(XbG6$&nUhzU^hRb_+}n~T3$g;h9ZVkhGK?%hEgCanIUzup`d6whA2aEZoZ34 oN@+R2vr3chQZ1Cxdj^wKQeA+SNO{g08w=&yZ`_I diff --git a/braincradleapp/app.js b/braincradleapp/app.js index aaab72a..be15f92 100755 --- a/braincradleapp/app.js +++ b/braincradleapp/app.js @@ -18,7 +18,9 @@ ,'braincradle.app.projects' ,'braincradle.app.solutions' ,'braincradle.app.tutorials' + ,'braincradle.app.FBauth' ]) + .constant('FBMSG', 'https://braincradleai.firebaseio.com/') .service('AppFirebase',function(){ var self = this; // Initialize Firebase diff --git a/braincradleapp/components/auth/auth.js b/braincradleapp/components/auth/auth.js index c2419f8..7beca46 100755 --- a/braincradleapp/components/auth/auth.js +++ b/braincradleapp/components/auth/auth.js @@ -1,3 +1,4 @@ + (function() { 'use strict'; angular.module('braincradle.app.auth', []) @@ -39,31 +40,108 @@ return AppFirebase.auth(); }) - .controller('AuthController',function(Auth,$state,AppConfig,AppFirebase){ + .controller('AuthController',function($scope,Auth,$state,AppConfig,AppFirebase){ var self = this; var provider = new firebase.auth.GoogleAuthProvider(); - Auth.signInWithPopup(provider).then(function(result) { - // This gives you a Google Access Token. You can use it to access the Google API. - var token = result.credential.accessToken; - // The signed-in user info. - var user = result.user; - console.log(user); - $state.go('home'); - }).catch(function(error) { - // Handle Errors here. - var errorCode = error.code; - var errorMessage = error.message; - // The email of the user's account used. - var email = error.email; - // The firebase.auth.AuthCredential type that was used. - var credential = error.credential; + self.googleLogin = function() { + Auth.signInWithPopup(provider).then(function (result) { + // This gives you a Google Access Token. You can use it to access the Google API. + var token = result.credential.accessToken; + // The signed-in user info. + var user = result.user; + console.log(user); + $state.go('home'); + }).catch(function (error) { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; - self.error.message = errorCode + ":" + errorMessage; - }); + self.error.message = errorCode + ":" + errorMessage; + }); + } + + var providerFB = new firebase.auth.FacebookAuthProvider(); + self.facebookLogin = function() { + console.log("using functions") + Auth.signInWithPopup(providerFB).then(function(result) { + // This gives you a Facebook Access Token. You can use it to access the Facebook API. + var token = result.credential.accessToken; + // The signed-in user info. + var user = result.user; + // ... + }).catch(function(error) { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + // ... + self.error.message = errorCode + ":" + errorMessage; + }); + + } + self.register = function() { + console.log(self.user.email) + var result = Auth.createUserWithEmailAndPassword(self.user.email, self.user.password) + .catch(function(error) { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // .. + self.error.message = errorCode + ":" + errorMessage; + }); + result.then(function(userData){ + console.log("User Successfully created with email: ", userData.email) + }, function(error) { + console.log("an error occurred ", self.error.message) + }) + } + + self.login = function () { + + var result = Auth.signInWithEmailAndPassword(self.user.email, self.user.password).catch(function(error) { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // ... + self.error.message = errorCode + ":" + errorMessage; + });; + result.then(function(authData){ + console.log("User Successfully logged in with uid: ", authData.uid) + }, function(error) { + console.log("Authentication Failed: ", self.error.message) + }) + } }) +})(); + +window.fbAsyncInit = function () { + FB.init({ + appId: '130858520918634', + autoLogAppEvents: true, + xfbml: true, + version: 'v2.11' + }); +}; + +(function (d, s, id) { + var js, fjs = d.getElementsByTagName(s)[0]; + if (d.getElementById(id)) { + return; + } + js = d.createElement(s); + js.id = id; + js.src = "https://connect.facebook.net/en_US/sdk.js"; + fjs.parentNode.insertBefore(js, fjs); +}(document, 'script', 'facebook-jssdk')); -})(); \ No newline at end of file diff --git a/braincradleapp/components/auth/login.html b/braincradleapp/components/auth/login.html index ddc62bd..4924d5e 100755 --- a/braincradleapp/components/auth/login.html +++ b/braincradleapp/components/auth/login.html @@ -1,3 +1,4 @@ +
@@ -24,10 +25,23 @@
+
+
+ Not a user? Sign Up

+
+
+
+
+ + +
+
+ + \ No newline at end of file diff --git a/braincradleapp/components/auth/register.html b/braincradleapp/components/auth/register.html index abdcca9..34ded0d 100755 --- a/braincradleapp/components/auth/register.html +++ b/braincradleapp/components/auth/register.html @@ -34,6 +34,7 @@
+ Already a user? Log in

diff --git a/braincradleapp/components/blogs/blogs.css b/braincradleapp/components/blogs/blogs.css index e7f0ed6..1e3ddf9 100644 --- a/braincradleapp/components/blogs/blogs.css +++ b/braincradleapp/components/blogs/blogs.css @@ -27,6 +27,21 @@ ul.post-grid li:hover h3 { overflow: hidden; } +.blog-post{ + min-height: 140px; + overflow: hidden; +} + .blog-post-summary-buttons{ border-top: 1px solid #3a8bab; +} +.comment-container{ + padding: 30px; + background-color: #ffffff; +} +.comment-post{ + min-height: 40px; + max-height: 140px; + overflow: hidden; + } \ No newline at end of file diff --git a/braincradleapp/components/blogs/blogs.html b/braincradleapp/components/blogs/blogs.html index 3fad7a8..6ae07ab 100644 --- a/braincradleapp/components/blogs/blogs.html +++ b/braincradleapp/components/blogs/blogs.html @@ -36,15 +36,90 @@

{{post.blog_title}}

All posts +
+ +

{{blogsCtrl.current_post.blog_title}}

-

+

- +

+
+
+

User comments

+

{{blogsCtrl.current_post.comment.comment_title}}

+

author: {{blogsCtrl.current_post.comment.author.email}}

+

+
+ + +
+

Comment

+
+
+
+
+
+ + +
+
+
+
+
+
+ +
+
+
+
+
 
+
+
+ Save Comment   + Cancel +
+
+
+
+ +
+

Edit Post

+
+
+
+
+
+ + +
+
+
+
+
+
+ +
+
+
+
+
 
+
+
+ Save Change   + Cancel +
+
+
+
+
+

Add New Post

diff --git a/braincradleapp/components/blogs/blogs.js b/braincradleapp/components/blogs/blogs.js index 645584b..2c46c23 100644 --- a/braincradleapp/components/blogs/blogs.js +++ b/braincradleapp/components/blogs/blogs.js @@ -25,10 +25,14 @@ var database = AppFirebase.database(); var blogsRef = database.ref().child("blogs"); + self.blogs = $firebaseArray(blogsRef); self.addNew = false; self.viewPost = false; + self.editPost = false; + self.leaveComment = false; + self.hasComment = false; self.IsUserAutheticated = function(){ if(self.currentUser){ @@ -43,14 +47,14 @@ self.newpost = {} } self.Save = function () { + var newKey = firebase.database().ref().child('blogs').push().key; var updateObj = { + post_id: newKey, blog_title: self.newpost.blog_title, blog_post: self.newpost.blog_post, author: {email:self.currentUser.email,user:self.currentUser.displayName} } - console.log(updateObj); // Get a key for a new record. - var newKey = firebase.database().ref().child('blogs').push().key; database.ref('blogs/'+newKey).set(updateObj); // Done @@ -65,10 +69,67 @@ self.ViewPost = function (post) { self.viewPost = true; self.current_post = post; + self.ifComment() + console.log(self.hasComment) } + self.AllPosts = function () { self.viewPost = false; } + self.EditPost = function () { + self.editPost = true; + } + self.SaveChange = function () { + var updateRef = blogsRef.child(self.current_post.post_id) + var updates = {}; + var postData = { + "post_id": self.current_post.post_id, + "blog_title": self.current_post.blog_title, + "blog_post" :self.current_post.blog_post, + "author": self.current_post.author} + + updates['/blogs/' + self.current_post.post_id] = postData; + firebase.database().ref().update(updates) + + self.editPost = false; + + } + self.Comment = function () { + self.leaveComment = true; + self.comment = {} + + } + self.SaveComment = function () { + self.comment.author = {email:self.currentUser.email,user:self.currentUser.displayName} + console.log(self.comment) + var postData = { + "post_id": self.current_post.post_id, + "blog_title": self.current_post.blog_title, + "blog_post" :self.current_post.blog_post, + "author": self.current_post.author, + comment: self.comment + } + var updates = {}; + updates['/blogs/' + self.current_post.post_id] = postData; + firebase.database().ref().update(updates) + self.comment = {} + self.leaveComment = false; + self.displayComment += 1; + } + + self.ifComment = function () { + console.log("ifComment") + var currentBlog = firebase.database().ref().child('blogs').child(self.current_post.post_id) + console.log(currentBlog) + currentBlog.child("comment").once("value").then(function(snapshot){ + if(snapshot.val()){ + console.log(snapshot.val()) + self.hasComment = true; + } + } + ) + } + }) diff --git a/braincradleapp/components/navbar/header.html b/braincradleapp/components/navbar/header.html index 135d468..d3e20ec 100755 --- a/braincradleapp/components/navbar/header.html +++ b/braincradleapp/components/navbar/header.html @@ -8,6 +8,7 @@
+
diff --git a/braincradleapp/components/navbar/navbar.js b/braincradleapp/components/navbar/navbar.js index 28a6fd4..a70f628 100755 --- a/braincradleapp/components/navbar/navbar.js +++ b/braincradleapp/components/navbar/navbar.js @@ -39,6 +39,16 @@ } }); + self.signOut = function () { + console.log("clicked") + firebase.auth().signOut().then(function () { + // Sign-out successful. + }).catch(function (error) { + // An error happened. + }); + + } + }) })(); diff --git a/braincradleapp/index.html b/braincradleapp/index.html index 83de45f..a90a4a1 100755 --- a/braincradleapp/index.html +++ b/braincradleapp/index.html @@ -83,6 +83,7 @@ + From 718fe5d7a5e0d0f76f852d6517dd41f1ee0a6005 Mon Sep 17 00:00:00 2001 From: irene024081 Date: Wed, 29 Nov 2017 22:54:04 -0500 Subject: [PATCH 2/2] add id --- braincradleapp/components/navbar/header.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/braincradleapp/components/navbar/header.html b/braincradleapp/components/navbar/header.html index d3e20ec..511f5e2 100755 --- a/braincradleapp/components/navbar/header.html +++ b/braincradleapp/components/navbar/header.html @@ -6,7 +6,7 @@
- +