Permalink
Browse files

Added users page, auth shoudl be working

  • Loading branch information...
1 parent a40c8fd commit da6ae6ac636677c97d567579f76d96fff94f1945 iplk committed Oct 11, 2012
Showing with 105 additions and 59 deletions.
  1. +29 −5 web/assets/cslib/Users.coffee
  2. +76 −54 web/assets/js/Users.js
@@ -6,6 +6,9 @@ usernameInput = $ "#usernameInput"
passwordInput = $ "#passwordInput"
form_login = $ "#form_login"
+
+
+
###
setCookie = (name, value) ->
c_value = escape value
@@ -14,7 +17,7 @@ setCookie = (name, value) ->
console.log("Setting cookie to '#{c_name}=#{value};'")
console.log "Cookies is '#{document.cookie}'"
###
-
+###
getCookie = (name) ->
cookies = document.cookie.split(";")
console.log "cookies found #{cookies}"
@@ -37,7 +40,7 @@ setLogInControl = () ->
console.log("Is a user")
adminMenu.css {display: "none"}
loginMenu.css {display: "block"}
-
+###
### Old Testing controls
logoutButton.click ->
setCookie "status", "User"
@@ -50,10 +53,30 @@ loginButton.click ->
setLogInControl()
###
-# Check for the admin cookie and set the status...
+# Check with the server to see if this session has admin priviliges
$ ->
+ success = (data) ->
+ status = JSON.parse(data).status
+ console.log "Success #{data}"
+ if status == "true"
+ console.log("Is an Admin")
+ adminMenu.css {display: "block"}
+ loginMenu.css {display: "none"}
+ else
+ console.log("Is a user")
+ adminMenu.css {display: "none"}
+ loginMenu.css {display: "block"}
+
+ fail = (data) ->
+ console.log "Fail #{data}"
+
+ window.RWCall success, fail, {}, "status", "", "GET"
+
+ ###
setLogInControl()
+ ###
+ ###
form_login.submit ->
$.ajax {
@@ -70,9 +93,10 @@ form_login.submit ->
loginMenu.removeClass "open"
return false;
-
+###
+###
setInterval setLogInControl, 1000
-
+ ###
View
@@ -1,5 +1,5 @@
(function() {
- var adminMenu, form_login, getCookie, isAdmin, loginButton, loginMenu, logoutButton, passwordInput, setLogInControl, usernameInput;
+ var adminMenu, form_login, loginButton, loginMenu, logoutButton, passwordInput, usernameInput;
adminMenu = $("#adminMenu");
@@ -24,42 +24,30 @@
console.log "Cookies is '#{document.cookie}'"
*/
- getCookie = function(name) {
- var c, cookie, cookies, _i, _len;
- cookies = document.cookie.split(";");
- console.log("cookies found " + cookies);
- for (_i = 0, _len = cookies.length; _i < _len; _i++) {
- c = cookies[_i];
- console.log("Cookie is " + c);
- }
- cookie = c.split("=");
- if (name === cookie[0]) return unescape(cookie[1]);
- };
-
- isAdmin = function() {
- return getCookie("status") === "Admin";
- };
-
- setLogInControl = function() {
- console.log("setLogInControl Called");
- if (isAdmin()) {
- console.log("Is an Admin");
- adminMenu.css({
- display: "block"
- });
- return loginMenu.css({
- display: "none"
- });
- } else {
- console.log("Is a user");
- adminMenu.css({
- display: "none"
- });
- return loginMenu.css({
- display: "block"
- });
- }
- };
+ /*
+ getCookie = (name) ->
+ cookies = document.cookie.split(";")
+ console.log "cookies found #{cookies}"
+ for c in cookies
+ console.log("Cookie is #{c}")
+ cookie = c.split "="
+ if name == cookie[0]
+ return unescape cookie[1]
+
+ isAdmin = () ->
+ return getCookie("status") == "Admin"
+
+ setLogInControl = () ->
+ console.log("setLogInControl Called")
+ if isAdmin()
+ console.log("Is an Admin")
+ adminMenu.css {display: "block"}
+ loginMenu.css {display: "none"}
+ else
+ console.log("Is a user")
+ adminMenu.css {display: "none"}
+ loginMenu.css {display: "block"}
+ */
/* Old Testing controls
logoutButton.click ->
@@ -74,25 +62,59 @@
*/
$(function() {
- return setLogInControl();
- });
-
- form_login.submit(function() {
- $.ajax({
- type: "POST",
- data: $(this).serialize(),
- cache: false,
- url: "http://api.riverwatch.co.nz/wainz/login",
- crossDomain: true,
- dataType: "jsonp",
- success: function() {
- return alert("Success");
+ var fail, success;
+ success = function(data) {
+ var status;
+ status = JSON.parse(data).status;
+ console.log("Success " + data);
+ if (status === "true") {
+ console.log("Is an Admin");
+ adminMenu.css({
+ display: "block"
+ });
+ return loginMenu.css({
+ display: "none"
+ });
+ } else {
+ console.log("Is a user");
+ adminMenu.css({
+ display: "none"
+ });
+ return loginMenu.css({
+ display: "block"
+ });
}
- });
- loginMenu.removeClass("open");
- return false;
+ };
+ fail = function(data) {
+ return console.log("Fail " + data);
+ };
+ return window.RWCall(success, fail, {}, "status", "", "GET");
+ /*
+ setLogInControl()
+ */
});
- setInterval(setLogInControl, 1000);
+ /*
+ form_login.submit ->
+
+ $.ajax {
+ type: "POST"
+ data : $(this).serialize()
+ cache: false
+ url: "http://api.riverwatch.co.nz/wainz/login"
+ crossDomain: true
+ dataType: "jsonp"
+ success: () ->
+ alert "Success"
+ }
+
+ loginMenu.removeClass "open"
+
+ return false;
+ */
+
+ /*
+ setInterval setLogInControl, 1000
+ */
}).call(this);

0 comments on commit da6ae6a

Please sign in to comment.