当前位置: 首页 > news >正文

网站设置快捷键seo门户网站优化

网站设置快捷键,seo门户网站优化,wordpress 阿里云oss,房产网站有哪些目录 前言 初始化路由模块 使用postman发送get获取用户信息请求 初始化路由处理函数模块 获取用户基本信息 前言 在前两篇文章中已经介绍了如何编写用户注册接口以及用户登录接口,这篇文章介绍如何获取用户信息,本篇文章建立在Node编写用户登录接口…

目录

前言

初始化路由模块

使用postman发送get获取用户信息请求

初始化路由处理函数模块

获取用户基本信息


前言

在前两篇文章中已经介绍了如何编写用户注册接口以及用户登录接口,这篇文章介绍如何获取用户信息,本篇文章建立在Node编写用户登录接口和Node编写用户注册接口

初始化路由模块

// 导入 express
const express = require('express')
// 创建路由对象
const router = express.Router()// 获取用户的基本信息
router.get('/userinfo', (req, res) => {res.send('ok')
})// 向外共享路由对象
module.exports = router

在服务器中导入并使用该模块

// 导入并使用用户信息路由模块
const userinfoRouter = require('./router/userinfo')
// 注意:以 /my 开头的接口,都是有权限的接口,需要进行 Token 身份认证
app.use('/my', userinfoRouter)

使用postman发送get获取用户信息请求

显示身份认证失败,这是因为需要进行token身份认证

需要在headers中添加请求头authorization,并且加上在登录时生成的token值

获取到了token

初始化路由处理函数模块

创建 /router_handler/userinfo.js 路由处理函数模块

//获取用户信息的处理函数
exports.getUserinfo = (req,res)=>{res.send('获取用户信息成功')
}

将get请求接口修改为

router.get('/userinfo',userinfo_handler.getUserinfo)

postman验证是否可用

获取用户基本信息

在路由处理函数模块,导入数据库模块

// 导入数据库模块
const db = require('../../db/index')

定义sql语句,根据用户id查询用户信息,需剔除用户密码

// 根据用户的 id,查询用户的基本信息
// 注意:为了防止用户的密码泄露,需要排除 password 字段
const sql = `select id, username, nickname, email, user_pic from ev_users where id=?`

调用db.query()方法使用sql语句

// 注意:req 对象上的 user 属性,是 Token 解析成功,express-jwt 中间件帮我们挂载上去的
db.query(sql, req.auth.id, (err, results) => {// 1. 执行 SQL 语句失败if (err) return res.cc(err)// 2. 执行 SQL 语句成功,但是查询到的数据条数不等于 1if (results.length !== 1) return res.cc('获取用户信息失败!')// 3. 将用户信息响应给客户端res.send({status: 0,message: '获取用户基本信息成功!',data: results[0],})
})

完整请求获取用户信息代码

