pub fn create_user(
        &self,
        new_user: &NewUser,
        connect: Option<NewUserConnect>,
    ) -> Result<(User, (PublicKey, SecretKey))> {
        self.db.build_transaction().read_write().run(|| {
            let (user, keypair) = {
                use crate::schema::user_keys::{self, dsl as ak_dsl};
                use crate::schema::users;
                let user = diesel::insert_into(users::table)
                    .values(new_user)
                    .get_result::<User>(self.db)?;

                // Buatkan key pair untuk akun yang baru saja dibuat.
                let keypair = crypto::gen_keypair();

                diesel::insert_into(user_keys::table)
                    .values(&NewUserKey {
                        user_id: user.id,
                        pub_key: keypair.0.to_hex(),
                        secret_key: keypair.1.to_hex(),
                        active: true,
                    })
                    .execute(self.db)?;

                (user, keypair)
            };

            if let Some(mut new_user_connect) = connect {
                use crate::schema::user_connect::{self, dsl};
                new_user_connect.user_id = user.id;
                diesel::insert_into(user_connect::table)
                    .values(&new_user_connect)
                    .on_conflict(dsl::device_id)
                    .do_update()
                    .set(&new_user_connect)
                    .execute(self.db)?;
            }

            Ok((user, keypair))
        })
    }
/// Buat akun baru secara langsung.
Buat akun baru secara langsung.
Buat akun baru secara langsung .
pub fn create_user(
        &self,
        new_user: &NewUser,
        connect: Option<NewUserConnect>,
    ) -> Result<(User, (PublicKey, SecretKey))> {
        self.db.build_transaction().read_write().run(|| {
            let (user, keypair) = {
                use crate::schema::user_keys::{self, dsl as ak_dsl};
                use crate::schema::users;
                let user = diesel::insert_into(users::table)
                    .values(new_user)
                    .get_result::<User>(self.db)?;
                // Buatkan key pair untuk akun yang baru saja dibuat.
                let keypair = crypto::gen_keypair();
                diesel::insert_into(user_keys::table)
                    .values(&NewUserKey {
                        user_id: user.id,
                        pub_key: keypair.0.to_hex(),
                        secret_key: keypair.1.to_hex(),
                        active: true,
                    })
                    .execute(self.db)?;
                (user, keypair)
            };
            if let Some(mut new_user_connect) = connect {
                use crate::schema::user_connect::{self, dsl};
                new_user_connect.user_id = user.id;
                diesel::insert_into(user_connect::table)
                    .values(&new_user_connect)
                    .on_conflict(dsl::device_id)
                    .do_update()
                    .set(&new_user_connect)
                    .execute(self.db)?;
            }
            Ok((user, keypair))
        })
    }
pub fn create_user ( & self , new_user : & NewUser , connect : Option < NewUserConnect > , ) -> Result < ( User , ( PublicKey , SecretKey ) ) > { self . db . build_transaction ( ) . read_write ( ) . run ( | | { let ( user , keypair ) = { use crate :: schema :: user_keys :: { self , dsl as ak_dsl } ; use crate :: schema :: users ; let user = diesel :: insert_into ( users :: table ) . values ( new_user ) . get_result :: < User > ( self . db ) ? ; // Buatkan key pair untuk akun yang baru saja dibuat. let keypair = crypto :: gen_keypair ( ) ; diesel :: insert_into ( user_keys :: table ) . values ( & NewUserKey { user_id : user . id , pub_key : keypair . 0 . to_hex ( ) , secret_key : keypair . 1 . to_hex ( ) , active : true , } ) . execute ( self . db ) ? ; ( user , keypair ) } ; if let Some ( mut new_user_connect ) = connect { use crate :: schema :: user_connect :: { self , dsl } ; new_user_connect . user_id = user . id ; diesel :: insert_into ( user_connect :: table ) . values ( & new_user_connect ) . on_conflict ( dsl :: device_id ) . do_update ( ) . set ( & new_user_connect ) . execute ( self . db ) ? ; } Ok ( ( user , keypair ) ) } ) }
Buat akun baru secara langsung.
Buat akun baru secara langsung .
&self
new_user
&NewUser
connect
Option<NewUserConnect>
&self
new_user
&NewUser
connect
Option<NewUserConnect>