/** * Update the user infomation . * @return \Illuminate\Http\Response */ public function update() { $data = ["status" => ""]; $validatorRules = array('password' => 'confirmed|between:6,15', 'username' => 'between:6,20', 'birthday' => 'date'); $validatorAttributes = array('password' => '密码', 'username' => '用户名', 'birthday' => '生日'); postCheck($validatorRules, Config::get('phylab.validatorMessage'), $validatorAttributes); $userAttr = ['password' => 'password', 'username' => 'name', 'birthday' => 'birthday', 'sex' => 'sex', 'company' => 'company', 'companyAddr' => 'company_addr', 'introduction' => 'introduction']; try { foreach ($userAttr as $key => $value) { if (Request::has($key)) { Auth::user()->update([$value => Request::get($key)]); } } $data["status"] = SUCCESS_MESSAGE; } catch (Exception $e) { throw new DatabaseOperatorException(); } return response()->json($data); }
/** * Delete the Star * @return \Illuminate\Http\Response */ public function delete() { $data = ["status" => ""]; $validatorRules = array('id' => 'required|integer|exists:stars,id,user_id,' . Auth::user()->id); $validatorAttributes = array('id' => '收藏的对象'); postCheck($validatorRules, Config::get('phylab.validatorMessage'), $validatorAttributes); try { $link = Star::find(Request::get('id'))->link; Star::destroy(Request::get('id')); try { Storage::disk('local_public')->delete('star_pdf/' . $link); } catch (Exception $e) { throw new FileIOException(); } $data["status"] = SUCCESS_MESSAGE; } catch (Exception $e) { throw new DatabaseOperatorException(); } return response()->json($data); }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { //post 传入 xml 模板文件 $data = ["status" => "", "experimentId" => "", "link" => ""]; $validatorRules = array('id' => 'required|integer|exists:reports,id', 'xml' => 'required'); $validatorAttributes = array('id' => '生成报告ID', 'xml' => '模板xml文件'); postCheck($validatorRules, Config::get('phylab.validatorMessage'), $validatorAttributes); //ToDo $xmlLink = getRandName() . ".xml"; try { Storage::put("xml_tmp/" . $xmlLink, Request::get('xml')); } catch (Exception $e) { throw new FileIOException(); } $tmpName = getRandName(); $report = Report::find(Request::get('id')); $scriptLink = $report->script_link; $experimentId = $report->experiment_id; $system = exec(Config::get('phylab.scriptPath') . "create.sh " . Config::get('phylab.tmpReportPath') . " " . Config::get('phylab.scriptPath') . $scriptLink . " " . Config::get('phylab.tmpXmlPath') . $xmlLink . " " . Config::get('phylab.tmpReportPath') . $tmpName . ".tex", $output, $reval); #echo Config::get('phylab.scriptPath')."create.sh ".Config::get('phylab.tmpReportPath')." ".Config::get('phylab.scriptPath').$scriptLink." ".Config::get('phylab.tmpXmlPath').$xmlLink." ".Config::get('phylab.tmpReportPath').$tmpName.".tex"; #echo $out; #echo $system."\n"; #echo $reval."\n"; #echo var_dump($output); if ($reval == 0) { #echo $system.'\n'; #echo "python ".storage_path()."/app/script/".$scriptLink." ".storage_path()."/app/xml_tmp/".$xmlLink." ".public_path()."/pdf_tmp/".$tmpName.".tex"; $system = json_decode($system); if ($system->status == SUCCESS_MESSAGE) { $data["status"] = SUCCESS_MESSAGE; $data["link"] = $tmpName . ".pdf"; $data["experimentId"] = $experimentId; } else { $data["status"] = FAIL_MESSAGE; } } else { $data["status"] = FAIL_MESSAGE; } return response()->json($data); }
<?php if (isset($_POST["account"]) && isset($_POST["password"])) { $account = $_POST["account"]; $password = $_POST["password"]; $confirmPW = $_POST["confirmPW"]; $name = $_POST["name"]; //字符过滤和HTML注入 $account = strCheck($account); $password = strCheck($password); $name = strCheck($name); $account = postCheck("账号", $account, 3, 10); if ($account) { $password = postCheck("密码", $password, 3, 50); if ($password) { $name = postCheck("姓名", $name, 2, 20); } } if ($account && $password && $name) { if ($password == $confirmPW) { //创建对象并打开连接,最后一个参数是选择的数据库名称 $mysqli = new mysqli('localhost', 'root', '123456', 'test'); //检查连接是否成功 if (mysqli_connect_errno()) { die('Unable to connect!') . mysqli_connect_error(); } $passwordHash = password_hash($password, PASSWORD_DEFAULT); $sql = "INSERT INTO user VALUES ('{$account}', '{$passwordHash}', '{$name}')"; //执行sql语句,完全面向对象的 $result = $mysqli->query($sql); if ($result) {