Skip to content
This repository
tree: a40c8fd306
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 80 lines (61 sloc) 1.8 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
adminMenu = $ "#adminMenu"
logoutButton = $ "#logoutButton"
loginMenu = $ "#loginMenu"
loginButton = $ "#loginButton"
usernameInput = $ "#usernameInput"
passwordInput = $ "#passwordInput"
form_login = $ "#form_login"

###
setCookie = (name, value) ->
c_value = escape value
c_name = escape name
document.cookie = "#{c_name}=#{c_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}"
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 ->
setCookie "status", "User"
setLogInControl()
loginButton.click ->
form_login.submit ->
alert "Done"
setLogInControl()
###

# Check for the admin cookie and set the status...
$ ->
    setLogInControl()
    
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





Something went wrong with that request. Please try again.