chyabrung-cli 0.2.2

The `chy` command line tool for Chyabrung: scaffolding, dev server with hot reload, builds, generators, migrations and one-command deploys
use chyabrung::prelude::*;

/// A row of the `users` table (created in `migrations/..._create_users_table.up.sql`).
#[derive(Debug, Clone, Serialize, Deserialize, Model)]
#[model(timestamps)]
pub struct User {
    pub id: i64,
    pub name: String,
    pub email: String,
    /// Never sent to clients.
    #[serde(skip_serializing, default)]
    pub password_hash: String,
    pub role: String,
    pub created_at: Option<String>,
    pub updated_at: Option<String>,
}

impl User {
    /// Who this user is, for tokens and permission checks.
    pub fn identity(&self) -> Identity {
        Identity::new(self.id.to_string()).with_name(self.name.clone()).with_role(self.role.clone())
    }
}