signup function
This commit is contained in:
+6
-8
@@ -28,7 +28,7 @@ async fn main() {
|
||||
// build our application with a route
|
||||
let app = Router::new()
|
||||
// `GET /` goes to `root`
|
||||
.route("/", post(root))
|
||||
.route("/", get(root))
|
||||
// `POST /users` goes to `create_user`
|
||||
.route("/user/signup", post(signup))
|
||||
.with_state(pool);
|
||||
@@ -45,16 +45,14 @@ async fn main() {
|
||||
|
||||
// basic handler that responds with a static string
|
||||
async fn root() -> &'static str {
|
||||
println!("jjjj",);
|
||||
"Hello, World!"
|
||||
}
|
||||
|
||||
async fn signup(
|
||||
State(pool): State<PgPool>,
|
||||
Query(query_params): Query<Signup>,
|
||||
) -> impl IntoResponse {
|
||||
println!("{:?}", query_params);
|
||||
async fn signup(State(pool): State<PgPool>, Json(signup): Json<Signup>) -> impl IntoResponse {
|
||||
println!("{:?}", signup);
|
||||
// insert your application logic here
|
||||
let pass_hash = sha256::digest(&*query_params.password);
|
||||
let pass_hash = sha256::digest(&*signup.password);
|
||||
|
||||
let result = sqlx::query!(
|
||||
r#"
|
||||
@@ -62,7 +60,7 @@ INSERT INTO users (username, password)
|
||||
VALUES ( $1, $2 )
|
||||
RETURNING id;
|
||||
"#,
|
||||
query_params.username,
|
||||
signup.username,
|
||||
pass_hash.as_bytes(),
|
||||
)
|
||||
.fetch_one(&pool)
|
||||
|
||||
Reference in New Issue
Block a user