コード例 #1
0
 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.');
     }
 }