public static function update($id, $data) { foreach ($data as $key => $value) { switch ($key) { case "idUser": break; case "username": if (!UserValidation::validateUsername($value)) { User::$error = "Inocorrenct username."; return false; } break; case "password": if (!UserValidation::validatePassword($value)) { User::$error = "Inocorrenct password."; return false; } break; } } return parent::update($id, $data, get_class()); }
public function extAction() { if ($this->request->isPost()) { $ans = []; try { //登陆验证 $id = $this->checkLogin(); $validation = new UserValidation(); $messages = $validation->validate($_POST); if (count($messages)) { foreach ($messages as $message) { throw new Exception($message, 102); } } $user_ext = UserExt::findFirst($id); if ($user_ext == null) { $user_ext = new UserExt(); $user_ext->id = $id; } $user_ext->realname = $_POST['realname']; $user_ext->phone = $_POST['phone']; $user_ext->birthday = $_POST['birthday']; $user_ext->sex = $_POST['sex']; $user_ext->email = $_POST['email']; $date = explode('-', $user_ext->birthday); if (!checkdate($date[1], $date[2], $date[0])) { //检查时间是否合法 throw new Exception('日期不合法', 602); } $z1 = strtotime(date("y-m-d")); //当前时间 $z2 = strtotime($user_ext->birthday); //输入时间 if ($z2 > $z1) { throw new Exception('这是未来的某一天', 603); } $success = $user_ext->save(); if ($success) { $ans['ret'] = 0; } else { foreach ($user_ext->getMessages() as $message) { throw new Exception($message, 100); } } echo json_encode($ans); } catch (Exception $e) { $ans['ret'] = -1; Utils::makeError($e, $ans); echo json_encode($ans); } } }