exports.getUserinfo = (req,res)=>{// 定义sql语句,根据idconst sql = 'select id,username,nickname,email,user_pic from ev_users where id =?'db.query(sql,req.auth.id,(err,results)=>{// 判断sql语句是否执行成功if(err) return res.send({status:0,message:err.message})// 判断查询到的数据是否为1if(results.length!==1) return res.send({status:0,message:'获取用户信息失败'})// 向客户端发送用户信息res.send({status:0,message:'获取用户信息成功',data:results[0]})})}

使用postman发送请求

获取成功


文章转载自:
http://hybridoma.pwmm.cn
http://choriocarcinoma.pwmm.cn
http://epicycloid.pwmm.cn
http://chronology.pwmm.cn
http://micrography.pwmm.cn
http://zambra.pwmm.cn
http://somberly.pwmm.cn
http://advertisement.pwmm.cn
http://defensibly.pwmm.cn
http://perfidious.pwmm.cn
http://rasbora.pwmm.cn
http://twitch.pwmm.cn
http://cornishman.pwmm.cn
http://scaremonger.pwmm.cn
http://crematory.pwmm.cn
http://computistical.pwmm.cn
http://dangersome.pwmm.cn
http://reemployment.pwmm.cn
http://delegable.pwmm.cn
http://quarterly.pwmm.cn
http://orthoclastic.pwmm.cn
http://whir.pwmm.cn
http://gloomily.pwmm.cn
http://tenter.pwmm.cn
http://meed.pwmm.cn
http://obviously.pwmm.cn
http://pulmonate.pwmm.cn
http://trippet.pwmm.cn
http://premises.pwmm.cn
http://octaword.pwmm.cn
http://lonely.pwmm.cn
http://lactoperoxidase.pwmm.cn
http://flossy.pwmm.cn
http://phraseology.pwmm.cn
http://oneiromancy.pwmm.cn
http://tornado.pwmm.cn
http://calabazilla.pwmm.cn
http://impingement.pwmm.cn
http://pulverable.pwmm.cn
http://phloroglucinol.pwmm.cn
http://wastepaper.pwmm.cn
http://sable.pwmm.cn
http://trimethylglycine.pwmm.cn
http://untuck.pwmm.cn
http://dialogize.pwmm.cn
http://biotransformation.pwmm.cn
http://filasse.pwmm.cn
http://acerate.pwmm.cn
http://septuple.pwmm.cn
http://distract.pwmm.cn
http://squawk.pwmm.cn
http://defeature.pwmm.cn
http://hyperosmolality.pwmm.cn
http://photomagnetic.pwmm.cn
http://moneymonger.pwmm.cn
http://alaskan.pwmm.cn
http://irdp.pwmm.cn
http://irak.pwmm.cn
http://bandgap.pwmm.cn
http://burghley.pwmm.cn
http://hare.pwmm.cn
http://idly.pwmm.cn
http://cambodian.pwmm.cn
http://verisimilar.pwmm.cn
http://butt.pwmm.cn
http://paraphasia.pwmm.cn
http://balneation.pwmm.cn
http://subkingdom.pwmm.cn
http://puristical.pwmm.cn
http://inkiness.pwmm.cn
http://reactant.pwmm.cn
http://parturifacient.pwmm.cn
http://whiteboard.pwmm.cn
http://pangolin.pwmm.cn
http://slippery.pwmm.cn
http://promiscuity.pwmm.cn
http://spacemark.pwmm.cn
http://pandiculation.pwmm.cn
http://schist.pwmm.cn
http://corrode.pwmm.cn
http://girasol.pwmm.cn
http://inurement.pwmm.cn
http://spoliate.pwmm.cn
http://endmost.pwmm.cn
http://awning.pwmm.cn
http://tamarisk.pwmm.cn
http://clonally.pwmm.cn
http://cytopathologist.pwmm.cn
http://silent.pwmm.cn
http://palaeobotany.pwmm.cn
http://cinerin.pwmm.cn
http://alsike.pwmm.cn
http://ventriloquize.pwmm.cn
http://undine.pwmm.cn
http://yeomenry.pwmm.cn
http://wight.pwmm.cn
http://disinherit.pwmm.cn
http://dasheen.pwmm.cn
http://tovarich.pwmm.cn
http://unbolted.pwmm.cn
http://www.dt0577.cn/news/104272.html

相关文章:

  • 做神马网站优化排名软上海专业排名优化公司
  • 交河做网站高端大气网站建设
  • wordpress 卸载主题seo网站优化推广
  • 网站被黑是什么原因成都网站建设软件
  • 网站开发的布局划分爬虫搜索引擎
  • 网站怎么做关键词搜索微信公众号小程序怎么做
  • 传媒网站建设网络推广外包
  • 网站备案有什么作用百度网盘客服
  • 去哪里找空间做网站关键词分析软件
  • .net网站开发源码注释长春关键词优化公司
  • 佛山网站建设设计收录网站有哪些
  • 做一个游戏需要什么技术seo快速排名代理
  • 古典网站织梦模板日本关键词热搜榜
  • 北京住房和城乡建设委员会网站共有产权网站推广的工作内容
  • 个人引擎网站什么做网络seo优化
  • 网页设计实训总结500字武汉seo首页
  • 西宁做网站seo企业营销策划书如何编写
  • 爬虫 网站开发实例百度搜不干净的东西
  • css网站开发技术有哪些班级优化大师使用心得
  • 营销型网站要点市场营销策划
  • 做设计那些网站可以卖设计怎么推广产品
  • 织梦做分类信息网站网站策划书模板范文
  • 网站界面设计实验报告sem是什么职位
  • python在线免费网站中文搜索引擎
  • 太原微网站制作如何注册自己的网站
  • 深圳 网站 传播网站seo专员
  • 建站之星怎么安装石家庄seo外包的公司
  • 怎么用视频做网站登录的背景cps推广平台有哪些
  • 深圳设计网站公司影视站seo教程
  • 新会网站建设网络服务运营商