/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = UserInvites::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('phrase', 'The requested page does not exist.')); } return $model; }
/** * before validate attributes */ protected function beforeValidate() { $controller = strtolower(Yii::app()->controller->id); $currentAction = strtolower(Yii::app()->controller->id . '/' . Yii::app()->controller->action->id); if (parent::beforeValidate()) { if ($this->isNewRecord) { $setting = OmmuSettings::model()->findByPk(1, array('select' => 'site_type, signup_username, signup_approve, signup_verifyemail, signup_random, signup_inviteonly, signup_checkemail')); $this->profile_id = 1; $this->salt = self::getUniqueCode(); if (in_array($controller, array('o/admin', 'o/member'))) { // Auto Approve Users if ($setting->signup_approve == 1) { $this->enabled = 1; } // Auto Verified Email User if ($setting->signup_verifyemail == 1) { $this->verified = 0; } // Generate user by admin $this->modified_id = !Yii::app()->user->isGuest ? Yii::app()->user->id : 0; } else { $this->level_id = UserLevel::getDefault(); $this->enabled = $setting->signup_approve == 1 ? 1 : 0; $this->verified = $setting->signup_verifyemail == 1 ? 0 : 1; // Signup by Invite (Admin or User) if ($setting->site_type == 1 && $setting->signup_inviteonly != 0) { if ($setting->signup_checkemail == 1 && $this->inviteCode == '') { $this->addError('inviteCode', 'Invite Code tidak boleh kosong.'); } if ($this->email != '') { $invite = UserInvites::getInvite(strtolower($this->email)); if ($invite != null) { if ($invite->queue->member_id != 0) { $this->addError('email', 'Email anda sudah terdaftar sebagai user, silahkan login.'); } else { if ($setting->signup_inviteonly == 1 && $invite->queue->invite == 0) { $this->addError('email', 'Maaf invite hanya bisa dilakukan oleh admin'); } else { if ($setting->signup_checkemail == 1) { $code = UserInvites::model()->findByAttributes(array('code' => $this->inviteCode), array('select' => 'queue_id, user_id, code')); if ($code == null) { $this->addError('inviteCode', 'Invite Code yang and masukan salah.'); } else { $this->referenceId = $code->user_id; } } } } } else { $this->addError('email', 'Email anda belum ada dalam daftar invite.'); } } else { if ($setting->signup_checkemail == 1) { $this->addError('inviteCode', 'Invite Code yang and masukan salah, silahkan lengkapi input email'); } } } } // Username required if ($setting->signup_username == 1) { if ($this->username != '') { $user = self::model()->findByAttributes(array('username' => $this->username)); if ($user != null) { $this->addError('username', 'Username already in use'); } } else { $this->addError('username', 'Username cannot be blank.'); } } // Random password if ($setting->signup_random == 1) { $this->confirmPassword = $this->newPassword = self::getGeneratePassword(); $this->verified = 1; } $this->creation_ip = $_SERVER['REMOTE_ADDR']; } else { /** * Modify Mamber * = Admin modify member * = User modify */ // Admin modify member if (in_array($currentAction, array('o/admin/edit', 'o/member/edit'))) { $this->modified_date = date('Y-m-d H:i:s'); $this->modified_id = Yii::app()->user->id; } else { if (!in_array($controller, array('password'))) { $this->update_date = date('Y-m-d H:i:s'); } $this->update_ip = $_SERVER['REMOTE_ADDR']; } } } return true; }
public static function deleteInvitedUserById($id) { return UserInvites::model()->deleteByPk($id); }