public function userSignUp()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $update = !Generic::IsNullOrEmptyString($_POST['id_user']);
     $idUser = Generic::IsNullOrEmptyString($_POST['id_user']) ? "" : $_POST['id_user'];
     $fullName = Generic::mustCheck($_POST['full_name'], Keys::$ERR_USER_EMPTY_FULL_NAME);
     $userName = Generic::mustCheck($_POST['user_name'], Keys::$ERR_USER_EMPTY_NICK_NAME);
     $email = Generic::mustCheck($_POST['email'], Keys::$ERR_USER_EMPTY_EMAIL);
     $password = Generic::mustCheck($_POST['pwd'], Keys::$ERR_USER_EMPTY_PASSWORD);
     //        $password2 = Generic::mustCheck($_POST['pwd2'], Keys::$ERR_USER_EMPTY_PASSWORD_2);
     $idCuisine = Generic::mustCheck($_POST['pref_cuisine'], Keys::$ERR_USER_EMPTY_CUISINE);
     $birthday = Generic::mustCheck($_POST['birthday'], Keys::$ERR_USER_EMPTY_BIRTHDAY);
     $phoneNo = Generic::mustCheck($_POST['phone_no'], Keys::$ERR_USER_EMPTY_PHONE);
     $fbId = Generic::IsNullOrEmptyString($_POST['fb_id']) ? "" : $_POST['fb_id'];
     $latitude = Generic::getOrDefault($_POST['lat'], Keys::$DEFAULT_LATITUDE);
     $longitude = Generic::getOrDefault($_POST['long'], Keys::$DEFAULT_LONGITUDE);
     $district = Generic::getOrDefault($_POST['district'], Keys::$EMPTY);
     $city = Generic::getOrDefault($_POST['city'], Keys::$EMPTY);
     $pic = Generic::getOrDefault($_POST['pic'], Keys::$EMPTY);
     ///START OF LOVELY VALIDATION TIME
     if (!Generic::isValidUserName($userName)) {
         Generic::errorMsg(Keys::$ERR_USER_INVALID_USERNAME);
     }
     if (!Generic::isValidUserNameLength($userName)) {
         Generic::errorMsg(Keys::$ERR_USER_USERNAME_TOO_LONG);
     }
     if (!Generic::isValidEmail($email)) {
         Generic::errorMsg(Keys::$ERR_USER_INVALID_EMAIL);
     }
     if (!Generic::isValidPassword($password)) {
         Generic::errorMsg(Keys::$ERR_USER_INVALID_PASSWORD);
     }
     //        if ($password != $password2)
     //            Generic::errorMsg(Keys::$ERR_USER_CONFIRM_PASSWORD_NOT_MATCH);
     $u = new UserModel();
     $arrU = $u->getWhere("user_name='{$userName}'");
     if (count($arrU) > 0) {
         Generic::errorMsg(Keys::$ERR_USER_DUPLICATE_USERNAME);
     }
     $u1 = new UserModel();
     $arrU = $u1->getWhere("email='{$email}'");
     if (count($arrU) > 0) {
         Generic::errorMsg(Keys::$ERR_USER_DUPLICATE_EMAIL);
     }
     if ($fbId != "") {
         $u2 = new UserModel();
         $arrU = $u2->getWhere("fb_id='{$fbId}'");
         if (count($arrU) > 0) {
             Generic::errorMsg(Keys::$ERR_USER_DUPLICATE_FB_ID);
         }
     }
     ///END OF LOVELY VALIDATION TIME, HOW SAD :(
     //pagar untuk regis
     if (Efiwebsetting::getData('Doku_switch')) {
         $doku = new PaymentDoku();
         $dokuId = $doku->registerCustomer($fullName, $email, $phoneNo);
         if (!$dokuId) {
             Generic::errorMsg(Keys::$ERR_USER_FAILED_CREATE_DOKU);
         }
     }
     $user = new UserModel();
     $user->full_name = $fullName;
     $user->user_name = $userName;
     $user->email = $email;
     $user->password = $password;
     $user->id_cuisine = $idCuisine;
     $user->birthday = $birthday;
     if ($pic == "") {
         $user->pic = "";
     } else {
         $user->pic = Util::savePic($pic);
     }
     $user->phone_no = $phoneNo;
     $user->fb_id = $fbId;
     $user->latitude = $latitude;
     $user->longitude = $longitude;
     $user->district = $district;
     $user->city = $city;
     $user->last_lat = $latitude;
     $user->last_long = $longitude;
     $user->last_district = $district;
     $user->last_city = $city;
     $user->status = "1";
     $user->payment_id = $dokuId;
     //        $user->load = 1;
     $uid = $user->save();
     if (!$uid) {
         Generic::errorMsg(Keys::$ERR_USER_FAILED_CREATE);
     } else {
         Generic::saveDistrictCityFromLatLng($latitude, $longitude, $uid, false);
         $results['fb_id'] = $fbId;
         $results['id_user'] = $uid;
         //$user->id_user;
         $results['user_name'] = $userName;
         $results['full_name'] = $fullName;
         $results['email'] = $email;
         $results['pic'] = Generic::insertImageUrl($pic);
         Generic::finish($results);
     }
 }
 public function userUpdateProfile()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $idUser = Generic::mustCheck($_POST['id_user'], "ID user required");
     $fullName = Generic::mustCheck($_POST['full_name'], "Empty Full Name");
     $userName = Generic::mustCheck($_POST['user_name'], "Empty User Name");
     $email = Generic::mustCheck($_POST['email'], "Empty Email");
     $password = Generic::mustCheck($_POST['pwd'], "Empty Password");
     $idCuisine = Generic::mustCheck($_POST['pref_cuisine'], "Cuisine Not Selected");
     $birthday = Generic::mustCheck($_POST['birthday'], "Empty Birthday");
     $phoneNo = Generic::mustCheck($_POST['phone_no'], "Empty Phone Number");
     $fbId = Generic::IsNullOrEmptyString($_POST['fb_id']) ? "" : $_POST['fb_id'];
     $latitude = Generic::IsNullOrEmptyString($_POST['lat']) ? "" : $_POST['lat'];
     $longitude = Generic::IsNullOrEmptyString($_POST['long']) ? "" : $_POST['long'];
     $district = Generic::IsNullOrEmptyString($_POST['district']) ? "" : $_POST['district'];
     $city = Generic::IsNullOrEmptyString($_POST['city']) ? "" : $_POST['city'];
     $pic = Generic::IsNullOrEmptyString($_POST['pic']) ? "" : MasterRestaurant::savePic($_POST['pic']);
     ///START OF LOVELY VALIDATION TIME
     if (!Generic::isValidUserName($userName)) {
         Generic::errorMsg("Username must only contains alphanumeric (and/or) \\'.\\', \\'-\\', \\'_\\'");
     }
     if (!Generic::isValidUserNameLength($userName)) {
         Generic::errorMsg("Max username length is 20");
     }
     if (!Generic::isValidEmail($email)) {
         Generic::errorMsg("Email format not valid");
     }
     if (!Generic::isValidPassword($password)) {
         Generic::errorMsg("Password must contain minimum 5 character and no whitespace");
     }
     $user = new UserModel();
     $user->getByID($idUser);
     if ($birthday != $user->birthday) {
         Generic::errorMsg("Birthday cannot be changed");
     }
     if ($userName != $user->user_name) {
         Generic::errorMsg("Username cannot be changed");
     }
     if (!Generic::IsNullOrEmptyString($user->fb_id) && $fbId != $user->fb_id) {
         Generic::errorMsg("Facebook cannot be changed");
     } else {
         $user->fb_id = $fbId;
     }
     ///END OF LOVELY VALIDATION TIME, HOW SAD :(
     $user->full_name = $fullName;
     $user->email = $email;
     $user->password = $password;
     $user->id_cuisine = $idCuisine;
     $user->phone_no = $phoneNo;
     if (!Generic::IsNullOrEmptyString($pic)) {
         $user->pic = $pic;
     }
     if (!Generic::IsNullOrEmptyString($latitude)) {
         $user->latitude = $latitude;
         $user->last_lat = $latitude;
     }
     if (!Generic::IsNullOrEmptyString($longitude)) {
         $user->longitude = $longitude;
         $user->last_long = $longitude;
     }
     if (!Generic::IsNullOrEmptyString($district)) {
         $user->district = $district;
         $user->last_district = $district;
     }
     if (!Generic::IsNullOrEmptyString($city)) {
         $user->city = $city;
         $user->last_city = $city;
     }
     $user->status = "1";
     $uid = $user->save();
     if (!$uid) {
         Generic::errorMsg("Failed Creating User");
     } else {
         $json['status_code'] = 1;
         $json['results']['fb_id'] = $user->fb_id;
         $json['results']['id_user'] = $idUser;
         $json['results']['user_name'] = $user->user_name;
         $json['results']['full_name'] = $user->full_name;
         $json['results']['email'] = $user->email;
         $json['results']['pic'] = Generic::insertImageUrl($user->pic);
         echo json_encode($json);
         die;
     }
 }