static function signup($app) { // Get Post Data $post = $app->request->post(); // Validate Sent Input $valid = self::signup_validateSentParameters($post); if ($valid !== true) { return array('registered' => false, 'msg' => $valid, 'post' => $post); } // Look for user with that email $existing = AuthData::selectUserAndPasswordByEmail($post['email']); if ($existing) { /// FAIL - If a user with that email already exists return array('registered' => false, 'msg' => 'Signup failed. A user with that email already exists.'); } // Create and insert a new user $validUser = array(':email' => $post['email'], ':name_first' => v::key('nameFirst', v::stringType())->validate($post) ? $post['nameFirst'] : '', ':name_last' => v::key('nameLast', v::stringType())->validate($post) ? $post['nameLast'] : '', ':phone' => v::key('phone', v::stringType())->validate($post) ? $post['phone'] : NULL, ':password' => password_hash($post['password'], PASSWORD_DEFAULT)); $userId = AuthData::insertUser($validUser); if (!$userId) { /// FAIL - If Inserting the user failed return array('registered' => false, 'msg' => 'Signup failed. Could not save user.'); } // Select our new user $user = AuthData::selectUserById($userId); if (!$user) { /// FAIL - If Inserting the user failed (hopefully this is redundant) return array('registered' => false, 'msg' => 'Signup failed. Could not select user.'); } // If a token was sent, update token status if (v::key('token', v::stringType())->validate($post)) { $inviteTeamId = AuthData::selectSignupInvite($post['token']); if ($inviteTeamId) { AuthData::updateAcceptSignupTeamInvite(array(':user_id' => $userId, ':token' => $post['token'], ':team_id' => $inviteTeamId)); } else { AuthData::updateAcceptSignupPlayerInvite(array(':user_id' => $userId, ':token' => $post['token'])); } } // Save "Where did you hear about us" and any other additional questions // This is "quiet" in that it may not execute if no paramters match // And it doesnt set the response for the api call InfoController::quietlySaveAdditional($post, $user->id); // Create an authorization $token = self::createAuthToken($app, $user->id); if ($token) { // Create the return object $found = array('user' => $user); $found['user']->apiKey = $token['apiKey']; $found['user']->apiToken = $token['apiToken']; $found['sessionLifeHours'] = $token['sessionLifeHours']; $found['registered'] = true; return $found; } else { /// FAIL - If the auth token couldnt be created and saved return array('registered' => false, 'msg' => 'Signup failed to create auth token.'); } }
static function signup($app) { // Get Post Data $post = $app->request->post(); // Validate Sent Input $valid = self::validateFacebookProfile($post); if ($valid !== true) { return array('registered' => false, 'msg' => 'Facebook signup failed. Check your parameters and try again.'); } /* $token = self::getActiveAccessToken(); $profile = self::getProfile($post['accessToken']); if(true || !$token) { return array('registered' => false, 'msg' => 'Facebook signup failed. You are not logged into Facebook.', 'token' => $token, 'profile' => $profile, 'post' => $post, 'cookie' => $_COOKIE); } */ // Look for user with that email $existing = AuthData::selectUserAndPasswordByEmail($post['email']); if ($existing) { /// FAIL - If a user with that email already exists return array('registered' => false, 'msg' => 'Facebook signup failed. A user with that email already exists.'); } $validUser = array(':email' => $post['email'], ':name_first' => $post['nameFirst'], ':name_last' => $post['nameLast'], ':facebook_id' => $post['facebookId']); $userId = AuthData::insertFacebookUser($validUser); if (!$userId) { /// FAIL - If Inserting the user failed return array('registered' => false, 'msg' => 'Facebook signup failed. Could not save user.'); } // Select our new user $user = AuthData::selectUserById($userId); if (!$user) { /// FAIL - If Inserting the user failed (hopefully this is redundant) return array('registered' => false, 'msg' => 'Facebook signup failed. Could not select user.'); } // Save "Where did you hear about us" and any other additional questions // This is "quiet" in that it may not execute if no paramters match // And it doesnt set the response for the api call InfoController::quietlySaveAdditional($post, $user->id); // Create an authorization $token = AuthControllerNative::createAuthToken($app, $user->id); if ($token) { // Create the return object $found = array('user' => $user); $found['user']->apiKey = $token['apiKey']; $found['user']->apiToken = $token['apiToken']; $found['sessionLifeHours'] = $token['sessionLifeHours']; $found['registered'] = true; return $found; } else { return array('registered' => false, 'msg' => 'Facebook Signup failed to creat auth token.'); } }