/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { if ($this->initCompanyTables()) { $glbUser = new GlbUser(); $glbUser->username = $this->username; $glbUser->email = $this->email; $glbUser->company_id = $this->company_id; $glbUser->region = $this->region; if ($glbUser->save()) { if ($this->initUserTables($this->company_id)) { Yii::$app->session->set('company_id', $this->company_id); $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); $user->firstname = $this->firstname; $user->middlename = $this->middlename; $user->lastname = $this->lastname; $user->mobile = $this->mobile; $user->phone = $this->phone; $user->role = 'admin'; $user->verification_code = Yii::$app->security->generateRandomString('10'); if ($user->save()) { return $user; } } } } } return false; }