backend/models/forms/RegisterUserBySellerForm.php
/**
     * Signs user up.
     *
     * @return Users|null the saved model or null if saving fails
     */
Signs user up.
@return Users|null the saved model or null if saving fails
Signs user up . @return Users|null the saved model or null if saving fails
public function createUser()
    {
        $transaction = Yii::$app->db->beginTransaction();
        $user                 = new Users();
        $user->user_name      = $this->user_name
            ? $this->user_name
            : Functions::getNameFromEmail($this->user_email);
        $user->user_email     = $this->user_email;
        $user->license_type   = Licenses::TYPE_FREE_TRIAL;
        $user->license_expire = date(SQL_DATE_FORMAT, time() + Licenses::getCountDaysTrialLicense() * 86400);
        $user->user_last_ip   = Yii::$app->request->getUserIP();
        $user->user_ref_id    = $this->seller_id;
        $user->has_personal_seller = $this->has_personal_seller;
        $user->setPassword($this->password);
        $user->generateAuthKey();
        $user->generatePasswordResetToken();
        if ($user->save()) {
            if ($this->create_business_account == Users::YES) {
                $user->license_type   = Licenses::TYPE_PAYED_BUSINESS_ADMIN;
                $user->license_period = Licenses::PERIOD_MONTHLY;
                $user->pay_type       = Users::PAY_CARD;
                $user->payment_already_initialized = Users::PAYMENT_INITIALIZED;
                $lic_start = date(SQL_DATE_FORMAT, Functions::getTimestampEndOfDayByTimestamp(time()));
                $lic_end = $user->license_expire;
                $lic_lastpay = time();
                $lic_group_id = time();
                for ($i = 1; $i <= $this->license_count; $i++) {
                    $lic = new UserLicenses();
                    $lic->lic_start = $lic_start;
                    $lic->lic_end = $lic_end;
                    $lic->lic_period = $user->license_period;
                    $lic->lic_owner_user_id = $user->user_id;
                    $lic->lic_colleague_user_id = ($i == 1) ? $user->user_id : null;
                    $lic->lic_colleague_email = ($i == 1) ? $user->user_email : null;
                    $lic->lic_lastpay_timestamp = $lic_lastpay;
                    $lic->lic_group_id = $lic_group_id;
                    if (!$lic->save()) {
                        Yii::$app->session->setFlash('danger', Json::encode($lic->getErrors()));
                        $transaction->rollBack();
                        return false;
                    }
                }
                UserLicenses::updateAll(['lic_end' => $lic_end], ['lic_owner_user_id' => $user->user_id]);
                $user->license_expire = $lic_end;
                $user->license_count_available = $this->license_count - 1;
                $user->license_count_used = 1;
            }
            if ($user->save()) {
                $transaction->commit();
            } else {
                $transaction->rollBack();
                return false;
            }
            if ($this->send_email_about_registration) {
                MailTemplatesStatic::sendByKey(MailTemplatesStatic::template_key_newRegister, $user->user_email, ['UserObject' => $user]);
            }
            return $user;
        }
        $transaction->rollBack();
        return false;
    }
public function createUser ( ) { $ transaction = Yii :: $ app -> db -> beginTransaction ( ) ; $ user = new Users ( ) ; $ user -> user_name = $ this -> user_name ? $ this -> user_name : Functions :: getNameFromEmail ( $ this -> user_email ) ; $ user -> user_email = $ this -> user_email ; $ user -> license_type = Licenses :: TYPE_FREE_TRIAL ; $ user -> license_expire = date ( SQL_DATE_FORMAT , time ( ) + Licenses :: getCountDaysTrialLicense ( ) * 86400 ) ; $ user -> user_last_ip = Yii :: $ app -> request -> getUserIP ( ) ; $ user -> user_ref_id = $ this -> seller_id ; $ user -> has_personal_seller = $ this -> has_personal_seller ; $ user -> setPassword ( $ this -> password ) ; $ user -> generateAuthKey ( ) ; $ user -> generatePasswordResetToken ( ) ; if ( $ user -> save ( ) ) { if ( $ this -> create_business_account == Users :: YES ) { $ user -> license_type = Licenses :: TYPE_PAYED_BUSINESS_ADMIN ; $ user -> license_period = Licenses :: PERIOD_MONTHLY ; $ user -> pay_type = Users :: PAY_CARD ; $ user -> payment_already_initialized = Users :: PAYMENT_INITIALIZED ; $ lic_start = date ( SQL_DATE_FORMAT , Functions :: getTimestampEndOfDayByTimestamp ( time ( ) ) ) ; $ lic_end = $ user -> license_expire ; $ lic_lastpay = time ( ) ; $ lic_group_id = time ( ) ; for ( $ i = 1 ; $ i <= $ this -> license_count ; $ i ++ ) { $ lic = new UserLicenses ( ) ; $ lic -> lic_start = $ lic_start ; $ lic -> lic_end = $ lic_end ; $ lic -> lic_period = $ user -> license_period ; $ lic -> lic_owner_user_id = $ user -> user_id ; $ lic -> lic_colleague_user_id = ( $ i == 1 ) ? $ user -> user_id : null ; $ lic -> lic_colleague_email = ( $ i == 1 ) ? $ user -> user_email : null ; $ lic -> lic_lastpay_timestamp = $ lic_lastpay ; $ lic -> lic_group_id = $ lic_group_id ; if ( ! $ lic -> save ( ) ) { Yii :: $ app -> session -> setFlash ( 'danger' , Json :: encode ( $ lic -> getErrors ( ) ) ) ; $ transaction -> rollBack ( ) ; return false ; } } UserLicenses :: updateAll ( [ 'lic_end' => $ lic_end ] , [ 'lic_owner_user_id' => $ user -> user_id ] ) ; $ user -> license_expire = $ lic_end ; $ user -> license_count_available = $ this -> license_count - 1 ; $ user -> license_count_used = 1 ; } if ( $ user -> save ( ) ) { $ transaction -> commit ( ) ; } else { $ transaction -> rollBack ( ) ; return false ; } if ( $ this -> send_email_about_registration ) { MailTemplatesStatic :: sendByKey ( MailTemplatesStatic :: template_key_newRegister , $ user -> user_email , [ 'UserObject' => $ user ] ) ; } return $ user ; } $ transaction -> rollBack ( ) ; return false ; }
Signs user up.
Signs user up .
//var_dump($lic->getErrors()); exit; //Yii::$app->session->setFlash('success', 'User successfuly created.'); //Yii::$app->session->setFlash('danger', 'There was an error on creating new User.');