Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local composer = require "composer"
- local scene = composer.newScene()
- local json = require "json"
- local widget = require "widget"
- local firebase = require("plugin.firebase")
- require("extensions.table")
- local lastScene = composer.getSceneName("previous")
- local fbJson -->Converts Firebase response to JSON
- local fbDecoded -->Converts JSON to a Lua table
- local fbResponse
- function scene:create (event)
- loginGroup = self.view
- --fixes issues with buttons showing weird on android version
- widget.setTheme( "widget_theme_ios7" )
- --Background
- local background = display.newRect(display.contentWidth/2, display.contentHeight/2, display.contentWidth*2, display.contentHeight*2)
- --Title
- local title = display.newText("PCI Connect", display.contentWidth/2, display.contentHeight/5, native.systemFontBold, display.viewableContentHeight/16)
- title:setFillColor(154/255, 17/255, 49/255)
- title.y = display.contentHeight/4 - 1.2*title.height
- --Email textbox
- local username = native.newTextField(display.contentWidth/2, display.contentHeight/4, 4*display.contentWidth/6, display.viewableContentHeight/20)
- username:setTextColor(154/255, 17/255, 49/255)
- username.placeholder = "Packer Username"
- --Email textbox border
- local usernameBox = display.newRect(0, 0, username.width, username.height)
- usernameBox.x = username.x
- usernameBox.y = username.y
- usernameBox:setStrokeColor(200/255,200/255,200/255)
- usernameBox.strokeWidth = display.contentWidth/90
- --Password textbox
- local password = native.newTextField(display.contentWidth/2, username.y + display.viewableContentHeight/10, 4*display.contentWidth/6, display.viewableContentHeight/20)
- password:setTextColor(154/255, 17/255, 49/255)
- password.placeholder = "Password"
- --Password textbox border
- local passwordBox = display.newRect(0, 0, password.width, password.height)
- passwordBox.x = password.x
- passwordBox.y = password.y
- passwordBox:setStrokeColor(200/255,200/255,200/255)
- passwordBox.strokeWidth = display.contentWidth/90
- --Forgot Password Button
- local forgotPasswordButton = display.newText("Forgot Password", display.contentWidth/2, password.y + 50, native.systemFontBold, display.viewableContentHeight/50)
- forgotPasswordButton.x = display.contentWidth/2 + passwordBox.width/2 - forgotPasswordButton.width/2 + 2
- forgotPasswordButton.y = passwordBox.y + passwordBox.height
- forgotPasswordButton:setFillColor(200/255,200/255,200/255)
- --Login Box
- local loginButton = display.newRect(0, 0, display.contentWidth/3.2, display.contentHeight/13.5)
- loginButton.strokeWidth = display.contentWidth/220
- loginButton:setStrokeColor(154/255, 17/255, 49/255)
- loginButton.x = display.contentWidth/2
- loginButton.y = forgotPasswordButton.y + loginButton.height
- loginButton:setFillColor(1,1,1)
- --Login Text
- local loginText = display.newText("Login", loginButton.x, loginButton.y, native.systemFontBold, display.viewableContentHeight/20)
- loginText:setFillColor(154/255, 17/255, 49/255)
- --Create Account Text
- local createAccountText = display.newText("Create Account", loginButton.x, loginButton.y, native.systemFontBold, display.viewableContentHeight/44)
- createAccountText:setFillColor(154/255, 17/255, 49/255)
- createAccountText.y = loginButton.y + 3*createAccountText.height
- --Create Account Border
- local createAccountBorder = display.newRect(0, 0, display.contentWidth/3.2, display.contentHeight/13.5)
- createAccountBorder.strokeWidth = display.contentWidth/220
- createAccountBorder:setStrokeColor(154/255, 17/255, 49/255)
- createAccountBorder.x = createAccountText.x
- createAccountBorder.y = createAccountText.y
- createAccountBorder.width = 1.1*createAccountText.width
- createAccountBorder.height = 1.1*createAccountText.height
- --Extra Info
- local extraInfo1 = display.newText("This application requires you to sign up", display.contentWidth/2, 0, native.systemFontBold, display.viewableContentHeight/48)
- extraInfo1:setFillColor(200/255,200/255,200/255)
- extraInfo1.y = extraInfo1.height*1.1
- extraInfo1.alpha = 0
- --Extra Info
- local extraInfo2 = display.newText("with your Packer email but this account", display.contentWidth/2, extraInfo1.height*2, native.systemFontBold, display.viewableContentHeight/48)
- extraInfo2:setFillColor(200/255,200/255,200/255)
- extraInfo2.alpha = 0
- --Extra Info
- local extraInfo3 = display.newText("is not connected to your Packer login.", display.contentWidth/2, extraInfo2.height*2, native.systemFontBold, display.viewableContentHeight/48)
- extraInfo3:setFillColor(200/255,200/255,200/255)
- extraInfo3.alpha = 0
- --INSERTING EACH ELEMENT OF THE PAGE INTO THE GROUP TO MAKE REMOVAL EASIER
- loginGroup:insert(background)
- loginGroup:insert(title)
- loginGroup:insert(usernameBox)
- loginGroup:insert(username)
- loginGroup:insert(passwordBox)
- loginGroup:insert(password)
- loginGroup:insert(loginButton)
- loginGroup:insert(loginText)
- loginGroup:insert(createAccountBorder)
- loginGroup:insert(createAccountText)
- loginGroup:insert(forgotPasswordButton)
- loginGroup:insert(extraInfo1)
- loginGroup:insert(extraInfo2)
- loginGroup:insert(extraInfo3)
- --password field doesnt allow placeholder when secure so this changes it after it is clicked
- local function secureField(event)
- password.isSecure = true
- end
- password:addEventListener("userInput", secureField)
- local function lis( e )
- --Converts JSON to Lua table
- fbResponse = json.encode(e.error)
- --Converts data to JSON
- fbJson=json.decode(fbResponse)
- --print(fbJson)
- fbDecoded = json.decode(fbJson)
- print(fbResponse)
- --[[local tempVar = e.error
- print(tempVar)
- if (tempVar == nil) then
- dataLocal.username = username.text.."@packer.edu"
- dataLocal.password = password.text
- if (dataLocal.form == 0 or dataLocal.form == nil) then
- composer.gotoScene("Form", {effect = "fade", time = 300})
- dataLocal.form = 1
- else
- composer.gotoScene("HomeScreen", {effect = "fade", time = 300})
- table.save(dataLocal, "localSave")
- end
- elseif (tempVar == "email not verified")then
- username.text = ""
- password.text = ""
- dataLocal.username = ""
- dataLocal.password = ""
- table.save(dataLocal, "localSave")
- username.placeholder = "Please Verify Your"
- password.placeholder = "Email Address."
- extraInfo1.alpha = 1
- extraInfo2.alpha = 2
- extraInfo3.alpha = 3
- else
- username.placeholder = "Error Try Again"
- dataLocal.username = ""
- dataLocal.password = ""
- table.save(dataLocal, "localSave")
- extraInfo1.alpha = 1
- extraInfo2.alpha = 2
- extraInfo3.alpha = 3
- end]]
- end
- --ALLOWS YOU TO OPEN AND CLOSE KEYBOARD BY TAPPING ON SCREEN
- local function keyboardListener(event)
- native.setKeyboardFocus(nil)
- end
- local function textListener( event )
- if ( event.phase == "editing" ) then
- elseif(event.phase == "ended" or event.phase == "submitted")then
- keyboardListener()
- end
- end
- --Function that is used for login button
- local function loginFunction(event)
- if (event.phase == "began") then
- loginButton:setFillColor(154/255, 17/255, 49/255)
- loginText:setFillColor(1,1,1)
- elseif (event.phase == "cancelled") then
- print("Event cancelled")
- loginButton:setFillColor(1,1,1)
- loginText:setFillColor(154/255, 17/255, 49/255)
- elseif (event.phase == "ended") then
- loginButton:setFillColor(1,1,1)
- loginText:setFillColor(154/255, 17/255, 49/255)
- firebase.login(username.text.."@packer.edu", password.text, lis, true)
- end
- end
- loginButton:addEventListener("touch", loginFunction)
- --Function that goes to create account page
- local function createAccount(event)
- if (event.phase == "began") then
- createAccountBorder:setFillColor(154/255, 17/255, 49/255)
- createAccountText:setFillColor(1,1,1)
- elseif (event.phase == "cancelled") then
- print("Event cancelled")
- createAccountBorder:setFillColor(1,1,1)
- createAccountText:setFillColor(154/255, 17/255, 49/255)
- elseif (event.phase == "ended") then
- createAccountBorder:setFillColor(1,1,1)
- createAccountText:setFillColor(154/255, 17/255, 49/255)
- composer.gotoScene("CreateAccount")
- end
- end
- createAccountText:addEventListener("touch", createAccount)
- --Function that goes to forgot password
- local function forgotPassword (event)
- composer.gotoScene("ForgotPassword")
- end
- forgotPasswordButton:addEventListener("tap", forgotPassword)
- username:addEventListener("ended", keyboardListener)
- username:addEventListener("submitted", keyboardListener)
- password:addEventListener("ended", keyboardListener)
- password:addEventListener("submitted", keyboardListener)
- background:addEventListener("tap", keyboardListener)
- end
- --THIS FUNCTION HIDES THE WHOLE PAGE
- function scene:hide (event)
- end
- --THIS FUNCTION SHOWS THE NEXT EVENT
- function scene:show (event)
- end
- scene:addEventListener("create", scene)
- scene:addEventListener("show", scene)
- scene:addEventListener("hide", scene)
- return scene
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement