예제 #1
0
 public function createAccount($user_name, $email, $password)
 {
     foreach (get_defined_vars() as $var) {
         if (!isset($var)) {
             $data['status'] = 'bad data';
             echo json_encode($data);
             die;
         }
     }
     require_once $_SERVER['DOCUMENT_ROOT'] . '/model/user.model.php';
     $userModel = new userModel();
     //check if user name is taken
     if ($userModel->checkIfUserNameExists($user_name)) {
         $data['status'] = 'username exists';
         echo json_encode($data);
         die;
     }
     //check if email is taken
     if ($userModel->checkIfEmailExists($email)) {
         $data['status'] = 'email exists';
         echo json_encode($data);
         die;
     }
     $verification = md5(uniqid(rand(), true));
     $password_hash = $userModel->hashPlainText($password);
     $userModel->addPlayer($email, $user_name, $password_hash, $verification);
     $data['status'] = 'ok';
     echo json_encode($data);
 }