You can use session.*,Captcha,PasswordValidateJwtMake, JwtValidate and other processes to implement custom user login and user identity authentication.
The session data set when logging in can be used in data streams, JS-written processes and data tables.
Account and password login process:
On the login page, the user fills in the account name, verification code and password, and clicks the button to submit to the specified API.
The API receives the account name and password information, transfers it to the designated process, verifies the password, and issues a JWT token.
process password verification logic:
Call the CaptchaValidate process to verify the captcha.
Call the data model process to query the user data record through the account name, and obtain the encrypted stored password information.
Call the PasswordValidate process to verify whether the user fills in the correct password.
Issue a JWT token and set session information.
Write user.tab.json
and place it in the application tables
directory.
Create data table & add default user:
yao migrate -n user
Write password.flow.json
and token.flow.json
in the application flows/login/
directory. Implement password verification logic and JWT token issuance logic respectively.
Run process Debug:
yao run flows.login.password '::{"mobile":"zhang@yaoapps.com", "password": "5MCIXQYrR"}'
Write the interface description file user.http.json
, add two interfaces /captcha
and /login/password
, which are used for verification code picture and username and password login interface respectively, and place them in the api
directory of the application .
Description file content:
Interface debugging:
Start the service:
yao start
Read verification code interface:
curl http://127.0.0.1:5099/xiang/api/user/captcha
Login interface:
curl -X POST http://127.0.0.1:5099/xiang/api/user/login/password \-H 'Content-Type: application/json' \-d '{"mobile":"zhang@yaoapps.com", "password": "5MCIXQYrR", "captcha":{"id":1024, "code":"xv98"}}'
Edit app.json
to set up the user login API. The login interface route is /xiang/login/user/:is
, is
is a custom variable, which is submitted to the login interface along with the login form to identify the source of the user, and is generally used in multi-tenant systems.
{"name": "Elephant Biography","short": "Elephant Biography","description": "Elephant app background","option": {"nav_user": "xiang.user","nav_menu": "menu","hide_user": true,"hide_menu": true,"login": {"password": {"captcha": "/api/xiang/user/captcha","login": "/api/user/login/password"}}}}
The session data set by the user's successful login can be used in data streams, JS scripts and data tables.
Write inspect.flow.json
and place it in the application flows/user/
directory.
{"label": "Current user information","version": "1.0.0","description": "Current user information","nodes": [{"name": "Session","process": "session.Get","args": ["user"]}],"output": "{{$res.session}}"}
Run Debug:
Start the service and enable debug mode:
yao start --debug
Create a new command console:
yao run@127.0.0.1:5099 loginyao run@127.0.0.1:5099 flows.user.inspect
Write user.js
and place it in the application scripts
directory.
function Inspect() {return Process("session.Get", "user");}
yao run@127.0.0.1:5099 loginyao run@127.0.0.1:5099 scripts.user.Inspect
Session variables can be referenced directly in the data table apis.*.default
.
You can use session.*,Captcha,PasswordValidateJwtMake, JwtValidate and other processes to implement custom user login and user identity authentication.
The session data set when logging in can be used in data streams, JS-written processes and data tables.
Account and password login process:
On the login page, the user fills in the account name, verification code and password, and clicks the button to submit to the specified API.
The API receives the account name and password information, transfers it to the designated process, verifies the password, and issues a JWT token.
process password verification logic:
Call the CaptchaValidate process to verify the captcha.
Call the data model process to query the user data record through the account name, and obtain the encrypted stored password information.
Call the PasswordValidate process to verify whether the user fills in the correct password.
Issue a JWT token and set session information.
Write user.tab.json
and place it in the application tables
directory.
Create data table & add default user:
yao migrate -n user
Write password.flow.json
and token.flow.json
in the application flows/login/
directory. Implement password verification logic and JWT token issuance logic respectively.
Run process Debug:
yao run flows.login.password '::{"mobile":"zhang@yaoapps.com", "password": "5MCIXQYrR"}'
Write the interface description file user.http.json
, add two interfaces /captcha
and /login/password
, which are used for verification code picture and username and password login interface respectively, and place them in the api
directory of the application .
Description file content:
Interface debugging:
Start the service:
yao start
Read verification code interface:
curl http://127.0.0.1:5099/xiang/api/user/captcha
Login interface:
curl -X POST http://127.0.0.1:5099/xiang/api/user/login/password \-H 'Content-Type: application/json' \-d '{"mobile":"zhang@yaoapps.com", "password": "5MCIXQYrR", "captcha":{"id":1024, "code":"xv98"}}'
Edit app.json
to set up the user login API. The login interface route is /xiang/login/user/:is
, is
is a custom variable, which is submitted to the login interface along with the login form to identify the source of the user, and is generally used in multi-tenant systems.
{"name": "Elephant Biography","short": "Elephant Biography","description": "Elephant app background","option": {"nav_user": "xiang.user","nav_menu": "menu","hide_user": true,"hide_menu": true,"login": {"password": {"captcha": "/api/xiang/user/captcha","login": "/api/user/login/password"}}}}
The session data set by the user's successful login can be used in data streams, JS scripts and data tables.
Write inspect.flow.json
and place it in the application flows/user/
directory.
{"label": "Current user information","version": "1.0.0","description": "Current user information","nodes": [{"name": "Session","process": "session.Get","args": ["user"]}],"output": "{{$res.session}}"}
Run Debug:
Start the service and enable debug mode:
yao start --debug
Create a new command console:
yao run@127.0.0.1:5099 loginyao run@127.0.0.1:5099 flows.user.inspect
Write user.js
and place it in the application scripts
directory.
function Inspect() {return Process("session.Get", "user");}
yao run@127.0.0.1:5099 loginyao run@127.0.0.1:5099 scripts.user.Inspect
Session variables can be referenced directly in the data table apis.*.default
.