Open akelyasir opened 4 months ago
Hi @akelyasir
Answer your questions.
teo generate admin
.Hi @victorteokw
Thank you very much for your answers. You have done a great job, congratulations. I'm still very new to the Rust programming language. I saw that you use actix-web based on Teo. I'm looking forward to your example and plugin about using cookie sessions. The reason I asked about Tera was because you were basically using actix-web, I was just wondering if it was possible to add it and it would be nice if it were. Of course, you know the system much better, I have just discovered Teo. I am thinking of integrating Rust Lettre regarding mail, but I would appreciate it if you could give me some information on where to start. Finally, I would be happy if you share whether it is possible to add all the features of Actix-web or everything integrated to Teo.
Thanks and regards
Hi @akelyasir, if you send emails inside a route, just write route handler to handle email sending. Otherwise, use custom pipeline item. Follow the 4 tutorials from the official docs: https://docs.teodev.io/getting-started/beginner-tutorial/write-a-schema-only-app, and you will be able to write custom pipeline item.
I will add sessions and cookies tomorrow. A new version will be published.
@victorteokw
thank you for your interest I tried to create it with the cargo teo generate admin
command, but there was no result. Do I need to make any extra settings? How can I reach
Hi @akelyasir, try this demo, replace schema.teo with this:
connector {
// SQLite
// provider: .sqlite,
// url: "sqlite:./database.sqlite",
// MySQL
// provider: .mysql,
// url: "mysql://localhost:3306/adminbackend",
// PostgreSQL
provider: .postgres,
url: "postgres://localhost:5432/adminbackend",
}
server {
bind: ("0.0.0.0", 5052)
}
admin {
dest: "../teo-admin-dev",
host: .inject("process.env.TEO_HOST"),
languages: [.enUs, .enUk, .de, .es, .fr, .he, .hi, .ja, .ko, .zhCn, .zhTw]
}
@identity.tokenIssuer($identity.jwt(expired: 3600 * 24 * 365))
@identity.jwtSecret(ENV["JWT_SECRET"]!) @admin.administrator
model Root {
@id @autoIncrement @readonly
id: Int
@unique @onSet($if($presents, $isEmail)) @identity.id
email: String
@writeonly @onSet($presents.bcrypt.salt) @admin.secureInput
@identity.checker($get(.value).presents.bcrypt.verify($self.get(.password).presents))
password: String
include handler identity.signIn
include handler identity.identity
}
@identity.tokenIssuer($identity.jwt(expired: 3600 * 24 * 365))
@identity.jwtSecret(ENV["JWT_SECRET"]!) @admin.administrator
model Admin {
@id @autoIncrement @readonly
id: Int
@unique @onSet($if($presents, $isEmail)) @identity.id
email: String
@unique @identity.id
phoneNo: String
@writeonly @onSet($presents.bcrypt.salt) @admin.secureInput
@identity.checker($get(.value).presents.bcrypt.verify($self.get(.password).presents))
password: String
include handler identity.signIn
include handler identity.identity
}
model Item {
@id @autoIncrement @readonly
id: Int
@admin.title
name: String
}
model Product {
@id @autoIncrement @readonly
id: Int
name: String
stock: Int
@foreignKey
categoryId: Int
@relation(fields: .categoryId, references: .id)
category: Category
}
model Category {
@id @autoIncrement @readonly
id: Int
name: String
@relation(fields: .id, references: .categoryId)
products: Product[]
}
enum Sex {
male
female
}
model Record {
@id @autoIncrement @readonly
id: Int
string: String
bool: Bool
int: Int
float: Float
decimal: Decimal
date: Date
dateTime: DateTime
sex: Sex
strings: String[]
genders: Sex[]
}
middlewares [identity.identityFromJwt(secret: ENV["JWT_SECRET"]!)]
autoseed dataset default {
group Admin {
record admin {
email: "admin@gmail.com",
phoneNo: "13588888888",
password: "Aa123456"
}
}
group Root {
record root {
email: "root@gmail.com",
password: "Aa123456"
}
}
}
Remove array type fields if you are not using PostgreSQL.
Hi @akelyasir, I added cookies to the Rust Request object. However, it's a bit cumbersome to add it to the Response object. In the future 0.3.0 version, we will use hyper to rewrite the HTTP layer. At that time, full features of cookies will be supported.
Hi @victorteokw
Thank you for your attention. I couldn't run the schema you sent and couldn't find the problem.
Error: Error { code: 500, message: "teo_result::Error: {\"code\":500,\"message\":\"Cannot convert Null into String\",\"errors\":null}", errors: None, platform_native_object: None }
I am getting an error like this. I am using Postgresql.
connector {
provider: .postgres,
url: "postgres://username:password@localhost:5432/database",
}
Hi @akelyasir, create a file named .env
in the same directory: JWT_SECRET=mytopsecret
Hi @victorteokw
Thank you very much. I forgot to create the env file.
Hi @akelyasir, Cookie APIs are added to the Rust Response API in the 0.3.0-alpha.0 version.
Hello, I had a few questions about the system.
Thanks