diff --git a/README.md b/README.md index 59489da..4213208 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # README for inkletblot.com This is an angularjs project, currently it is a total rebuild of inkletblot.com using the framework. -In the future the forum will be separated from the gallery and 'things' pages. +The forum has been separated from the gallery and 'things' pages. It is at https://github.com/Inkletblot/forum.com > I know things is a stupid name, can you come up with a better one? @@ -13,23 +13,8 @@ In the future the forum will be separated from the gallery and 'things' pages. * Fix client catching of server errors. * Generally strengthen server API, especially once forum is separate. -### Forum: -* ***Create Category, both client and server.*** -* ***Create Topic, both client and server.*** -* **Create Post/Reply, both client and server.** -* ***Fix and test signup.*** -* Create edit post functionality. -* Create delete post functionality. -* Menu only shows applicable items based on user level. - * Update server/client/cookie to include all user info. -* implement correct session with server. - * reduce clients reliance on cookie info to prevent security threats. - ### Gallery/Things: *Deal with this once forum is totally complete, it is now main project* ## Interesting Ideas. -* Implement a text editor for posts? -* Add an account page for users to manage their accounts. -* Add admin ability to remove topics and categories. -* Figure out passing information down the line so that the post page shows the category as well as topic. \ No newline at end of file +* None as of yet x \ No newline at end of file diff --git a/index.html b/index.html index f331cd1..04e5982 100644 --- a/index.html +++ b/index.html @@ -15,12 +15,9 @@ - - -
diff --git a/package.json b/package.json index 0c3b811..13c1bb5 100644 --- a/package.json +++ b/package.json @@ -12,5 +12,5 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "author": "Solomon Laing", - "license": "ISC" + "license": "MIT" } diff --git a/scripts/auth.controllers.js b/scripts/auth.controllers.js deleted file mode 100644 index 5037e1e..0000000 --- a/scripts/auth.controllers.js +++ /dev/null @@ -1,158 +0,0 @@ -daddy.controller("loginCtrlr", function($scope, $cookies, $location, $http, stateData){ - - let titles = { - login : "Login!", - signup : "Not a Member?" - } - $scope.titles = titles - - let message = { - start : "Feel free to", - link : "Sign Up", - end : "at any time!" - } - $scope.message = message - - $scope.setSignup = () => { - stateData.setPage("things") - $location.path("/signup") - } - - $scope.login = () => { - $scope.status = true - $scope.loginStatus = "Logging you in..." - console.log("logging in") - console.log("requesting authentication from server") - $http({ - url : server + "/auth/login?userName="+$scope.user.username+"&userPass="+$scope.user.password, - method : "GET" - }).then((res) => { - console.log(res) - if (res.status == 200) { - console.log("request granted") - let today = new Date() - let expired = new Date(today) - expired.setDate(today.getDate()+1) - $cookies.putObject('user', res.data[0], {expires : expired}) - console.log("set cookie") - stateData.setUser(res.data[0]) - console.log("set data") - stateData.setPage("things") - $location.path("/things") - } - }).catch((res) => { - if (res.status == 400) { - $scope.loginStatus = "Incorrect information!" - console.log("request denied") - } else if (res.status == 500) { - console.log("something went wrong: " + res) - } - }) - } - -}) - -daddy.controller("signupCtrlr", function($scope, $http, $location, stateData) { - - let titles = { - form : "Sign up here!", - success : "Signup Success!" - } - $scope.titles = titles - - let message = { - start : "You account has been created!", - line2 : "Feel free to", - link : "Login", - end : "whenever you like." - } - $scope.message = message - - $scope.success = false - $scope.exists = false - $scope.status = false - - $scope.setLogin = () => { - stateData.setPage("things") - $location.path("/login") - } - - $scope.signup = () => { - $scope.userExists() - $scope.passwordsMatch() - $scope.emailGood() - - if ($scope.match && !$scope.exists && $scope.goodemail) { - $scope.status = false - $scope.submit() - } else { - $scope.status = true - $scope.signupStatus = "Please correct errors above." - } - } - - $scope.emailGood = () => { - if (validateEmail($scope.user.email)) { - $scope.goodemail = true - $scope.emailError = "" - } else { - $scope.goodemail = false - $scope.emailError = "< invalid email." - } - } - - $scope.passwordsMatch = () => { - if ($scope.user.password != $scope.user.confirmPassword) { - $scope.match = false - $scope.passwordError = "< password does not match." - } else { - $scope.match = true - $scope.passwordError = "" - } - } - - $scope.submit = () => { - $http({ - url : server + "/auth/signup?userName=" + $scope.user.username + "&userPass=" + $scope.user.password + "&userEmail=" + $scope.user.email, - method : "POST" - }).then((res) => { - if (res.status == 200) { - console.log("user created successfully") - $scope.success = true - $scope.signupForm.$setPristine() - $scope.user.username = "" - $scope.user.password = "" - $scope.user.confirmPassword = "" - $scope.user.email = "" - } - }).catch((res) => { - if (res.status == 500) { - console.log("whoops...") - } - }) - } - - $scope.userExists = () => { - console.log("checking username is used?") - $http({ - url : server + "/auth/exists?userName=" + $scope.user.username, - method : "POST" - }).then((res) => { - if (res.status == 200) { - console.log(res.data) - if (res.data == true) { - $scope.exists = true - $scope.usernameError= "< username already exists." - } else { - $scope.exists = false - $scope.usernameError = "" - } - } - }).catch((res) => { - if (res.status == 500) { - console.log ("something went wrong") - } - }) - } - -}) \ No newline at end of file diff --git a/scripts/forum.controller.js b/scripts/forum.controller.js deleted file mode 100644 index 19cbf25..0000000 --- a/scripts/forum.controller.js +++ /dev/null @@ -1,469 +0,0 @@ -daddy.controller("forumCtrlr", function($scope, $http, $location) { - - $scope.titles = { - main : "Talking Points...", - list : "Catergories", - last : "Last Topic" - } - - $scope.errors = { - topic : { - show : false, - text : "None yet!" - }, - catagory : { - show : false, - text: "None yet!" - } - } - - $scope.getCategories = () => { - console.log("getting categories form server") - $http({ - url : server + "/forum/category/all", - method : "GET" - }).then((res) => { - if (res.status == 200) { - if (res.data.length == 0) { - $scope.errors.catagory.show = true - } else { - $scope.categories = res.data - for (let i = 0; i < res.data.length; i++) { - $http({ - url : server + "/forum/category/topic/last?cat=" + res.data[i].catNo, - method : "GET" - }).then((res) => { - if (res.status == 200) { - console.log("topicNo: " + res.data.topicNo) - // if (res.data.topicNo == null) { - // $scope.errors.topic.show = true - // } else { - res.data.topicDate = niceDate(res.data.topicDate) - $scope.categories[i].lastTopic = res.data - // } - } else { - console.log("server has encountered an error: " + res.status) - } - }) - } - console.log(res) - } - } - }).catch((res) => { - console.log("server has encountered an error: " + res.status) - }) - } - - $scope.setCat = (catNo) => { - $location.path("/forum/category/"+catNo) - } - - $scope.setTopic = (topicNo) => { - $location.path("/forum/topic/"+topicNo) - } - -}) - -daddy.controller("createTopicCtrlr", function($scope, $location, $http, stateData) { - - $scope.titles = { - form : "Create a topic!" - } - - $scope.status = { - show : false, - text : "" - } - - let error = { - loggedIn : { - show : false, - text1 : "You must be", - link1 : "Logged In", - text2 : "to create a topic!" - }, - userLevel : { - show : false, - text1 : "No categories have been created, please contact an administrator about creating some.", - text2 : "Administrator contact: solomonlaing@inkletblot.com" - }, - category : { - show : false - } - } - - $scope.error = error - - $scope.start = () => { - if (stateData.state.user.userName == null) { - console.log("not logged in.") - error.loggedIn.show = true - } - if (stateData.state.user.userLevel == 0) { - console.log("user not an admin.") - error.userLevel.show = true - } - $scope.getCategories() - } - - $scope.getCategories = () => { - console.log("getting categories form server") - $http({ - url : server + "/forum/category/all", - method : "GET" - }).then((res) => { - if (res.status == 200) { - if (res.data.length == 0) { - $scope.errors.catagory.show = true - } else { - $scope.categories = res.data - console.log(res) - } - } - }).catch((res) => { - console.log("server has encountered an error: " + res.status) - }) - } - - $scope.setLogin = () => { - $location.path("/login") - stateData.setPage("things") - } - - $scope.createTopic = () => { - console.log("sending new topic to server!!") - let formData = new FormData() - formData.append('topicSubject', $scope.topic.topicSubject) - formData.append('topicCat', $scope.topic.topicCat) - formData.append('userNo', stateData.state.user.userNo) - $http({ - url : server + "/forum/topic/create", - method : "POST", - data : formData, - headers : { 'Content-Type' : undefined }, - transformRequest : angular.identity - }).then((res) => { - if (res.status == 200) { - console.log("topic submitted") - $scope.createPost($scope.topic.postContent, res.data.topicNo) - } - }).catch((res) => { - if (res.status == 500) { - console.log("something went wrong: " + res.data) - $scope.status.text = "Something went wrong: " + res.status - } - }) - } - - $scope.createPost = (postContent, topicNo) => { - console.log("sending new post to server") - let formData = new FormData() - formData.append('postContent', postContent) - formData.append('topicNo', topicNo) - formData.append('userNo', stateData.state.user.userNo) - $http({ - url : server + "/forum/topic/post/create", - method : "POST", - data : formData, - headers : { 'Content-Type' : undefined }, - transformRequest : angular.identity - }).then((res) => { - if (res.status == 200) { - console.log("post added") - $location.path("/forum/topic/" + topicNo) - } - }).catch((res) => { - if (res.status == 500) { - console.log("something went wrong: " + res.data) - $scope.status.text = "Something went wrong: " + res.status - } - }) - } -}) - -daddy.controller("createCategoryCtrlr", function($scope, $http, $location, stateData) { - - let error = { - loggedIn : { - show : false, - text1 : "You must be", - link1 : "Logged In", - text2 : "to create a category!" - }, - userLevel : { - show : false, - text1 : "You must be an administrator to create a category!" - } - } - - $scope.error = error - - $scope.titles = { - form : "Create a Category!" - } - - $scope.status = { - show : false, - text : "" - } - - $scope.start = () => { - if (stateData.state.user.userName == null) { - error.loggedIn.show = true - } - if (stateData.state.user.userLevel == 0) { - error.userLevel.show = true - } - } - - $scope.setLogin = () => { - $location.path("/login") - stateData.setPage("things") - } - - $scope.createCategory = () => { - $scope.status.show = true - $scope.status.text = "Adding category..." - - let formData = new FormData() - formData.append('catName', $scope.category.catName) - formData.append('catDescr', $scope.category.catDescr) - - console.log("sending to server...") - $http({ - url : server + "/forum/category/create", - method : "POST", - data : formData, - headers : { 'Content-Type' : undefined }, - transformRequest : angular.identity - }).then((res) => { - if (res.status == 200) { - console.log("category submitted") - $location.path("/forum/category/" + res.data.catNo) - } - }).catch((res) => { - if (res.status == 500) { - console.log("something went wrong: " + res.data) - $scope.status.text = "Something went wrong: " + res.status - } - }) - } - -}) - -daddy.controller("topicCtrlr", function($scope, $routeParams, $timeout, $http, $location, stateData) { - stateData.setPage("forum") - - $scope.error = false - $scope.message = { - start : null, - link : "Go Back!" - } - $scope.logged = { - text1 : "You must be", - link1 : "logged in", - text2 : "to reply. You can also", - link2 : "sign up", - text3 : "for an account." - } - $scope.status = { - show : false, - text : "", - } - $scope.first = { - show : false, - text : "Be the first to create a post, write below..." - } - - $scope.getTopic = () => { - console.log("getting topic") - $http({ - url : server + "/forum/topic?topic=" + $routeParams.topicNo, - method : "GET" - }).then((res) => { - if (res.status == 200) { - let topic = res.data - // if (res.data.posts.length == 0) { - // $scope.first.show = true - // } - - for (let i = 0; i < topic.posts.length; i++) { - topic.posts[i].postDate = niceDate(topic.posts[i].postDate) - } - $scope.topic = topic - } - }).catch((res) => { - if (res.status == 404) { - console.log(res.data) - $scope.error = true - $scope.message.start = "No such topic," - } else if (res.status == 500) { - console.log(res.data) - $scope.error = true - $scope.message.start = "An error has occured: " + res.status - } else { - console.log(res) - } - }) - } - - $scope.makeReply = (topicNo) => { - console.log("sending new post to server") - let formData = new FormData() - formData.append('postContent', $scope.reply.postContent) - formData.append('topicNo', topicNo) - formData.append('userNo', stateData.state.user.userNo) - $http({ - url : server + "/forum/topic/post/create", - method : "POST", - data : formData, - headers : { 'Content-Type' : undefined }, - transformRequest : angular.identity - }).then((res) => { - if (res.status == 200) { - console.log("post added") - $scope.reply.postContent = "" - $timeout(function() { $scope.getTopic() }, 2000) - } - }).catch((res) => { - if (res.status == 500) { - console.log("something went wrong: ") - console.log(res.data) - $scope.status.text = "Something went wrong: " + res.status - } - }) - } - - $scope.setLogin = () => { - $location.path("/login") - } - - $scope.setSignup = () => { - $location.path("/signup") - } - - $scope.deletePost = (postNo) => { - if (!window.confirm("Are you sure you want to delete this post?")) { - return - } - $http({ - url : server + "/forum/topic/post/delete?postNo=" + postNo, - method : "POST" - }).then((res) => { - if (res.status == 200) { - console.log("post deleted") - for (let i = 0; i < $scope.topic.posts.length; i++) { - if ($scope.topic.posts[i].postNo == postNo) { - $scope.topic.posts[i].postContent = "[deleted]" - } - } - } - }).catch((res) => { - if (res.status == 500) { - console.log("something went wrong: ") - console.log(res.data) - $scope.status.text = "Something went wrong: " + res.status - } - }) - } - - $scope.editPost = (postNo, postContent) => { - /* This is incomplete, need to figure out hiding the edit box after edit. Would rather not use timeout. */ - console.log("submitting edited post") - let formData = new FormData() - formData.append("postNo", postNo) - formData.append("postContent", postContent) - $http({ - url : server + "/forum/topic/post/edit", - method : "POST", - data : formData, - headers : { 'Content-Type' : undefined }, - transformRequest : angular.identity - }).then((res) => { - if (res.status == 200) { - console.log("post edited") - for (let i = 0; i < $scope.topic.posts.length; i++) { - if ($scope.topic.posts[i].postNo == postNo) { - $scope.topic.posts[i].postContent = postContent + " [edited]" - } - } - } - }).catch((res) => { - if (res.status == 500) { - console.log("something went wrong: ") - console.log(res.data) - $scope.status.text = "Something went wrong: " + res.status - } - }) - } - -}) - -daddy.controller("categoryCtrlr", function($scope, $http, $routeParams, $location, stateData) { - stateData.setPage("forum") - - $scope.errors = { - exists : { - show : false, - text1 : "No such category,", - link1 : "Go Back!" - }, - empty : { - show : false, - text : "No topics have been created yet..." - } - } - - $scope.titles = { - topic : "topic", - date : "date" - } - - $scope.getCat = () => { - console.log("getting category") - $http({ - url : server + "/forum/category?cat=" + $routeParams.catNo, - method : "GET" - }).then((res) => { - console.log(res) - if (res.status == 200) { - let category = res.data - if (category.topics.length == 0) { - $scope.errors.empty.show = true - } else { - for (let i = 0; i < category.topics.length; i++) { - category.topics[i].topicDate = niceDate(category.topics[i].topicDate) - } - } - $scope.category = category - } - }).catch((res) => { - if (res.status == 404) { - console.log(res.data) - $scope.errors.exists.show = true - } else if (res.status == 500) { - console.log(res.data) - } else { - console.log(res) - } - }) - } - - $scope.setTopic = (topicNo) => { - $location.path("/forum/topic/"+topicNo) - } - - $scope.setForum = () => { - $location.path("/forum") - } -}) - -niceDate = (string) => { - let date = new Date(string) - return "on " + date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate() + " at " + date.getHours() + ":" + date.getMinutes() -} - -isNum = (str) => { - let re = /^[0-9]+$/ - return re.test(String(str).toLowerCase()) -} \ No newline at end of file diff --git a/scripts/main.js b/scripts/main.js index 121dbc4..709458b 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,36 +1,18 @@ -let daddy = angular.module("daddy", ["ngRoute", "ngAnimate", "ngCookies"]) +let daddy = angular.module("daddy", ["ngRoute", "ngAnimate"]) let server = "http://127.0.0.1:7001" -daddy.controller("bodyCtrlr", function($scope, $cookies, stateData){ +daddy.controller("bodyCtrlr", function($scope, stateData){ $scope.state = stateData.state - - let user = $cookies.getObject('user') - - if (user == null) { - stateData.logOut() - } else { - stateData.setUser(user) - } }) -daddy.controller("headerCtrlr", function($scope, stateData){ +daddy.controller("headerCtrlr", function($scope){ $scope.subtitle = "Inks Things." }) -daddy.controller("navCtrlr", function($scope, $location, $http, $cookies, stateData){ - - $scope.setLogin = () => { - stateData.setPage("things") - $location.path("/login") - } - - $scope.setSignup = () => { - stateData.setPage("things") - $location.path("/signup") - } +daddy.controller("navCtrlr", function($scope, $location, $http, stateData){ $scope.setThings = () => { stateData.setPage("things") @@ -46,21 +28,6 @@ daddy.controller("navCtrlr", function($scope, $location, $http, $cookies, stateD stateData.setPage("gallery") $location.path("/gallery/upload") } - - $scope.setForum = () => { - stateData.setPage("forum") - $location.path("/forum") - } - - $scope.setTopicCreate = () => { - stateData.setPage("forum") - $location.path("/forum/create/topic") - } - - $scope.setCategoryCreate = () => { - stateData.setPage("forum") - $location.path("/forum/create/category") - } switch ($location.path()) { case "": @@ -74,27 +41,6 @@ daddy.controller("navCtrlr", function($scope, $location, $http, $cookies, stateD case "/gallery/upload": $scope.setUpload() break - case "/forum": - $scope.setForum() - break - case "/forum/topic": - // this has to be done in the controller - break - case "/forum/create/topic": - $scope.setTopicCreate() - break - case "/forum/category": - // this has to be done in the controller - break - case "/forum/create/category": - $scope.setCategoryCreate() - break - case "/login": - $scope.setLogin() - break - case "/signup": - $scope.setSignup() - break } $scope.clearGallery = () => { @@ -116,11 +62,6 @@ daddy.controller("navCtrlr", function($scope, $location, $http, $cookies, stateD }) } - $scope.logOut = () => { - $cookies.remove('user') - stateData.logOut() - } - }) daddy.controller("thingsCtrlr", function($scope){ @@ -137,13 +78,6 @@ daddy.config(function ($routeProvider) { $routeProvider.when("/pet", {templateUrl : "views/pet.html", controller : "petCtrlr"}) $routeProvider.when("/gallery", {templateUrl : "views/gallery/gallery.html", controller : "galleryCtrlr"}) $routeProvider.when("/gallery/upload", {templateUrl : "views/gallery/upload.html", controller : "uploadCtrlr"}) - $routeProvider.when("/forum", {templateUrl : "views/forum/forum.html", controller : "forumCtrlr"}) - $routeProvider.when("/forum/create/topic", {templateUrl : "views/forum/create_topic.html", controller : "createTopicCtrlr"}) - $routeProvider.when("/forum/topic/:topicNo", {templateUrl : "views/forum/topic.html", controller : "topicCtrlr"}) - $routeProvider.when("/forum/create/category", {templateUrl : "views/forum/create_category.html", controller : "createCategoryCtrlr"}) - $routeProvider.when("/forum/category/:catNo", {templateUrl : "views/forum/category.html", controller : "categoryCtrlr"}) - $routeProvider.when("/login", {templateUrl : "views/login.html", controller : "loginCtrlr"}) - $routeProvider.when("/signup", {templateUrl : "views/signup.html", controller : "signupCtrlr"}) $routeProvider.otherwise({template : "{{category.catDescr}}
-| {{titles.topic}} | -{{titles.date}} | -
|---|---|
| {{topic.topicSubject}} | -{{topic.topicDate}} | -
| {{errors.empty.text}} | -|
{{errors.exists.text1}} {{errors.exists.link1}}
-{{status.text}}
-{{error.loggedIn.text1}} {{error.loggedIn.link1}} {{error.loggedIn.text2}}
-{{error.userLevel.text1}}
-{{error.category.text1}} {{error.category.link1}} {{error.category.text2}}
-{{error.userLevel.text1}}
{{error.userLevel.text2}}
{{status.text}}
-{{error.loggedIn.text1}} {{error.loggedIn.link1}} {{error.loggedIn.text2}}
-| {{titles.list}} | -{{titles.last}} | -|
|---|---|---|
| {{cat.catName}} - {{cat.catDescr}} |
- {{cat.lastTopic.topicSubject}} {{cat.lastTopic.topicDate}} | -{{errors.topic.text}} | -
| {{errors.catagory.text}} | -||
| {{topic.topicSubject}} | -|||
|---|---|---|---|
|
- {{first.text}} - |
- |||
| {{post.postContent}} | -{{post.postContent}} [delete] [edit]
-
-
- - - |
- {{post.user.userName}} {{post.postDate}} |
- |
| {{logged.text1}} {{logged.link1}} {{logged.text2}} {{logged.link2}} {{logged.text3}} | -
-
- {{status.text}} - |
- ||
{{message.start}} {{message.link}}
-{{loginStatus}}
-{{message.start}} {{message.link}} {{message.end}}
-{{signupStatus}}
-{{message.start}}
{{message.line2}} {{message.link}} {{message.end}}