pub fn activate_registered_user(&self, token: String) -> Result<User> {
        use crate::schema::user_keys::{self, dsl as ak_dsl};
        use crate::schema::{register_users, users};

        self.db.build_transaction().read_write().run(|| {
            let reg_acc: RegisterUser = register_users::dsl::register_users
                .find(token.clone())
                .first(self.db)?;
            // .map_err(From::from)?;

            let new_user = NewUser {
                full_name: &reg_acc.full_name,
                email: &reg_acc.email,
                phone_num: &reg_acc.phone_num,
                active: true,
                register_time: Utc::now().naive_utc(),
            };

            let user = diesel::insert_into(users::table)
                .values(&new_user)
                .get_result::<User>(self.db)?;
            // .map_err(From::from)?;

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

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

            // delete reference in registered users table
            diesel::delete(register_users::dsl::register_users.find(token)).execute(self.db)?;

            Ok(user)
        })
    }
/// Mengaktifkan akun yang telah melakukan registrasi tapi belum aktif.
Mengaktifkan akun yang telah melakukan registrasi tapi belum aktif.
Mengaktifkan akun yang telah melakukan registrasi tapi belum aktif .
pub fn activate_registered_user(&self, token: String) -> Result<User> {
        use crate::schema::user_keys::{self, dsl as ak_dsl};
        use crate::schema::{register_users, users};
        self.db.build_transaction().read_write().run(|| {
            let reg_acc: RegisterUser = register_users::dsl::register_users
                .find(token.clone())
                .first(self.db)?;
            // .map_err(From::from)?;
            let new_user = NewUser {
                full_name: &reg_acc.full_name,
                email: &reg_acc.email,
                phone_num: &reg_acc.phone_num,
                active: true,
                register_time: Utc::now().naive_utc(),
            };
            let user = diesel::insert_into(users::table)
                .values(&new_user)
                .get_result::<User>(self.db)?;
            // .map_err(From::from)?;
            // Buatkan key pair untuk akun yang baru saja dibuat.
            let (pub_key, secret_key) = crypto::gen_keypair();
            diesel::insert_into(user_keys::table)
                .values(&NewUserKey {
                    user_id: user.id,
                    pub_key: pub_key.to_hex(),
                    secret_key: secret_key.to_hex(),
                    active: true,
                })
                .execute(self.db)?;
            // delete reference in registered users table
            diesel::delete(register_users::dsl::register_users.find(token)).execute(self.db)?;
            Ok(user)
        })
    }
pub fn activate_registered_user ( & self , token : String ) -> Result < User > { use crate :: schema :: user_keys :: { self , dsl as ak_dsl } ; use crate :: schema :: { register_users , users } ; self . db . build_transaction ( ) . read_write ( ) . run ( | | { let reg_acc : RegisterUser = register_users :: dsl :: register_users . find ( token . clone ( ) ) . first ( self . db ) ? ; // .map_err(From::from)?; let new_user = NewUser { full_name : & reg_acc . full_name , email : & reg_acc . email , phone_num : & reg_acc . phone_num , active : true , register_time : Utc :: now ( ) . naive_utc ( ) , } ; let user = diesel :: insert_into ( users :: table ) . values ( & new_user ) . get_result :: < User > ( self . db ) ? ; // .map_err(From::from)?; // Buatkan key pair untuk akun yang baru saja dibuat. let ( pub_key , secret_key ) = crypto :: gen_keypair ( ) ; diesel :: insert_into ( user_keys :: table ) . values ( & NewUserKey { user_id : user . id , pub_key : pub_key . to_hex ( ) , secret_key : secret_key . to_hex ( ) , active : true , } ) . execute ( self . db ) ? ; // delete reference in registered users table diesel :: delete ( register_users :: dsl :: register_users . find ( token ) ) . execute ( self . db ) ? ; Ok ( user ) } ) }
Mengaktifkan akun yang telah melakukan registrasi tapi belum aktif.
Mengaktifkan akun yang telah melakukan registrasi tapi belum aktif .
&self
token
String
&self
token
String