File: /var/www/dk/wp-content/themes/food/api/user/index.php
<?php
class UserNoauth
{
public $result;
public $debug;
// public $RankingBsObj = null;
public function __construct()
{
$this->result = new stdClass();
// $this->result->rc = ApiErrorDesc::ERR_CONTROLLER[0];
// $this->result->msg = ApiErrorDesc::ERR_CONTROLLER[1];
$this->result->rc = ApiErrorDesc::ERR_METHOD[0];
$this->result->msg = ApiErrorDesc::ERR_METHOD[1];
$this->debug = isset($_REQUEST['debugmod']) ? intval($_REQUEST['debugmod']) : 0;
// $this->RankingBsObj = new RankingBs();
}
function __destruct()
{
$this->echo_json($this->result);
}
public function run()
{
$a = CheckFunc::checkInput2('a', 50, '');
// echo 'a = > ' . $a;
if (method_exists($this, $a)) {
$this->$a();
}
// if ($a == 'playerlist') {
//// $this->playerlist();
// $this->$a();
// }
}
function echo_json($result)
{
echo preg_replace_callback(
'/\\\\u([0-9a-zA-Z]{4})/',
function ($matches) {
return mb_convert_encoding(pack('H*', $matches[1]), 'UTF-8', 'UTF-16');
},
json_encode($result)
);
}
/**
* 更改用户信息
* @return void
*/
public function updateWpUser()
{
$debug = $this->debug;
$action = CheckFunc::checkInput2('func_action', 30, '');
$display_name = CheckFunc::checkInput2('display_name', 50, '');
$phone = CheckFunc::checkInput2('phone', 30, '');
$birthday = CheckFunc::checkInput2('birthday', 15, '');
$declaration = CheckFunc::checkInput2('declaration', 300, '');
$wp_user_avatar_id = CheckFunc::checkInputInt2('wp_user_avatar_id', 10, 0);
$wp_user_avatar_url = CheckFunc::checkInput2('wp_user_avatar_url', 400, '');
$user_id = CheckFunc::checkInputInt2('user_id', 10, 0);
if ($user_id == 0) {
$this->result->rc = ApiErrorDesc::ERR_PARAMS[0];
$this->result->msg = ApiErrorDesc::ERR_PARAMS[1];
die();
}
if ($user_id != 0) {
$user = get_user_by("id", $user_id);
if ($user == false) {
$this->result->rc = ApiErrorDesc::ERR_LOGIN_USER[0];
$this->result->msg = "no such user";
} else {
if ($action == "getInfo") {
$isdisplay = true;
} else if ($action == "competition_user_info") {
$res = wp_update_user(array('ID' => $user->ID, 'display_name' => $display_name));
// $flag = get_user_meta($user->ID, 'nickname', true) == $nickname;
if (is_wp_error($res)) {
$this->result->rc = -4;
$this->result->msg = "update nickname failed";
die();
}
update_user_meta($user->ID, 'phone', $phone);
update_user_meta($user->ID, 'birthday', $birthday);
update_user_meta($user->ID, 'declaration', $declaration);
update_user_meta($user->ID, 'wp_user_display_name', $display_name);
if($wp_user_avatar_id > 0){
update_user_meta($user->ID, 'wp_user_avatar_id', $wp_user_avatar_id);
update_user_meta($user->ID, 'wp_user_avatar_url', $wp_user_avatar_url);
}
// else if (!$flag) {
// $res = update_user_meta($user->ID, 'nickname', $nickname);
// if ($res == false) {
// $result->rc = -4;
// $result->msg = "update nickname failed";
// }
// }
// $wpuseravatarID = get_user_meta($user_id, 'wp_user_avatar_id', true); //用户头像id
// $wpuseravatar = wp_get_attachment_url($wpuseravatarID);
// if ($wpuseravatar) {
// $result->data->wpuseravatar = $wpuseravatar;
// } else {
// $result->data->wpuseravatar = 'https://class.bearingshield.cn/wp-content/uploads/2019/06/1544455123-logo-150x150.jpg';
// }
$this->result->rc = ApiErrorDesc::SUCCESS[0];
$this->result->msg = ApiErrorDesc::SUCCESS[1];
} else if ($action == "update_nickname") {
$nickname = htmlspecialchars($_POST['nickname']);
if ($nickname != null) {
$res = wp_update_user(array('ID' => $user->ID, 'display_name' => $nickname, 'user_nicename' => $nickname));
$flag = get_user_meta($user->ID, 'nickname', true) == $nickname;
if (is_wp_error($res)) {
$result->rc = -4;
$result->msg = "update nickname failed";
} else if (!$flag) {
$res = update_user_meta($user->ID, 'nickname', $nickname);
if ($res == false) {
$result->rc = -4;
$result->msg = "update nickname failed";
}
}
} else {
$result->rc = -3;
$result->msg = "nickname can not be null";
}
}
// else if ($action == "update_sex") {
// $sex_array = array('M', 'F');
// $flag = get_user_meta($user->ID, 'user_sex', true) == $_POST['sex'];
// if (!$flag&& in_array($_POST['sex'], $sex_array)) {
// $res = update_user_meta($user->ID, 'user_sex', $_POST['sex']);
// if ($res == false) {
// $result->rc = -5;
// $result->msg = "update sex failed";
// $result->debug = $res;
// }
// }
// }
else if ($action == "update_email") {
$email = $_POST['email'];
if ($email != null && is_email($email)) {
$res = wp_update_user(array('ID' => $user->ID, 'user_email' => $email));
if (is_wp_error($res)) {
$result->rc = -7;
$result->msg = "update email failed";
}
} else {
$result->rc = -6;
$result->msg = "incorrect email";
}
} else if ($action == "update_password") {
$oldpass = $_POST['op'];
$newpass = $_POST['np'];
$creds = array();
$creds['user_login'] = $user->data->user_login;
$creds['user_password'] = $_POST['op'];
$creds['remember'] = false;
$u = wp_signon($creds, false);
if (is_wp_error($u)) {
$result->rc = -8;
$result->msg = "incorrect old password";
} else {
$filterpsd = sanitize_text_field($newpass);
if ($newpass == "" || strlen($newpass) < 6 || strlen($newpass) > 20) {
$result->rc = -9;
$result->msg = "incorrect password length";
} else if ($filterpsd != $newpass) {
$result->rc = -10;
$result->msg = "incorrect new password";
} else {
wp_set_password($filterpsd, $u->ID);
}
$isdisplay = true;
}
} else if ($action == "update_wpuseravatar") {
$height = intval($_POST['img']);
$flag = get_user_meta($user->ID, 'wp_user_avatar', true) == $height;
$result->msg = "头像上传成功";
if (!$flag) {
$res = update_user_meta($user->ID, 'wp_user_avatar', $height);
if ($res == false) {
$result->rc = -11;
$result->msg = "update wpuseravatar failed";
$result->debug = $res;
}
}
}
}
}
}
///下面已废弃
/**
* 活動
* @return void
*/
// public function activityListGetInfoByPage()
// {
// $debug = $this->debug;
//
// $where = [];
// $where['pageNum'] = CheckFunc::checkInputInt2('pageNum', 10, 1);
// $where['pageSize'] = CheckFunc::checkInputInt2('pageSize', 10, 100);
// $where['order'] = 'id desc';
//
// $where['id'] = CheckFunc::checkInputInt2('id', 10, 0);
//
//// $id = CheckFunc::checkInputInt2('id', 10, 0);
//// if ($id > 0) {
//// $where['id'] = $id;
//// }
//
// $data = [];
//
// if ($debug) {
// print_r($where);
// }
//
// if ($where['id'] == 0) {
// $this->result->rc = ApiErrorDesc::ERR_PARAMS[0];
// $this->result->msg = ApiErrorDesc::ERR_PARAMS[1];
// die();
// }
//
//
// # 获取配置
// $RankingBiz = new RankingBs();
// $pageObj = $RankingBiz->activityListGetInfoByPage($where, $data, $debug);
//
// $this->result->rc = $pageObj->rc;
// $this->result->msg = $pageObj->msg;
//
// $this->result->total = $pageObj->total;
// $this->result->pageNum = $pageObj->pageNum;
// $this->result->pageSize = $pageObj->pageSize;
// $this->result->data = $pageObj->dataList;
// }
}
//单一文件入口
$app = new UserNoauth();
$app->run();
$isAi_output = true;
$rc = 666;