mirror of
https://github.com/actix/examples
synced 2024-11-30 17:14:35 +01:00
parent
da976e0415
commit
f3cf37bb0d
23
Cargo.lock
generated
23
Cargo.lock
generated
@ -491,17 +491,6 @@ dependencies = [
|
|||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "actix-web-cors"
|
|
||||||
version = "1.0.0"
|
|
||||||
dependencies = [
|
|
||||||
"actix-cors",
|
|
||||||
"actix-web",
|
|
||||||
"env_logger",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "actix-web-lab"
|
name = "actix-web-lab"
|
||||||
version = "0.19.1"
|
version = "0.19.1"
|
||||||
@ -2296,6 +2285,18 @@ version = "0.8.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cors"
|
||||||
|
version = "1.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"actix-cors",
|
||||||
|
"actix-web",
|
||||||
|
"env_logger",
|
||||||
|
"log",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpufeatures"
|
name = "cpufeatures"
|
||||||
version = "0.2.9"
|
version = "0.2.9"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-web-cors"
|
name = "cors"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
@ -8,5 +8,6 @@ actix-web = { workspace = true, features = ["rustls"] }
|
|||||||
actix-cors.workspace = true
|
actix-cors.workspace = true
|
||||||
|
|
||||||
env_logger.workspace = true
|
env_logger.workspace = true
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
log.workspace = true
|
||||||
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
|
@ -1,17 +1,21 @@
|
|||||||
|
use std::io;
|
||||||
|
|
||||||
use actix_cors::Cors;
|
use actix_cors::Cors;
|
||||||
use actix_web::{http::header, middleware::Logger, App, HttpServer};
|
use actix_web::{http::header, middleware::Logger, App, HttpServer};
|
||||||
|
|
||||||
mod user;
|
mod user;
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> io::Result<()> {
|
||||||
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
|
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
|
||||||
|
|
||||||
|
log::info!("starting HTTP server at http://localhost:8080");
|
||||||
|
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
App::new()
|
App::new()
|
||||||
.wrap(
|
.wrap(
|
||||||
Cors::default()
|
Cors::default()
|
||||||
.allowed_origin("http://localhost:8080")
|
.allowed_origin("http://localhost:8081")
|
||||||
.allowed_methods(vec!["GET", "POST"])
|
.allowed_methods(vec!["GET", "POST"])
|
||||||
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
|
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
|
||||||
.allowed_header(header::CONTENT_TYPE)
|
.allowed_header(header::CONTENT_TYPE)
|
||||||
|
@ -4,15 +4,42 @@
|
|||||||
<div id="title">
|
<div id="title">
|
||||||
<a to="#">SignUp</a>
|
<a to="#">SignUp</a>
|
||||||
</div>
|
</div>
|
||||||
<input type="text" name="username" placeholder="Username" v-model="Username" required />
|
<input
|
||||||
<input type="text" name="email" placeholder="E-mail" v-model="Email" required />
|
type="text"
|
||||||
<input type="password" name="password" placeholder="Password" v-model="Password" required/>
|
name="username"
|
||||||
<input type="password" name="confirm_password" placeholder="Confirm password" v-model="ConfirmPassword" required/><br/>
|
placeholder="Username"
|
||||||
|
v-model="Username"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="email"
|
||||||
|
placeholder="E-mail"
|
||||||
|
v-model="Email"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
name="password"
|
||||||
|
placeholder="Password"
|
||||||
|
v-model="Password"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
name="confirm_password"
|
||||||
|
placeholder="Confirm password"
|
||||||
|
v-model="ConfirmPassword"
|
||||||
|
required
|
||||||
|
/><br />
|
||||||
|
|
||||||
<button id="submit" @click="signup">Sign up</button>
|
<button id="submit" @click="signup">Sign up</button>
|
||||||
|
|
||||||
<div id="user-info">
|
<div id="user-info">
|
||||||
<p>Click Above 'Sign up' Button <br> Then Get Your Signup Info!</p>
|
<p>
|
||||||
|
Click Above 'Sign up' Button <br />
|
||||||
|
Then Get Your Signup Info!
|
||||||
|
</p>
|
||||||
<p>email : {{ email }}</p>
|
<p>email : {{ email }}</p>
|
||||||
<p>username : {{ username }}</p>
|
<p>username : {{ username }}</p>
|
||||||
<p>password : {{ password }}</p>
|
<p>password : {{ password }}</p>
|
||||||
@ -33,7 +60,7 @@ export default {
|
|||||||
|
|
||||||
email: '',
|
email: '',
|
||||||
username: '',
|
username: '',
|
||||||
password: ''
|
password: '',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -46,16 +73,17 @@ export default {
|
|||||||
username: username,
|
username: username,
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
confirm_password: confirm_password
|
confirm_password: confirm_password,
|
||||||
}
|
}
|
||||||
fetch('http://localhost:8000/user/info', {
|
fetch('http://localhost:8080/user/info', {
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
headers: {
|
headers: {
|
||||||
'content-type': 'application/json'
|
'content-type': 'application/json',
|
||||||
},
|
},
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
}).then(response => response.json())
|
})
|
||||||
.then(json => {
|
.then((response) => response.json())
|
||||||
|
.then((json) => {
|
||||||
console.log(json)
|
console.log(json)
|
||||||
this.email = json.email
|
this.email = json.email
|
||||||
this.username = json.username
|
this.username = json.username
|
||||||
@ -64,8 +92,8 @@ export default {
|
|||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -82,13 +110,13 @@ export default {
|
|||||||
background-color: bisque;
|
background-color: bisque;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
input[type="text"],
|
input[type='text'],
|
||||||
input[type="password"] {
|
input[type='password'] {
|
||||||
margin: 6px auto auto;
|
margin: 6px auto auto;
|
||||||
width: 250px;
|
width: 250px;
|
||||||
height: 36px;
|
height: 36px;
|
||||||
border: none;
|
border: none;
|
||||||
border-bottom: 1px solid #AAA;
|
border-bottom: 1px solid #aaa;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
#submit {
|
#submit {
|
||||||
@ -103,7 +131,7 @@ input[type="password"] {
|
|||||||
transition: 0.1s ease;
|
transition: 0.1s ease;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
input[type="checkbox"] {
|
input[type='checkbox'] {
|
||||||
margin-top: 11px;
|
margin-top: 11px;
|
||||||
}
|
}
|
||||||
dialog {
|
dialog {
|
||||||
@ -131,7 +159,8 @@ color: white;
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
#closeDialog:hover, #closeDialog:focus {
|
#closeDialog:hover,
|
||||||
|
#closeDialog:focus {
|
||||||
opacity: 0.92;
|
opacity: 0.92;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,11 @@ version = "1.0.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4"
|
actix-web.workspace = true
|
||||||
chrono = { version = "0.4.26", default-features = false, features = ["std", "clock"] }
|
chrono.workspace = true
|
||||||
derive_more = "0.99.7"
|
derive_more.workspace = true
|
||||||
dotenv = "0.15"
|
dotenv = "0.15"
|
||||||
env_logger = "0.10"
|
env_logger.workspace = true
|
||||||
log = "0.4"
|
log.workspace = true
|
||||||
mysql = "24"
|
mysql = "24"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde.workspace = true
|
||||||
|
Loading…
Reference in New Issue
Block a user