增加用户登录认证接口,并返回认证相关结果数据
This commit is contained in:
parent
4b9c6ee202
commit
9b3712e7fa
|
|
@ -11,27 +11,27 @@ local user = require("model.user")
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
--认证用户返回用户数据信息
|
--认证用户返回用户数据信息
|
||||||
local function authenticate(username, password)
|
local function authenticate(name, passwd)
|
||||||
--验证用户名是否为空
|
--验证用户名是否为空
|
||||||
if username == nil or username == "" then
|
if name == "" then
|
||||||
return 0x010003, nil
|
return 0x010003, nil
|
||||||
end
|
end
|
||||||
--验证密码是否为空
|
--验证密码是否为空
|
||||||
if password == nil or password == "" then
|
if passwd == "" then
|
||||||
return 0x010002, nil
|
return 0x010002, nil
|
||||||
end
|
end
|
||||||
--根据用户进行验证用户是否存在
|
--根据用户进行验证用户是否存在
|
||||||
local code, res = user:where("name", "=", username).where("password", "=", password):get()
|
local code, res = user:where("name", "=", name):where("password", "=", passwd):get()
|
||||||
if code == 0 and res ~= nil then
|
if code == 0 and res ~= nil then
|
||||||
return code, res
|
return code, res
|
||||||
end
|
end
|
||||||
--根据手机号进行验证用户是否存在
|
--根据手机号进行验证用户是否存在
|
||||||
code, res = user:where("phone", "=", username).where("password", "=", password):get()
|
code, res = user:where("phone", "=", name):where("password", "=", passwd):get()
|
||||||
if code == 0 and res ~= nil then
|
if code == 0 and res ~= nil then
|
||||||
return code, res
|
return code, res
|
||||||
end
|
end
|
||||||
--根据邮箱进行验证用户是否存在
|
--根据邮箱进行验证用户是否存在
|
||||||
code, res = user:where("email", "=", username).where("password", "=", password):get()
|
code, res = user:where("email", "=", name):where("password", "=", passwd):get()
|
||||||
if code == 0 and res ~= nil then
|
if code == 0 and res ~= nil then
|
||||||
return code, res
|
return code, res
|
||||||
end
|
end
|
||||||
|
|
@ -47,7 +47,10 @@ function _M.login(jsonData)
|
||||||
return 0x000001,result
|
return 0x000001,result
|
||||||
end
|
end
|
||||||
--解析json中的键和数据值
|
--解析json中的键和数据值
|
||||||
local name, passwd, captcha, checkKey
|
local name = ""
|
||||||
|
local passwd = ""
|
||||||
|
local captcha = ""
|
||||||
|
local checkKey = ""
|
||||||
for key, value in pairs(result) do
|
for key, value in pairs(result) do
|
||||||
if key == "username" then name = value end
|
if key == "username" then name = value end
|
||||||
if key == "password" then passwd = value end
|
if key == "password" then passwd = value end
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ function _M.addUser(jsonData)
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据用户、手机号、邮箱进行验证用户是否存在
|
--根据用户、手机号、邮箱进行验证用户是否存在
|
||||||
local code, res = user:where("name", "=", name).where("phone", "=", phone).where("email", "=", phone):get()
|
local code, res = user:where("name", "=", name):where("phone", "=", phone):where("email", "=", phone):get()
|
||||||
if code ~= 0 then
|
if code ~= 0 then
|
||||||
return 0x000001,res
|
return 0x000001,res
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ local helpers = require("util.helpers")
|
||||||
|
|
||||||
--max =a and b or c--a?b:c
|
--max =a and b or c--a?b:c
|
||||||
|
|
||||||
--[[
|
local cjson = require("cjson")
|
||||||
local User = require("model.user")
|
local User = require("model.user")
|
||||||
|
|
||||||
--获取数据表中的记录数
|
--获取数据表中的记录数
|
||||||
|
|
@ -27,21 +27,24 @@ code, res = User:find("1")
|
||||||
--查询表中的所有记录
|
--查询表中的所有记录
|
||||||
code, res = User:all()
|
code, res = User:all()
|
||||||
--显示查询到的数据记录
|
--显示查询到的数据记录
|
||||||
--for _, row in ipairs(res) do
|
for _, row in ipairs(res) do
|
||||||
-- for key, value in pairs(row) do
|
for key, value in pairs(row) do
|
||||||
-- ngx.say(key .. ":" .. tostring(value))
|
ngx.say(key .. ":" .. tostring(value))
|
||||||
-- end
|
end
|
||||||
--end
|
end
|
||||||
|
|
||||||
--ngx.say("----begin where and query---")
|
ngx.say("----begin where and query---")
|
||||||
-- 返回 users 表中 username 字段的值是 `cgreen` 的,`password` 字段的值是 `xxxxxx` 的多条数据,注意此处返回是 table 数组,`first()` 方法返回的是单条数据
|
-- 返回 users 表中 username 字段的值是 `cgreen` 的,`password` 字段的值是 `xxxxxx` 的多条数据,注意此处返回是 table 数组,`first()` 方法返回的是单条数据
|
||||||
code, res = User:where('name','=','zhangsan'):where('password','=','111111'):get()
|
code, res = User:where('name','=','zhangsan'):where('password','=','111111'):get()
|
||||||
--for _, row in ipairs(res) do
|
ngx.say(code)
|
||||||
-- for key, value in pairs(row) do
|
if res ~= nil then
|
||||||
-- ngx.say(key .. ":" .. tostring(value))
|
for _, row in ipairs(res) do
|
||||||
-- end
|
for key, value in pairs(row) do
|
||||||
--end
|
ngx.say(key .. ":" .. tostring(value))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--[[
|
||||||
--ngx.say("----begin where or query---")
|
--ngx.say("----begin where or query---")
|
||||||
-- 返回 `name` 为 `xxx` 或者 `yyy` 的所有用户 table 数组
|
-- 返回 `name` 为 `xxx` 或者 `yyy` 的所有用户 table 数组
|
||||||
code, res = User:where('name','=','zhangsan'):orwhere('name','=','admin'):get()
|
code, res = User:where('name','=','zhangsan'):orwhere('name','=','admin'):get()
|
||||||
|
|
@ -92,9 +95,7 @@ for _, row in ipairs(data.data) do
|
||||||
end
|
end
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
--获取请求参数的键值和数据值
|
--[[
|
||||||
local cjson = require("cjson")
|
|
||||||
|
|
||||||
--读取请求体的数据
|
--读取请求体的数据
|
||||||
ngx.req.read_body()
|
ngx.req.read_body()
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
|
|
@ -106,6 +107,7 @@ local data = cjson.decode(body_data)
|
||||||
data.id = helpers.getUuid()
|
data.id = helpers.getUuid()
|
||||||
local ret = helpers.convert_json(data)
|
local ret = helpers.convert_json(data)
|
||||||
ngx.say(ret)
|
ngx.say(ret)
|
||||||
|
--]]
|
||||||
|
|
||||||
--local header = ngx.req.get_headers()
|
--local header = ngx.req.get_headers()
|
||||||
--for k,v in pairs(header) do
|
--for k,v in pairs(header) do
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user