mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
veb.auth: update the README.md example (#25245)
Some checks are pending
vlib modules CI / build-module-docs (push) Waiting to run
Some checks are pending
vlib modules CI / build-module-docs (push) Waiting to run
This commit is contained in:
parent
21c46f4ae5
commit
4665a6f4a8
1 changed files with 7 additions and 10 deletions
|
@ -51,17 +51,14 @@ pub fn (mut app App) register_user(mut ctx Context, name string, password string
|
||||||
password_hash: auth.hash_password_with_salt(password, salt)
|
password_hash: auth.hash_password_with_salt(password, salt)
|
||||||
salt: salt
|
salt: salt
|
||||||
}
|
}
|
||||||
sql app.db {
|
user_id := sql app.db {
|
||||||
insert new_user into User
|
insert new_user into User
|
||||||
} or {}
|
} or { 0 }
|
||||||
|
|
||||||
// Get new user ID (until RETURNING is supported by ORM)
|
|
||||||
if x := app.find_user_by_name(name) {
|
|
||||||
// Generate and insert the token using user ID
|
// Generate and insert the token using user ID
|
||||||
token := app.auth.add_token(x.id) or { '' }
|
token := app.auth.add_token(user_id) or { '' }
|
||||||
// Authenticate the user by adding the token to the cookies
|
// Authenticate the user by adding the token to the cookies
|
||||||
ctx.set_cookie(name: 'token', value: token)
|
ctx.set_cookie(name: 'token', value: token)
|
||||||
}
|
|
||||||
|
|
||||||
return ctx.redirect('/')
|
return ctx.redirect('/')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue