RUST, Actix, Login, Bcrypt, Diesel, SQLite
RUST, Actix, Login, Bcrypt, Diesel, SQLite
# SQLite3
# Ubuntu
$ sudo apt-get install libsqlite3-dev
# windows use vcpkg to install sqlite3
cargo install diesel_cli --no-default-features --features "sqlite-bundled"
$ echo "DATABASE_URL=user.db" > .env
$ diesel migration run
$ cargo check
$ cargo run
# for arm processor build
$ cargo build --target arm-unknown-linux-gnueabihf --release
curl -i --request GET http://127.0.0.1:3000/api/ping
# result
pong
curl -i --request POST \
--url http://127.0.0.1:3000/api/auth/register \
--header 'content-type: application/json' \
--data '{
"username": "admin",
"password":"12345"
}'
# result
HTTP/1.1 200 OK
set-cookie: auth=I7djxyY0IK5eecymVLQYi/WyoIh7m+et95qAnQ3ZQv1Nn8vmWEaf7JrhC2Kub4GRpw==; HttpOnly; Path=/; Domain=localhost; Max-Age=86400
content-length: 0
curl -i --request POST \
--url http://127.0.0.1:3000/api/auth/login \
--header 'content-type: application/json' \
--data '{
"username": "admin",
"password":"12345"
}'
# result
HTTP/1.1 200 OK
set-cookie: auth=I7djxyY0IK5eecymVLQYi/WyoIh7m+et95qAnQ3ZQv1Nn8vmWEaf7JrhC2Kub4GRpw==; HttpOnly; Path=/; Domain=localhost; Max-Age=86400
content-length: 0
curl -i --request POST \
--url http://127.0.0.1:3000/api/auth/update_password \
--header 'content-type: application/json' \
--data '{
"old_password": "12345",
"password":"123456"
}'
# result
HTTP/1.1 200 OK
set-cookie: auth=FkTMjoBI0crA6PcQ7BNJMoifVP/hLN9WpoySpwG8aplIphxy2aqh9ecPZMSfGCc; HttpOnly; Path=/; Domain=localhost; Max-Age=86400
content-length: 0