20
This commit is contained in:
8
.editorconfig
Normal file
8
.editorconfig
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.v]
|
||||||
|
indent_style = tab
|
7
.gitattributes
vendored
Normal file
7
.gitattributes
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
* text=auto eol=lf
|
||||||
|
*.bat eol=crlf
|
||||||
|
|
||||||
|
**/*.v linguist-language=V
|
||||||
|
**/*.vv linguist-language=V
|
||||||
|
**/*.vsh linguist-language=V
|
||||||
|
**/v.mod linguist-language=V
|
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Binaries for programs and plugins
|
||||||
|
main
|
||||||
|
v5
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
*.dll
|
||||||
|
|
||||||
|
# Ignore binary output folders
|
||||||
|
bin/
|
||||||
|
|
||||||
|
# Ignore common editor/system specific metadata
|
||||||
|
.DS_Store
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.iml
|
||||||
|
|
||||||
|
# ENV
|
||||||
|
.env
|
||||||
|
|
||||||
|
# vweb and database
|
||||||
|
*.db
|
||||||
|
*.js
|
8
databases/config_databases_sqlite.v
Normal file
8
databases/config_databases_sqlite.v
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
module databases
|
||||||
|
|
||||||
|
import db.sqlite // can change to 'db.mysql', 'db.pg'
|
||||||
|
|
||||||
|
pub fn create_db_connection() !sqlite.DB {
|
||||||
|
mut db := sqlite.connect('app.db')!
|
||||||
|
return db
|
||||||
|
}
|
8
src/controller.v
Normal file
8
src/controller.v
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
import vweb
|
||||||
|
|
||||||
|
@[post]
|
||||||
|
pub fn (mut app App) signup() vweb.Result{
|
||||||
|
return $vweb.html()
|
||||||
|
}
|
12
src/entitities.v
Normal file
12
src/entitities.v
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
@[table: 'auth']
|
||||||
|
pub struct Auth {
|
||||||
|
mut:
|
||||||
|
id int @[primary; sql: serial]
|
||||||
|
username string @[sql_type: 'TEXT']
|
||||||
|
email string @[sql_type: 'TEXT'; unique]
|
||||||
|
access_level int @[sql_type: 'INTEGER']
|
||||||
|
password string @[sql_type: 'TEXT']
|
||||||
|
// products []Product @[fkey: 'user_id']
|
||||||
|
}
|
45
src/main.v
Normal file
45
src/main.v
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
import vweb
|
||||||
|
import os
|
||||||
|
import databases
|
||||||
|
|
||||||
|
const (
|
||||||
|
port = 8082
|
||||||
|
)
|
||||||
|
|
||||||
|
struct App {
|
||||||
|
vweb.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (app App) before_request() {
|
||||||
|
println('[web] before_request: ${app.req.method} ${app.req.url}')
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut db := databases.create_db_connection() or { panic(err) }
|
||||||
|
|
||||||
|
sql db {
|
||||||
|
// create table Faculty (
|
||||||
|
// id serial primary key,
|
||||||
|
// name text not null,
|
||||||
|
// email text not null unique,
|
||||||
|
// password text not null
|
||||||
|
// )
|
||||||
|
create table Auth
|
||||||
|
} or { panic('error on create table: ${err}') }
|
||||||
|
|
||||||
|
db.close() or { panic(err) }
|
||||||
|
|
||||||
|
mut app := &App{}
|
||||||
|
app.serve_static('/favicon.ico', 'src/assets/favicon.ico')
|
||||||
|
// makes all static files available.
|
||||||
|
app.mount_static_folder_at(os.resource_abs_path('.'), '/')
|
||||||
|
|
||||||
|
vweb.run(app, port)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut app App) login() vweb.Result {
|
||||||
|
|
||||||
|
return $vweb.html()
|
||||||
|
}
|
0
src/services.v
Normal file
0
src/services.v
Normal file
24
src/templates/login.html
Normal file
24
src/templates/login.html
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<!-- Log-In Page -->
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Log In</title>
|
||||||
|
<!-- Add this line to include the Tailwind CSS library -->
|
||||||
|
@css 'https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css'
|
||||||
|
</head>
|
||||||
|
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
|
||||||
|
<div class="w-full max-w-md">
|
||||||
|
<h1 class="text-3xl mb-6 font-bold text-center text-blue-500">Welcome Back!</h1>
|
||||||
|
<form action="/login" method="post">
|
||||||
|
<div class="mb-4">
|
||||||
|
<label for="email" class="block text-sm font-medium leading-relaxed tracking-wide mb-2">Email:</label>
|
||||||
|
<input type="email" id="email" name="email" placeholder="Enter email address" class="appearance-none bg-white rounded w-full py-2 px-4 leading-tight focus:outline-none focus:shadow-outline"/>
|
||||||
|
</div>
|
||||||
|
<div class="mb-4">
|
||||||
|
<label for="password" class="block text-sm font-medium leading-relaxed tracking-wide mb-2">Password:</label>
|
||||||
|
<input type="password" id="password" name="password" placeholder="Enter password" class="appearance-none bg-white rounded w-full py-2 px-4 leading-tight focus:outline-none focus:shadow-outline"/>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline">Log In</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
28
src/templates/signup.html
Normal file
28
src/templates/signup.html
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<!-- Sign-Up Page -->
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Sign Up</title>
|
||||||
|
<!-- Add this line to include the Tailwind CSS library -->
|
||||||
|
@css 'https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css'
|
||||||
|
</head>
|
||||||
|
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
|
||||||
|
<div class="w-full max-w-md">
|
||||||
|
<h1 class="text-3xl mb-6 font-bold text-center text-blue-500">Create an Account</h1>
|
||||||
|
<form action="/signup" method="post">
|
||||||
|
<div class="mb-4">
|
||||||
|
<label for="username" class="block text-sm font-medium leading-relaxed tracking-wide mb-2">Username:</label>
|
||||||
|
<input type="text" id="username" name="username" placeholder="Enter username" class="appearance-none bg-white rounded w-full py-2 px-4 leading-tight focus:outline-none focus:shadow-outline"/>
|
||||||
|
</div>
|
||||||
|
<div class="mb-4">
|
||||||
|
<label for="email" class="block text-sm font-medium leading-relaxed tracking-wide mb-2">Email:</label>
|
||||||
|
<input type="email" id="email" name="email" placeholder="Enter email address" class="appearance-none bg-white rounded w-full py-2 px-4 leading-tight focus:outline-none focus:shadow-outline"/>
|
||||||
|
</div>
|
||||||
|
<div class="mb-4">
|
||||||
|
<label for="password" class="block text-sm font-medium leading-relaxed tracking-wide mb-2">Password:</label>
|
||||||
|
<input type="password" id="password" name="password" placeholder="Enter password" class="appearance-none bg-white rounded w-full py-2 px-4 leading-tight focus:outline-none focus:shadow-outline"/>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline">Submit</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
7
src/view.v
Normal file
7
src/view.v
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
import vweb
|
||||||
|
|
||||||
|
pub fn (mut app App) signup() vweb.Result{
|
||||||
|
return $vweb.html()
|
||||||
|
}
|
0
src/view_api.v
Normal file
0
src/view_api.v
Normal file
Reference in New Issue
Block a user