SHOW:
|
|
- or go back to the newest paste.
| 1 | local composer = require "composer" | |
| 2 | local scene = composer.newScene() | |
| 3 | local json = require "json" | |
| 4 | local widget = require "widget" | |
| 5 | local firebase = require("plugin.firebase")
| |
| 6 | require("extensions.table")
| |
| 7 | ||
| 8 | ||
| 9 | - | print(fbResponse) |
| 9 | + | local lastScene = composer.getSceneName("previous")
|
| 10 | ||
| 11 | ||
| 12 | ||
| 13 | local fbJson -->Converts Firebase response to JSON | |
| 14 | local fbDecoded -->Converts JSON to a Lua table | |
| 15 | local fbResponse | |
| 16 | function scene:create (event) | |
| 17 | loginGroup = self.view | |
| 18 | ||
| 19 | --fixes issues with buttons showing weird on android version | |
| 20 | widget.setTheme( "widget_theme_ios7" ) | |
| 21 | ||
| 22 | --Background | |
| 23 | local background = display.newRect(display.contentWidth/2, display.contentHeight/2, display.contentWidth*2, display.contentHeight*2) | |
| 24 | --Title | |
| 25 | local title = display.newText("PCI Connect", display.contentWidth/2, display.contentHeight/5, native.systemFontBold, display.viewableContentHeight/16)
| |
| 26 | title:setFillColor(154/255, 17/255, 49/255) | |
| 27 | title.y = display.contentHeight/4 - 1.2*title.height | |
| 28 | --Email textbox | |
| 29 | local username = native.newTextField(display.contentWidth/2, display.contentHeight/4, 4*display.contentWidth/6, display.viewableContentHeight/20) | |
| 30 | username:setTextColor(154/255, 17/255, 49/255) | |
| 31 | username.placeholder = "Packer Username" | |
| 32 | --Email textbox border | |
| 33 | local usernameBox = display.newRect(0, 0, username.width, username.height) | |
| 34 | usernameBox.x = username.x | |
| 35 | usernameBox.y = username.y | |
| 36 | usernameBox:setStrokeColor(200/255,200/255,200/255) | |
| 37 | usernameBox.strokeWidth = display.contentWidth/90 | |
| 38 | --Password textbox | |
| 39 | local password = native.newTextField(display.contentWidth/2, username.y + display.viewableContentHeight/10, 4*display.contentWidth/6, display.viewableContentHeight/20) | |
| 40 | password:setTextColor(154/255, 17/255, 49/255) | |
| 41 | password.placeholder = "Password" | |
| 42 | --Password textbox border | |
| 43 | local passwordBox = display.newRect(0, 0, password.width, password.height) | |
| 44 | passwordBox.x = password.x | |
| 45 | passwordBox.y = password.y | |
| 46 | passwordBox:setStrokeColor(200/255,200/255,200/255) | |
| 47 | passwordBox.strokeWidth = display.contentWidth/90 | |
| 48 | --Forgot Password Button | |
| 49 | local forgotPasswordButton = display.newText("Forgot Password", display.contentWidth/2, password.y + 50, native.systemFontBold, display.viewableContentHeight/50)
| |
| 50 | forgotPasswordButton.x = display.contentWidth/2 + passwordBox.width/2 - forgotPasswordButton.width/2 + 2 | |
| 51 | forgotPasswordButton.y = passwordBox.y + passwordBox.height | |
| 52 | forgotPasswordButton:setFillColor(200/255,200/255,200/255) | |
| 53 | --Login Box | |
| 54 | local loginButton = display.newRect(0, 0, display.contentWidth/3.2, display.contentHeight/13.5) | |
| 55 | loginButton.strokeWidth = display.contentWidth/220 | |
| 56 | loginButton:setStrokeColor(154/255, 17/255, 49/255) | |
| 57 | loginButton.x = display.contentWidth/2 | |
| 58 | loginButton.y = forgotPasswordButton.y + loginButton.height | |
| 59 | loginButton:setFillColor(1,1,1) | |
| 60 | --Login Text | |
| 61 | local loginText = display.newText("Login", loginButton.x, loginButton.y, native.systemFontBold, display.viewableContentHeight/20)
| |
| 62 | loginText:setFillColor(154/255, 17/255, 49/255) | |
| 63 | --Create Account Text | |
| 64 | local createAccountText = display.newText("Create Account", loginButton.x, loginButton.y, native.systemFontBold, display.viewableContentHeight/44)
| |
| 65 | createAccountText:setFillColor(154/255, 17/255, 49/255) | |
| 66 | createAccountText.y = loginButton.y + 3*createAccountText.height | |
| 67 | ||
| 68 | --Create Account Border | |
| 69 | local createAccountBorder = display.newRect(0, 0, display.contentWidth/3.2, display.contentHeight/13.5) | |
| 70 | createAccountBorder.strokeWidth = display.contentWidth/220 | |
| 71 | createAccountBorder:setStrokeColor(154/255, 17/255, 49/255) | |
| 72 | createAccountBorder.x = createAccountText.x | |
| 73 | createAccountBorder.y = createAccountText.y | |
| 74 | createAccountBorder.width = 1.1*createAccountText.width | |
| 75 | createAccountBorder.height = 1.1*createAccountText.height | |
| 76 | ||
| 77 | --Extra Info | |
| 78 | local extraInfo1 = display.newText("This application requires you to sign up", display.contentWidth/2, 0, native.systemFontBold, display.viewableContentHeight/48)
| |
| 79 | extraInfo1:setFillColor(200/255,200/255,200/255) | |
| 80 | extraInfo1.y = extraInfo1.height*1.1 | |
| 81 | extraInfo1.alpha = 0 | |
| 82 | ||
| 83 | --Extra Info | |
| 84 | local extraInfo2 = display.newText("with your Packer email but this account", display.contentWidth/2, extraInfo1.height*2, native.systemFontBold, display.viewableContentHeight/48)
| |
| 85 | extraInfo2:setFillColor(200/255,200/255,200/255) | |
| 86 | extraInfo2.alpha = 0 | |
| 87 | ||
| 88 | --Extra Info | |
| 89 | local extraInfo3 = display.newText("is not connected to your Packer login.", display.contentWidth/2, extraInfo2.height*2, native.systemFontBold, display.viewableContentHeight/48)
| |
| 90 | extraInfo3:setFillColor(200/255,200/255,200/255) | |
| 91 | extraInfo3.alpha = 0 | |
| 92 | ||
| 93 | --INSERTING EACH ELEMENT OF THE PAGE INTO THE GROUP TO MAKE REMOVAL EASIER | |
| 94 | loginGroup:insert(background) | |
| 95 | loginGroup:insert(title) | |
| 96 | loginGroup:insert(usernameBox) | |
| 97 | loginGroup:insert(username) | |
| 98 | loginGroup:insert(passwordBox) | |
| 99 | loginGroup:insert(password) | |
| 100 | loginGroup:insert(loginButton) | |
| 101 | loginGroup:insert(loginText) | |
| 102 | loginGroup:insert(createAccountBorder) | |
| 103 | loginGroup:insert(createAccountText) | |
| 104 | loginGroup:insert(forgotPasswordButton) | |
| 105 | loginGroup:insert(extraInfo1) | |
| 106 | loginGroup:insert(extraInfo2) | |
| 107 | loginGroup:insert(extraInfo3) | |
| 108 | ||
| 109 | --password field doesnt allow placeholder when secure so this changes it after it is clicked | |
| 110 | local function secureField(event) | |
| 111 | password.isSecure = true | |
| 112 | end | |
| 113 | password:addEventListener("userInput", secureField)
| |
| 114 | ||
| 115 | ||
| 116 | local function lis( e ) | |
| 117 | ||
| 118 | --Converts JSON to Lua table | |
| 119 | fbResponse = json.encode(e.error) | |
| 120 | --Converts data to JSON | |
| 121 | fbJson=json.decode(fbResponse) | |
| 122 | --print(fbJson) | |
| 123 | fbDecoded = json.decode(fbJson) | |
| 124 | print(fbResponse) | |
| 125 | ||
| 126 | ||
| 127 | --[[local tempVar = e.error | |
| 128 | print(tempVar) | |
| 129 | if (tempVar == nil) then | |
| 130 | dataLocal.username = username.text.."@packer.edu" | |
| 131 | dataLocal.password = password.text | |
| 132 | if (dataLocal.form == 0 or dataLocal.form == nil) then | |
| 133 | composer.gotoScene("Form", {effect = "fade", time = 300})
| |
| 134 | dataLocal.form = 1 | |
| 135 | else | |
| 136 | composer.gotoScene("HomeScreen", {effect = "fade", time = 300})
| |
| 137 | table.save(dataLocal, "localSave") | |
| 138 | end | |
| 139 | elseif (tempVar == "email not verified")then | |
| 140 | username.text = "" | |
| 141 | password.text = "" | |
| 142 | dataLocal.username = "" | |
| 143 | dataLocal.password = "" | |
| 144 | table.save(dataLocal, "localSave") | |
| 145 | username.placeholder = "Please Verify Your" | |
| 146 | password.placeholder = "Email Address." | |
| 147 | extraInfo1.alpha = 1 | |
| 148 | extraInfo2.alpha = 2 | |
| 149 | extraInfo3.alpha = 3 | |
| 150 | else | |
| 151 | username.placeholder = "Error Try Again" | |
| 152 | dataLocal.username = "" | |
| 153 | dataLocal.password = "" | |
| 154 | table.save(dataLocal, "localSave") | |
| 155 | extraInfo1.alpha = 1 | |
| 156 | extraInfo2.alpha = 2 | |
| 157 | extraInfo3.alpha = 3 | |
| 158 | end]] | |
| 159 | end | |
| 160 | ||
| 161 | --ALLOWS YOU TO OPEN AND CLOSE KEYBOARD BY TAPPING ON SCREEN | |
| 162 | local function keyboardListener(event) | |
| 163 | native.setKeyboardFocus(nil) | |
| 164 | end | |
| 165 | ||
| 166 | local function textListener( event ) | |
| 167 | if ( event.phase == "editing" ) then | |
| 168 | ||
| 169 | elseif(event.phase == "ended" or event.phase == "submitted")then | |
| 170 | keyboardListener() | |
| 171 | end | |
| 172 | end | |
| 173 | ||
| 174 | --Function that is used for login button | |
| 175 | local function loginFunction(event) | |
| 176 | if (event.phase == "began") then | |
| 177 | loginButton:setFillColor(154/255, 17/255, 49/255) | |
| 178 | loginText:setFillColor(1,1,1) | |
| 179 | elseif (event.phase == "cancelled") then | |
| 180 | print("Event cancelled")
| |
| 181 | loginButton:setFillColor(1,1,1) | |
| 182 | loginText:setFillColor(154/255, 17/255, 49/255) | |
| 183 | elseif (event.phase == "ended") then | |
| 184 | loginButton:setFillColor(1,1,1) | |
| 185 | loginText:setFillColor(154/255, 17/255, 49/255) | |
| 186 | firebase.login(username.text.."@packer.edu", password.text, lis, true) | |
| 187 | end | |
| 188 | end | |
| 189 | ||
| 190 | loginButton:addEventListener("touch", loginFunction)
| |
| 191 | ||
| 192 | --Function that goes to create account page | |
| 193 | local function createAccount(event) | |
| 194 | if (event.phase == "began") then | |
| 195 | createAccountBorder:setFillColor(154/255, 17/255, 49/255) | |
| 196 | createAccountText:setFillColor(1,1,1) | |
| 197 | elseif (event.phase == "cancelled") then | |
| 198 | print("Event cancelled")
| |
| 199 | createAccountBorder:setFillColor(1,1,1) | |
| 200 | createAccountText:setFillColor(154/255, 17/255, 49/255) | |
| 201 | elseif (event.phase == "ended") then | |
| 202 | createAccountBorder:setFillColor(1,1,1) | |
| 203 | createAccountText:setFillColor(154/255, 17/255, 49/255) | |
| 204 | composer.gotoScene("CreateAccount")
| |
| 205 | end | |
| 206 | end | |
| 207 | createAccountText:addEventListener("touch", createAccount)
| |
| 208 | ||
| 209 | --Function that goes to forgot password | |
| 210 | local function forgotPassword (event) | |
| 211 | composer.gotoScene("ForgotPassword")
| |
| 212 | end | |
| 213 | forgotPasswordButton:addEventListener("tap", forgotPassword)
| |
| 214 | ||
| 215 | username:addEventListener("ended", keyboardListener)
| |
| 216 | username:addEventListener("submitted", keyboardListener)
| |
| 217 | password:addEventListener("ended", keyboardListener)
| |
| 218 | password:addEventListener("submitted", keyboardListener)
| |
| 219 | background:addEventListener("tap", keyboardListener)
| |
| 220 | end | |
| 221 | ||
| 222 | --THIS FUNCTION HIDES THE WHOLE PAGE | |
| 223 | function scene:hide (event) | |
| 224 | ||
| 225 | end | |
| 226 | ||
| 227 | --THIS FUNCTION SHOWS THE NEXT EVENT | |
| 228 | function scene:show (event) | |
| 229 | ||
| 230 | end | |
| 231 | ||
| 232 | scene:addEventListener("create", scene)
| |
| 233 | scene:addEventListener("show", scene)
| |
| 234 | scene:addEventListener("hide", scene)
| |
| 235 | return scene |