Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cobalt = dofile( "cobalt" )
- os.loadAPI("json.lua")
- local show_login_screen = false
- local show_register_screen = false
- local show_home_screen = true
- local username_input = ""
- local password_input = ""
- local actual_password = ""
- local error_text = ""
- local username_input_selected = false
- local password_input_selected = false
- local cursor_state = false
- local alt_key = false
- local base_url = "http://fuckass69.tk:9901"
- function getResponse(url)
- local res = http.get(url)
- local output = res.readAll()
- res.close()
- sleep(2)
- return output
- end
- function register(username,password)
- return getResponse(base_url.."/api/register?username="..username.."&password="..password)
- end
- function login(username,password)
- return getResponse(base_url.."/api/login?username="..username.."&password="..password)
- end
- function get_user()
- local res = getResponse(base_url.."/api/get_user?session="..session_token)
- if(res == "INVALID_TOKEN") then
- return nil
- else
- return json.decode(res)
- end
- end
- function logout()
- local res = getResponse(base_url.."/api/logout?session="..session_token)
- return res
- end
- function cobalt.draw()
- cobalt.graphics.line(1,1,51,1,colors.white)
- cobalt.graphics.print("Federal Bank Client 0.0.1a",13,1,colors.white,colors.black)
- cursor_state = not cursor_state
- if(show_home_screen)then
- cobalt.graphics.line(1,19,51,19,colors.white)
- cobalt.graphics.print("Login-alt+1 Register-alt+2 About-alt+3",1,19,colors.white,colors.black)
- cobalt.graphics.print("Welcome to Federal Bank!",13,6,colors.white,colors.black)
- end
- if(show_login_screen)then
- cobalt.graphics.line(1,19,51,19,colors.white)
- cobalt.graphics.print("Username-alt+1 Password-alt+2 Home-alt+3",1,19,colors.white,colors.black)
- cobalt.graphics.print("Login",13,5,colors.white,colors.black)
- cobalt.graphics.print("U:",13,6,colors.white,colors.black)
- cobalt.graphics.print("P:",13,7,colors.white,colors.black)
- cobalt.graphics.print(username_input,15,6,colors.white,colors.black)
- cobalt.graphics.print(password_input,15,7,colors.white,colors.black)
- if(cursor_state == true) then
- if(username_input_selected) then
- cobalt.graphics.pixel(15+#username_input,6,colors.white)
- end
- if(password_input_selected) then
- cobalt.graphics.pixel(15+#password_input,7,colors.white)
- end
- else
- if(username_input_selected) then
- cobalt.graphics.pixel(15+#username_input,6,colors.black)
- end
- if(password_input_selected) then
- cobalt.graphics.pixel(15+#password_input,7,colors.black)
- end
- end
- end
- if(show_register_screen)then
- cobalt.graphics.line(1,19,51,19,colors.white)
- cobalt.graphics.print("Username-alt+1 Password-alt+2 Home-alt+3",1,19,colors.white,colors.black)
- cobalt.graphics.print("Register",13,5,colors.white,colors.black)
- cobalt.graphics.print("U:",13,6,colors.white,colors.black)
- cobalt.graphics.print("P:",13,7,colors.white,colors.black)
- cobalt.graphics.print(username_input,15,6,colors.white,colors.black)
- cobalt.graphics.print(password_input,15,7,colors.white,colors.black)
- if(cursor_state == true) then
- if(username_input_selected) then
- cobalt.graphics.pixel(15+#username_input,6,colors.white)
- end
- if(password_input_selected) then
- cobalt.graphics.pixel(15+#password_input,7,colors.white)
- end
- else
- if(username_input_selected) then
- cobalt.graphics.pixel(15+#username_input,6,colors.black)
- end
- if(password_input_selected) then
- cobalt.graphics.pixel(15+#password_input,7,colors.black)
- end
- end
- end
- cobalt.graphics.print(error_text,15,9,colors.black,colors.white)
- end
- function cobalt.update( dt )
- end
- function cobalt.mousepressed( x, y, button )
- end
- function cobalt.mousereleased( x, y, button )
- end
- function cobalt.keypressed( keycode, key )
- if(key == "leftAlt") then
- alt_key = true
- end
- if(key == "rightAlt") then
- alt_key = true
- end
- if(key == "backspace") then
- if(username_input_selected) then
- username_input = username_input:sub(1,-2)
- end
- if(password_input_selected) then
- password_input = password_input:sub(1,-2)
- actual_password = actual_password:sub(1,-2)
- end
- end
- if(key == "enter") then
- if(#username_input> 0 and #password_input > 0) then
- if(show_register_screen) then
- local res = register(username_input,actual_password)
- if(res == "SUCCESS") then
- -- go to account screen
- error_text = res
- else
- error_text = res
- end
- cobalt.update()
- cobalt.draw()
- elseif(show_login_screen) then
- local res = login(username_input,actual_password)
- if(res == "INVALID_PASSWORD") then
- -- Create error text
- error_text = res
- elseif(res == "INVALID_USERNAME") then
- error_text = res
- else
- session_token = res
- local user_tmp = get_user()
- end
- end
- end
- cobalt.update()
- cobalt.draw()
- cobalt.updatespeed = 0.01
- end
- end
- -- RegisterButton.onclick = function()
- -- if(#Username.text > 0 and #Password.text > 0) then
- -- local res = register(Username.text,Password.text)
- -- if(res == "SUCCESS") then
- -- ErrorText.text = ""
- -- else
- -- ErrorText.text = res
- -- end
- -- end
- -- end
- -- LoginButton.onclick = function()
- -- if(#Username.text > 0 and #Password.text > 0) then
- -- local res = login(Username.text,Password.text)
- -- if(res == "INVALID_PASSWORD") then
- -- ErrorText.text = res
- -- elseif(res == "INVALID_USERNAME") then
- -- ErrorText.text = res
- -- else
- -- ErrorText.text = ""
- -- session_token = res
- -- cobalt.state = "AccountPanel"
- -- local user_tmp = get_user()
- -- UsernameText.text = "Username: "..user_tmp.username
- -- BalanceText.text = "$"..user_tmp.balance
- -- IdText.text = "ID: "..user_tmp.id
- -- LogoutButton.text = "Logout"
- -- end
- -- end
- -- end
- -- LogoutButton.onclick = function()
- -- local res = logout()
- -- shell.run("/atm.lua")
- -- end
- function cobalt.keyreleased( keycode, key )
- if(key == "leftAlt") then
- alt_key = false
- end
- if(key == "rightAlt") then
- alt_key = false
- end
- end
- function cobalt.textinput( t )
- if(alt_key) then
- if(t == "1" and show_home_screen)then
- show_login_screen = true
- show_home_screen = false
- show_register_screen = false
- end
- if(t == "2" and show_home_screen)then
- show_login_screen = false
- show_home_screen = false
- show_register_screen = true
- end
- if(show_login_screen or show_register_screen) then
- if(t == "1") then
- username_input_selected = true
- password_input_selected = false
- elseif(t == "2") then
- username_input_selected = false
- password_input_selected = true
- elseif(t == "3") then
- show_login_screen = false
- show_home_screen = true
- show_register_screen = false
- end
- end
- else
- if(show_login_screen or show_register_screen) then
- if(username_input_selected) then
- username_input = username_input .. t
- end
- if(password_input_selected) then
- password_input = password_input .. "*"
- actual_password = actual_password .. t
- end
- end
- end
- end
- cobalt.initLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement