Coder Social home page Coder Social logo

Comments (11)

victorteokw avatar victorteokw commented on June 17, 2024 1

Hi @akelyasir, create a file named .env in the same directory: JWT_SECRET=mytopsecret

from teo.

victorteokw avatar victorteokw commented on June 17, 2024

Hi @akelyasir

Answer your questions.

  1. Integrate by yourself. Teo with custom programming code behaves just like any vanilla web frameworks.
  2. Temporarily cookie and session can't be accessed directly on the Request object. If you need it, I will add this feature in one day.
  3. Integrate by yourself. None of web frameworks provide email sender. Use an open source package to send.
  4. Use custom program feature of Teo.
  5. You can try it out with teo generate admin.

from teo.

akelyasir avatar akelyasir commented on June 17, 2024

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

from teo.

victorteokw avatar victorteokw commented on June 17, 2024

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.

from teo.

victorteokw avatar victorteokw commented on June 17, 2024

I will add sessions and cookies tomorrow. A new version will be published.

from teo.

akelyasir avatar akelyasir commented on June 17, 2024

@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

from teo.

victorteokw avatar victorteokw commented on June 17, 2024

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: "[email protected]",
      phoneNo: "13588888888",
      password: "Aa123456"
    }
  }
  group Root {
    record root {
      email: "[email protected]",
      password: "Aa123456"
    }
  }
}

from teo.

victorteokw avatar victorteokw commented on June 17, 2024

Remove array type fields if you are not using PostgreSQL.

from teo.

victorteokw avatar victorteokw commented on June 17, 2024

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.

from teo.

akelyasir avatar akelyasir commented on June 17, 2024

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",
}

from teo.

akelyasir avatar akelyasir commented on June 17, 2024

Hi @victorteokw

Thank you very much. I forgot to create the env file.

from teo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.