/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->login = $this->username ?: $this->email; $user->email = $this->email; $user->password = $this->password; $seller = User::findByUsername($this->seller ?: 'ahnames'); if (!$seller->id) { throw new InvalidParamException('wrong seller given'); } $user->seller_id = $seller->id; //$user->setPassword($this->password); //$user->generateAuthKey(); $user->save(); $user = User::findByUsername($user->login); if (!$user) { throw new IntegrityException('failed create user'); } $contact = Contact::findOne($user->id); $contact->load([$contact->formName() => $this->getAttributes()]); $contact->save(); return $user; } return null; }
/** * Finds the Contact model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Contact the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Contact::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Finds the Contact model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $company_id * @param integer $user_id * @return Contact the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($company_id, $user_id) { if (($model = Contact::findOne(['company_id' => $company_id, 'user_id' => $user_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }