public function actionCreate() { $this->layout = Yum::module()->adminLayout; $model = new YumPermission(); $this->performAjaxValidation($model, 'permission-create-form'); if (isset($_POST['YumPermission'])) { $model->attributes = $_POST['YumPermission']; if ($model->validate()) { if ($_POST['YumPermission']['type'] == 'user') { $model->subordinate = $_POST['YumPermission']['subordinate_id']; $model->principal = $_POST['YumPermission']['principal_id']; } else { if ($_POST['YumPermission']['type'] == 'role') { $model->subordinate_role = $_POST['YumPermission']['subordinate_id']; $model->principal_role = $_POST['YumPermission']['principal_id']; } } if ($model->save()) { $this->redirect(array('admin')); } return; } } $model->type = 'user'; // preselect 'user' $this->render('create', array('model' => $model)); }
public function rules() { $rules = parent::rules(); /* FIXME: As soon as i grasp how i can dynamically add variables to a class in PHP, i will enable this code snippet for flexibility: $profile = new YumProfile; $profile_rules = $profile->rules(); foreach($profile_rules as $rule) if(isset($rule[0]) && is_string($rule[0])) $this->${$rule[0]} = ''; $rules = array_merge($rules, $profile->rules()); */ $rules[] = array('username', 'required'); $rules[] = array('password, verifyPassword', 'required'); $rules[] = array('password', 'compare', 'compareAttribute'=>'verifyPassword', 'message' => Yum::t("Retype password is incorrect.")); if(Yum::module('registration')->enableCaptcha) $rules[] = array('verifyCode', 'captcha', 'allowEmpty'=>CCaptcha::checkRequirements()); return $rules; }
public function actionEditAvatar() { $model = YumUser::model()->findByPk(Yii::app()->user->id); if (isset($_POST['YumUser'])) { $model->attributes = $_POST['YumUser']; $model->setScenario('avatarUpload'); if (Yum::module('avatar')->avatarMaxWidth != 0) { $model->setScenario('avatarSizeCheck'); } $model->avatar = CUploadedFile::getInstanceByName('YumUser[avatar]'); if ($model->validate()) { if ($model->avatar instanceof CUploadedFile) { // Prepend the id of the user to avoid filename conflicts $filename = Yum::module('avatar')->avatarPath . '/' . $model->id . '_' . $_FILES['YumUser']['name']['avatar']; $model->avatar->saveAs($filename); $model->avatar = $filename; if ($model->save()) { Yum::setFlash(Yum::t('The image was uploaded successfully')); Yum::log(Yum::t('User {username} uploaded avatar image {filename}', array('{username}' => $model->username, '{filename}' => $model->avatar))); $this->redirect(array('//profile/profile/view')); } } } } $this->render('edit_avatar', array('model' => $model)); }
public function actionLeave($id = null) { if ($id !== null) { $p = YumUsergroup::model()->findByPk($id); $participants = $p->participants; if (!in_array(Yii::app()->user->id, $participants)) { Yum::setFlash(Yum::t('You are not participating in this group')); } else { $participants = $p->participants; foreach ($participants as $key => $participant) { if ($participant == Yii::app()->user->id) { unset($participants[$key]); } } $p->participants = $participants; if ($p->save(array('participants'))) { Yum::setFlash(Yum::t('You have left this group')); Yum::log(Yum::t('User {username} left group id {id}', array('{username}' => Yii::app()->user->data()->username, '{id}' => $id))); } } $this->redirect(array('//usergroup/groups/index')); } else { throw new CHttpException(404); } }
public function beforeAction($action) { if (Yum::module()->enableOnlineStatus && !Yii::app()->user->isGuest) { Yii::app()->user->data()->setLastAction(); } return parent::beforeAction($action); }
public function beforeControllerAction($controller, $action) { if (!Yum::hasModule('role')) { throw new Exception('Using the membership submodule requires the role module activated'); } return parent::beforeControllerAction($controller, $action); }
public function init() { if ($this->title === NULL) { $this->title = Yum::t('Login'); } parent::init(); }
public static function itemAlias($type,$code=NULL) { $_items = array( 'field_type' => array( 'INTEGER' => Yum::t('INTEGER'), 'VARCHAR' => Yum::t( 'VARCHAR'), 'TEXT'=> Yum::t( 'TEXT'), 'DATE'=> Yum::t( 'DATE'), 'DROPDOWNLIST' => Yum::t('DROPDOWNLIST'), 'FLOAT'=> Yum::t('FLOAT'), 'BOOL'=> Yum::t('BOOL'), 'BLOB'=> Yum::t('BLOB'), 'BINARY'=> Yum::t('BINARY'), 'FILE'=> 'FILE', ), 'required' => array( '0' => Yum::t('No'), '1' => Yum::t('Yes'), ), 'visible' => array( self::VISIBLE_USER_DECISION => Yum::t('Let the user choose in privacy settings'), self::VISIBLE_PUBLIC => Yum::t('For all'), self::VISIBLE_REGISTER_USER => Yum::t('Registered users'), self::VISIBLE_ONLY_OWNER => Yum::t('Only owner'), self::VISIBLE_HIDDEN => Yum::t('Hidden'), ), ); if (isset($code)) return isset($_items[$type][$code]) ? $_items[$type][$code] : false; else return isset($_items[$type]) ? $_items[$type] : false; }
/** * Adds the CAdvancedArBehavior and, if enabled, the LoggableBehavior to * every YUM Active Record model * @return array */ public function behaviors() { $behaviors = array('CAdvancedArBehavior'); if (Yum::module()->enableAuditTrail) { $behaviors = array_merge($behaviors, array('LoggableBehavior' => 'application.modules.auditTrail.behaviors.LoggableBehavior')); } return $behaviors; }
public function init() { $this->title = Yum::t('Profile Comments'); if (Yii::app()->user->isGuest) { return false; } parent::init(); }
public function createRandomPassword() { $lowercase = Yum::module()->passwordRequirements['minLowerCase']; $uppercase = Yum::module()->passwordRequirements['minUpperCase']; $minnumbers = Yum::module()->passwordRequirements['minDigits']; $max = Yum::module()->passwordRequirements['maxLen']; $chars = "abcdefghijkmnopqrstuvwxyz"; $numbers = "1023456789"; srand((double) microtime() * 1000000); $i = 0; $current_lc = 0; $current_uc = 0; $current_dd = 0; $password = ''; while ($i <= $max) { if ($current_lc < $lowercase) { $charnum = rand() % 22; $tmpchar = substr($chars, $charnum, 1); $password = $password . $tmpchar; $i++; } if ($current_uc < $uppercase) { $charnum = rand() % 22; $tmpchar = substr($chars, $charnum, 1); $password = $password . strtoupper($tmpchar); $i++; } if ($current_dd < $minnumbers) { $charnum = rand() % 9; $tmpchar = substr($numbers, $charnum, 1); $password = $password . $tmpchar; $i++; } if ($current_lc == $lowercase && $current_uc == $uppercase && $current_dd == $numbers && $i < $max) { $charnum = rand() % 22; $tmpchar = substr($chars, $charnum, 1); $password = $password . $tmpchar; $i++; if ($i < $max) { $charnum = rand() % 9; $tmpchar = substr($numbers, $charnum, 1); $password = $password . $tmpchar; $i++; } if ($i < $max) { $charnum = rand() % 22; $tmpchar = substr($chars, $charnum, 1); $password = $password . strtoupper($tmpchar); $i++; } } } return $password; }
public function beforeAction($event) { if (Yii::app()->user->isAdmin()) { $this->layout = Yum::module('userproject')->adminLayout; } else { $this->layout = Yum::module('userproject')->layout; } return parent::beforeAction($event); }
public function attributeLabels() { return array( 'id' => Yum::t('ID'), 'user_id' => Yum::t('Written from'), 'profile_id' => Yum::t('Profile'), 'comment' => Yum::t('Comment'), 'createtime' => Yum::t('Written at'), ); }
protected function renderContent() { if (Yum::module('message')->messageSystem === false) { return false; } if (!Yii::app()->user->isGuest) { $messages = YumMessage::model()->unread()->limit(10)->findAll(); $this->render('messages', array('messages' => $messages)); } }
public function actionDelete($id) { $comment = YumProfileComment::model()->findByPk($id); if ($comment->user_id == Yii::app()->user->id || $comment->profile_id == Yii::app()->user->id) { $comment->delete(); $this->redirect(array(Yum::module('profile')->profileView, 'id' => $comment->profile->user_id)); } else { throw new CHttpException(403, Yum::t('You are not the owner of this Comment or this Profile!')); } }
public function attributeLabels() { return array( 'id' => Yum::t('group id'), 'title' => Yum::t('Group title'), 'description' => Yum::t('Description'), 'participants' => Yum::t('Participants'), 'owner_id' => Yum::t('Group owner'), ); }
public function beforeAction($action) { if (Yum::module()->enableOnlineStatus && !Yii::app()->user->isGuest) { Yii::app()->user->data()->setLastAction(); } if (Yum::module()->enableBootstrap) { Yum::register('css/bootstrap.min.css'); } return parent::beforeAction($action); }
public function actionAdmin() { $this->layout = Yum::module()->adminLayout; $model = new YumAction('search'); $model->unsetAttributes(); if (isset($_GET['YumAction'])) { $model->attributes = $_GET['YumAction']; } $this->render('admin', array('model' => $model)); }
public function attributeLabels() { return array( 'id' => Yum::t('id'), 'timestamp' => Yum::t('timestamp'), 'user_id' => Yum::t('User'), 'action' => Yum::t('Action'), 'remote_addr' => Yum::t('Connected from IP'), 'http_user_agent' => Yum::t('Used browser(HTTP_USER_AGENT)'), ); }
public function attributeLabels() { return array( 'id' => Yum::t('ID'), 'author_id' => Yum::t('Author'), 'group_id' => Yum::t('Group'), 'createtime' => Yum::t('Createtime'), 'title' => Yum::t('Title'), 'message' => Yum::t('Message'), ); }
protected function renderContent() { if (!Yum::module('profile')->enableProfileVisitLogging) { return false; } parent::renderContent(); if (Yii::app()->user->isGuest) { return false; } $this->render('profile_visits', array('visits' => Yii::app()->user->data()->visits)); }
public function actionDelete() { $this->layout = Yum::module()->adminLayout; if (Yii::app()->request->isPostRequest) { $this->loadModel()->delete(); if (!isset($_POST['ajax'])) { $this->redirect(array('index')); } } else { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } }
public function search() { $criteria = new CDbCriteria(); $criteria->compare('principal_id', $this->principal_id); $criteria->compare('subordinate_id', $this->subordinate_id); $criteria->compare('type', $this->type, true); $criteria->compare('template', $this->template); $criteria->compare('comment', $this->comment, true); $criteria->compare('action', $this->action); $criteria->compare('subaction', $this->subaction); return new CActiveDataProvider(get_class($this), array('criteria' => $criteria, 'pagination' => array('pageSize' => Yum::module()->pageSize))); }
public function attributeLabels() { return array( 'id'=>Yum::t("#"), 'title'=>Yum::t("Title"), 'description'=>Yum::t("Description"), 'selectable'=>Yum::t("Selectable on registration"), 'searchable'=>Yum::t("Searchable"), 'price'=>Yum::t("Price"), 'duration'=>Yum::t("Duration in days"), ); }
public function sendRegistrationEmail($user, $password) { if (!isset($user->profile->email)) { throw new CException(Yum::t('Email is not set when trying to send Registration Email')); } $activation_url = $user->getActivationUrl(); if (is_object($content)) { $body = strtr('Hi, {email}, your new password is {password}. Please activate your account by clicking this link: {activation_url}', array('{email}' => $user->profile->email, '{password}' => $password, '{activation_url}' => $activation_url)); $mail = array('from' => Yum::module('registration')->registrationEmail, 'to' => $user->profile->email, 'subject' => 'Your registration on my example Website', 'body' => $body); $sent = YumMailer::send($mail); } return $sent; }
public function attributeLabels() { return array( 'id' => Yum::t( 'ID'), 'language' => Yum::t( 'Language'), 'text_email_registration' => Yum::t( 'Text Email Registration'), 'subject_email_registration' => Yum::t( 'Subject of Email Registration'), 'text_email_recovery' => Yum::t( 'Text Email Recovery'), 'text_email_activation' => Yum::t( 'Text Email Activation'), 'text_friendship_new' => Yum::t( 'Text for new friendship request'), 'text_profilecomment_new' => Yum::t( 'Text for new profile comment'), ); }
public function actionCsv($file, $delimiter = ', ', $enclosure = '"', $escape = '\\', $roles = '') { if (!Yii::app()->db) { throw new CException('No database configured'); } if (!in_array('user', Yii::app()->db->schema->tableNames)) { throw new CException('No table "user" found; is yum installed?'); } if (!$file) { throw new CException('No file given'); } $data = file_get_contents($file); Yum::import($data, $delimiter, $enclosure, $escape, $roles); }
public function rules() { $rules = parent::rules(); if (!(Yum::hasModule('registration') && Yum::module('registration')->registration_by_email)) { $rules[] = array('username', 'required'); } $rules[] = array('newsletter, terms,type_id', 'safe'); // password requirement is already checked in YumUser model, its sufficient // to check for verifyPassword here $rules[] = array('verifyPassword', 'required'); $rules[] = array('password', 'compare', 'compareAttribute' => 'verifyPassword', 'message' => Yum::t("Retype password is incorrect.")); if (Yum::module('registration')->enableCaptcha && !Yum::module()->debug) { $rules[] = array('verifyCode', 'captcha', 'allowEmpty' => CCaptcha::checkRequirements()); } return $rules; }
public function actionJoin($id = null) { if ($id !== null) { $p = YumUsergroup::model()->findByPk($id); $participants = $p->participants; if (in_array(Yii::app()->user->id, $participants)) { Yum::setFlash(Yum::t('You are already participating in this group')); } else { $participants[] = Yii::app()->user->id; $p->participants = $participants; if ($p->save(array('participants'))) { Yum::setFlash(Yum::t('You have joined this group')); Yum::log(Yum::t('User {username} joined group id {id}', array('{username}' => Yii::app()->user->data()->username, '{id}' => $id))); } } $this->redirect(array('//usergroup/groups/view', 'id' => $id)); } }
public function actionExport() { if (isset($_POST['profile_fields'])) { $fields = ''; foreach ($_POST['profile_fields'] as $field) { $fields .= $field . ','; } $fields = substr($fields, 0, -1); Yii::import('application.modules.user.components.CSVExport'); $sql = sprintf('select %s from profiles where %s', $fields, Yum::module()->customCsvExportCriteria); $result = Yii::app()->db->createCommand($sql)->queryAll(); $csv = new CSVExport($result); $content = $csv->toCSV(); $filename = Yii::app()->basePath . '/runtime/yum_user_export.csv'; $content = $csv->toCSV($filename, ",", "\""); Yii::app()->getRequest()->sendFile(basename($filename), @file_get_contents($filename), "text/csv", false); exit; } }