pub async fn login(
    db: ConnectionPool,
    user: User,
    user_agent: Option<extract::TypedHeader<headers::UserAgent>>,
    extract::ConnectInfo(addr): extract::ConnectInfo<std::net::SocketAddr>,
) -> Result<LoginResponse, chartered_db::Error> {
    let user_agent = if let Some(extract::TypedHeader(user_agent)) = user_agent {
        Some(user_agent.as_str().to_string())
    } else {
        None
    };

    let expires = chrono::Utc::now() + chrono::Duration::hours(1);
    let key = UserSession::generate(
        db,
        user.id,
        None,
        Some(expires.naive_utc()),
        user_agent,
        Some(addr.to_string()),
    )
    .await?;

    Ok(LoginResponse {
        user_uuid: user.uuid.0,
        key: key.session_key,
        expires,
        picture_url: user.picture_url,
    })
}
/// Takes the given `User` and generates a session for it and returns a response containing an API
/// key to the frontend that it can save for further request
Takes the given `User` and generates a session for it and returns a response containing an API
key to the frontend that it can save for further request
Takes the given ` User ` and generates a session for it and returns a response containing an API key to the frontend that it can save for further request
pub async fn login(
    db: ConnectionPool,
    user: User,
    user_agent: Option<extract::TypedHeader<headers::UserAgent>>,
    extract::ConnectInfo(addr): extract::ConnectInfo<std::net::SocketAddr>,
) -> Result<LoginResponse, chartered_db::Error> {
    let user_agent = if let Some(extract::TypedHeader(user_agent)) = user_agent {
        Some(user_agent.as_str().to_string())
    } else {
        None
    };
    let expires = chrono::Utc::now() + chrono::Duration::hours(1);
    let key = UserSession::generate(
        db,
        user.id,
        None,
        Some(expires.naive_utc()),
        user_agent,
        Some(addr.to_string()),
    )
    .await?;
    Ok(LoginResponse {
        user_uuid: user.uuid.0,
        key: key.session_key,
        expires,
        picture_url: user.picture_url,
    })
}
pub async fn login ( db : ConnectionPool , user : User , user_agent : Option < extract :: TypedHeader < headers :: UserAgent > > , extract :: ConnectInfo ( addr ) : extract :: ConnectInfo < std :: net :: SocketAddr > , ) -> Result < LoginResponse , chartered_db :: Error > { let user_agent = if let Some ( extract :: TypedHeader ( user_agent ) ) = user_agent { Some ( user_agent . as_str ( ) . to_string ( ) ) } else { None } ; let expires = chrono :: Utc :: now ( ) + chrono :: Duration :: hours ( 1 ) ; let key = UserSession :: generate ( db , user . id , None , Some ( expires . naive_utc ( ) ) , user_agent , Some ( addr . to_string ( ) ) , ) . await ? ; Ok ( LoginResponse { user_uuid : user . uuid . 0 , key : key . session_key , expires , picture_url : user . picture_url , } ) }
Takes the given `User` and generates a session for it and returns a response containing an API
key to the frontend that it can save for further request
Takes the given ` User ` and generates a session for it and returns a response containing an API key to the frontend that it can save for further request
db
ConnectionPool
user
User
user_agent
extract::ConnectInfo<std::net::SocketAddr>
db
ConnectionPool
user
User
user_agent
extract::ConnectInfo<std::net::SocketAddr>