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)); }
protected function renderContent() { parent::renderContent(); if (Yii::app()->user->isGuest) { return false; } $user = YumUser::model()->findByPk(Yii::app()->user->id); $this->render('profile_comments', array('comments' => Yii::app()->user->data()->profile->recentComments())); }
public function checkexists($attribute, $params) { $user = null; // we only want to authenticate when there are no input errors so far if (!$this->hasErrors()) { if (strpos($this->login_or_email, "@")) { $profile = YumProfile::model()->findByAttributes(array('email' => $this->login_or_email)); $this->user = $profile && $profile->user && $profile->user instanceof YumUser ? $profile->user : null; } else { $this->user = YumUser::model()->findByAttributes(array('username' => $this->login_or_email)); } } }
public function loadModel($id = null) { if (!$id) { $id = Yii::app()->user->id; } if (is_numeric($id)) { return $this->_model = YumUser::model()->findByPk($id); } else { if (is_string($id)) { return $this->_model = YumUser::model()->find("username = '******'"); } } }
public function isPublic($user = null) { if($user == null) $user = Yii::app()->user->id; if(!$this->visible) return false; if($privacy = YumUser::model()->findByPk($user)->privacy) { if($privacy->public_profile_fields & pow(2, $this->id)) return true; } return false; }
public function getPublicFields() { if (!Yum::module('profile')->enablePrivacySetting) { return false; } $fields = array(); if ($privacy = @YumUser::model()->cache(500)->with('privacy')->findByPk($this->user_id)->privacy->public_profile_fields) { $i = 1; foreach (YumProfileField::model()->cache(500)->findAll() as $field) { if ($i & $privacy && $field->visible != 0) { $fields[] = $field; } $i *= 2; } } return $fields; }
public function actionCreate() { $this->layout = Yum::module()->adminLayout; $model = new YumRole(); $this->performAjaxValidation($model, 'yum-role-form'); if (isset($_POST['YumRole'])) { $model->attributes = $_POST['YumRole']; if ($model->save()) { if (Yum::module()->enableLogging == true) { $user = YumUser::model()->findbyPK(Yii::app()->user->id); Yum::log(Yum::t('The role {role} has been created by {username}', array('{role}' => $model->title, '{username}' => Yii::app()->user->data()->username))); } $this->redirect(array('admin')); } } $this->render('create', array('model' => $model)); }
public function actionCompose($to_user_id = null, $answer_to = 0) { $model = new YumMessage(); $this->performAjaxValidation('YumMessage', 'yum-message-form'); if (isset($_POST['YumMessage'])) { $model->attributes = $_POST['YumMessage']; $model->from_user_id = Yii::app()->user->id; $model->validate(); if (!$model->hasErrors()) { $model->save(); Yum::setFlash(Yum::t('Message "{message}" has been sent to {to}', array('{message}' => $model->title, '{to}' => YumUser::model()->findByPk($model->to_user_id)->username))); $this->redirect(Yum::module('message')->inboxRoute); } } $fct = 'render'; if (Yii::app()->request->isAjaxRequest) { $fct = 'renderPartial'; } $this->{$fct}('compose', array('model' => $model, 'to_user_id' => $to_user_id, 'answer_to' => $answer_to)); }
public function authenticate($without_password = false) { $user = YumUser::model()->find('username = :username', array(':username' => $this->username)); // try to authenticate via email if (Yum::hasModule('profile') && Yum::module()->loginType & UserModule::LOGIN_BY_EMAIL && !$user) { if ($profile = YumProfile::model()->find('email = :email', array(':email' => $this->username))) { if ($profile->user) { $user = $profile->user; } } } if (!$user) { return self::ERROR_STATUS_USER_DOES_NOT_EXIST; } if ($user->status == YumUser::STATUS_INACTIVE) { $this->errorCode = self::ERROR_STATUS_INACTIVE; } else { if ($user->status == YumUser::STATUS_BANNED) { $this->errorCode = self::ERROR_STATUS_BANNED; } else { if ($user->status == YumUser::STATUS_REMOVED) { $this->errorCode = self::ERROR_STATUS_REMOVED; } else { if ($without_password) { $this->credentialsConfirmed($user); } else { if (!CPasswordHelper::verifyPassword($this->password, $user->password)) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { $this->credentialsConfirmed($user); } } } } } return !$this->errorCode; }
public static function write($to, $from, $subject, $body, $mail = true) { $message = new YumMessage(); if (!$mail) { $message->omit_mail = true; } if (is_object($from)) { $message->from_user_id = (int) $from->id; } else { if (is_numeric($from)) { $message->from_user_id = $from; } else { if (is_string($from) && ($user = YumUser::model()->find("username = '******'"))) { $message->from_user_id = $user->id; } else { return false; } } } if (is_object($to)) { $message->to_user_id = (int) $to->id; } else { if (is_numeric($to)) { $message->to_user_id = $to; } else { if (is_string($to) && ($user = YumUser::model()->find("username = '******'"))) { $message->to_user_id = $user->id; } else { return false; } } } $message->title = $subject; $message->message = $body; return $message->save(); }
public function beforeSave() { $this->updatetime = time(); // If the user has activated email receiving, send a email if ($this->isNewRecord) { if ($user = YumUser::model()->findByPk($this->friend_id)) { if (Yum::hasModule('messages') && $user->privacy && $user->privacy->message_new_friendship) { Yii::import('application.modules.messages.models.YumMessage'); YumMessage::write($user, $this->inviter, Yum::t('New friendship request from {username}', array('{username}' => $this->inviter->username)), YumTextSettings::getText('text_friendship_new', array('{username}' => $this->inviter->username, '{link_friends}' => Yii::app()->controller->createUrl('//friendship/friendship/index'), '{link_profile}' => Yii::app()->controller->createUrl('//profile/profile/view'), '{message}' => $this->message))); } } } return parent::beforeSave(); }
private function _checkAuth() { foreach (array('HTTP_X_USERNAME', 'PHP_AUTH_USER') as $var) { if (isset($_SERVER[$var]) && $_SERVER[$var] != '') { $username = $_SERVER[$var]; } } foreach (array('HTTP_X_PASSWORD', 'PHP_AUTH_PW') as $var) { if (isset($_SERVER[$var]) && $_SERVER[$var] != '') { $password = $_SERVER[$var]; } } if ($username && $password) { $user = YumUser::model()->find('LOWER(username)=?', array(strtolower($username))); if (Yum::module()->RESTfulCleartextPasswords && $user !== null && $user->superuser && md5($password) == $user->password) { return true; } if (!Yum::module()->RESTfulCleartextPasswords && $user !== null && $user->superuser && $password == $user->password) { return true; } } $this->_sendResponse(401, 'Error: Username or password is invalid'); }
public function loginsToday() { $day = $this->getStartOfDay(time()); return YumUser::model()->count('lastvisit > :begin and lastvisit < :end', array(':begin' => $day, ':end' => $day + 86400)); }
/** * Return admins. * @return array syperusers names */ public static function getAdmins() { $admins = YumUser::model()->active()->superuser()->findAll(); $returnarray = array(); foreach ($admins as $admin) { array_push($returnarray, $admin->username); } return $returnarray; }
public function actionLogout() { // If the user is already logged out send them to returnLogoutUrl if (Yii::app()->user->isGuest) { $this->redirect(Yum::module()->returnLogoutUrl); } // let's delete the login_type cookie $cookie = Yii::app()->request->cookies['login_type']; if ($cookie) { $cookie->expire = time() - Yum::module()->cookieDuration; Yii::app()->request->cookies['login_type'] = $cookie; } if ($user = YumUser::model()->findByPk(Yii::app()->user->id)) { $user->logout(); Yum::log(Yum::t('User {username} logged off', array('{username}' => $user->username))); Yii::app()->user->logout(); } $this->redirect(Yum::module()->returnLogoutUrl); }
public function actionLogout() { // If the user is already logged out send them to returnLogoutUrl if (Yii::app()->user->isGuest) { $this->redirect(Yum::module()->returnLogoutUrl); } //let's delete the login_type cookie $cookie = Yii::app()->request->cookies['login_type']; if ($cookie) { $cookie->expire = time() - 3600 * 72; Yii::app()->request->cookies['login_type'] = $cookie; } if ($user = YumUser::model()->findByPk(Yii::app()->user->id)) { $username = $user->username; $user->logout(); if (Yii::app()->user->name == 'facebook') { if (!Yum::module()->loginType & UserModule::LOGIN_BY_FACEBOOK) { throw new Exception('actionLogout for Facebook was called, but is not activated in main.php'); } Yii::import('application.modules.user.vendors.facebook.*'); require_once 'Facebook.php'; $facebook = new Facebook(Yum::module()->facebookConfig); $fb_cookie = 'fbs_' . Yum::module()->facebookConfig['appId']; $cookie = Yii::app()->request->cookies[$fb_cookie]; if ($cookie) { $cookie->expire = time() - 1 * (3600 * 72); Yii::app()->request->cookies[$cookie->name] = $cookie; $servername = '.' . Yii::app()->request->serverName; setcookie("{$fb_cookie}", "", time() - 3600); setcookie("{$fb_cookie}", "", time() - 3600, "/", "{$servername}", 1); } $session = $facebook->getSession(); Yum::log('Facebook logout from user ' . $username); Yii::app()->user->logout(); $this->redirect($facebook->getLogoutUrl(array('next' => $this->createAbsoluteUrl(Yum::module()->returnLogoutUrl), 'session_key' => $session['session_key']))); } else { Yum::log(Yum::t('User {username} logged off', array('{username}' => $username))); Yii::app()->user->logout(); } } $this->redirect(Yum::module()->returnLogoutUrl); }
<?php $form = $this->beginWidget('CActiveForm', array('id' => 'yum-message-form', 'action' => array('//message/message/compose'), 'enableAjaxValidation' => true)); ?> <br> <br> <i> <?php //echo Yum::requiredFieldNote(); echo CHtml::hiddenField('YumMessage[to_user_id]', $to_user_id); echo CHtml::hiddenField('YumMessage[answered]', $answer_to); echo Yum::t('This message will be sent to {username}', array('{username}' => YumUser::model()->findByPk($to_user_id)->username)); ?> </i> <br> <br> <div class="row"> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> <?php echo $form->textField($model, 'title', array('size' => 45, 'maxlength' => 45, 'class' => 'form-control')); ?> <?php echo $form->error($model, 'title'); ?> </div> </div> <br> <div class="row"> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> <?php echo $form->textArea($model, 'message', array('rows' => 6, 'cols' => 50, 'class' => 'form-control'));
/** * Loads the User Object instance * @return YumUser */ public function loadUser($uid = 0) { if($this->_model === null) { if($uid != 0) $this->_model = YumUser::model()->findByPk($uid); elseif(isset($_GET['id'])) $this->_model = YumUser::model()->findByPk($_GET['id']); if($this->_model === null) throw new CHttpException(404,'The requested User does not exist.'); } return $this->_model; }
/** * Checks if the user has the given Role * @mixed Role string or array of strings that should be checked * @int (optional) id of the user that should be checked * @return bool Return value tells if the User has access or hasn't access. */ public function hasRole($role, $uid = 0) { if(Yum::hasModule('role')) { Yii::import('application.modules.role.models.*'); if($uid == 0) $uid = Yii::app()->user->id; if(!is_array($role)) $role = array ($role); if($uid && $user = YumUser::model()->cache(500)->with('roles')->find( 't.id = '.$uid)) { // Check if a user has a active membership and, if so, add this // to the roles $roles = $user->roles; if(Yum::hasModule('membership')) $roles = array_merge($roles, $user->getActiveMemberships()); if(isset($roles)) foreach($roles as $roleobj) { if(in_array($roleobj->title, $role) || in_array($roleobj->id, $role)) return true; } } } return false; }
<div class="row white "> <div class="pipline_title"> <h1><span class="fa fa fa-envelope-o"></span> Message</h1> <!-- <h4><a href="<?php //echo Yii::app()->createAbsoluteUrl('/message/message/compose/'); ?> ">Compose a new Message</a></h4>--> </div> <div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 pipline"> <?php if (!empty($messageObj)) { foreach ($messageObj as $obj) { $messageId = $obj->id; $fromUserId = $obj->from_user_id; $condition = 'id = :id'; $userData = YumUser::model()->find($condition, array(':id' => $fromUserId)); $avatar = $userData['avatar']; // echo $avatar; ?> <div class="row"> <a id="p<?php echo $messageId; ?> " href="#"> <div class="col-xs-4 col-sm-8 col-md-4 col-lg-3 "> <img class="img-responsive img-circle" src="<?php echo Yii::app()->request->baseUrl; ?> /<?php echo $avatar; ?>
<div class="answer"> <?php $img_down="<img src='../../../../images/site/vote-down.png'>";?> <?php $img_up="<img src='../../../../images/site/vote-up.png'>";?> <?php foreach($answer as $ans): ?> <div class="ans-row"> <div class="ans-user"> <?php $user=YumUser::model()->findByPk($ans->owner); echo $user->getAvatar(); echo "<br>"; echo $user->username; ?> </div> <div class="ans-content" > <?php echo html_entity_decode($ans->content)?> <br/> <span id="ans-upvote-<?php echo "$ans->id";?>" style="color:green;"><?php echo $ans->up_vote;?></span><span> <?php echo CHtml::ajaxLink ($img_up,Yii::app()->createUrl('answer/upvote/id/'.$ans->id), array('type' =>'POST', 'data'=> CJSON::encode($ans->id), 'update'=>'#ans-upvote-'.$ans->id));?> </span> <span id="ans-downvote-<?php echo"$ans->id"; ?>" style="color:red;"><?php echo $ans->down_vote;?></span><span> <?php echo CHtml::ajaxLink ($img_down,Yii::app()->createUrl('answer/downvote/id/'.$ans->id), array('type' =>'POST', 'data'=> CJSON::encode($ans->id), 'update'=>'#ans-downvote-'.$ans->id));?> </span> </div>
public static function import($data, $delimiter = ',', $enclosure = '"', $escape = '\\', $roles = '') { if (!$data) { throw new CException('No data given'); } $rows = explode("\n", $data); $firstrow = str_getcsv($rows[0], $delimiter, $enclosure, $escape); $attributes = array(); $i = 0; foreach ($firstrow as $row) { $attributes[$i] = $row; $i++; } unset($rows[0]); foreach ($rows as $row) { $values = str_getcsv($row, $delimiter, $enclosure, $escape); $user = YumUser::model()->findByPk($values[0]); // Update existing User if ($user) { $profile = $user->profile; foreach ($attributes as $key => $attribute) { if (isset($user->{$attribute}) && isset($values[$key])) { $user->{$attribute} = htmlentities($values[$key], ENT_IGNORE, 'utf-8', FALSE); } else { if (isset($profile->{$attribute}) && isset($values[$key])) { $profile->{$attribute} = htmlentities($values[$key], ENT_IGNORE, 'utf-8', FALSE); } } } $user->save(false); if ($profile instanceof YumProfile) { $profile->save(false); } if ($roles) { foreach (explode(',', $roles) as $role) { $user->assignRole(trim($role)); } } } else { if (!$user) { // Create new User $user = new YumUser(); $profile = new YumProfile(); foreach ($attributes as $key => $attribute) { if (isset($user->{$attribute}) && isset($values[$key])) { $user->{$attribute} = htmlentities($values[$key], ENT_IGNORE, 'utf-8', FALSE); } else { if (isset($profile->{$attribute}) && isset($values[$key])) { $profile->{$attribute} = htmlentities($values[$key], ENT_IGNORE, 'utf-8', FALSE); } } } $user->id = $values[0]; if (!$user->username && $profile->email) { $user->username = $profile->email; } if (!$user->status) { $user->status = 1; } $user->createtime = time(); if ($user->username) { $user->save(false); $profile->user_id = $user->id; $profile->save(false); } } } } }
$this->breadcrumbs=array( 'Questions'=>array('index'), $model->title, ); $this->menu=array( array('label'=>'List Question', 'url'=>array('index')), array('label'=>'Create Question', 'url'=>array('create')), array('label'=>'Update Question', 'url'=>array('update', 'id'=>$model->id)), array('label'=>'Delete Question', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Are you sure you want to delete this item?')), array('label'=>'Manage Question', 'url'=>array('admin')), ); ?> <h1><?php echo $model->title; ?></h1> <?php $qowner=YumUser::model()->findByPk($model->owner);?> <div class="question-view" style="width:700px;"> <div class="question-header-wrapper" style="height:20px;"> <div id="question-vote" style="float:left;"> <span id="question-vote-number"><?php echo $qowner->getAvatar(); echo "<br>"; echo $qowner->username; ?> </div> <div class="question-user-time" style="float:center;"><span class="question-owner"><?php echo "posted by ".$qowner->username." on ".$model->create_date;?> </span></div> </div> <div><?php echo html_entity_decode($model->content);?></div>
public static function invitationLink($inviter, $invited) { if ($inviter === $invited) { return false; } if (!is_object($inviter)) { $inviter = YumUser::model()->findByPk($inviter); } if (!is_object($invited)) { $invited = YumUser::model()->findByPk($invited); } $friends = $inviter->getFriends(true); if ($friends && $friends[0] != NULL) { foreach ($friends as $friend) { if ($friend->id == $invited->id) { return false; } } } // already friends, rejected or request pending return CHtml::link(Yum::t('Add as a friend'), array('//friendship/friendship/invite', 'user_id' => $invited->id)); }
public function beforeSave() { $this->updatetime = time(); // If the user has activated email receiving, send a email if ($this->isNewRecord) { if ($user = YumUser::model()->findByPk($this->friend_id)) { if (Yum::hasModule('message') && $user->privacy && $user->privacy->message_new_friendship) { Yii::import('user.message.models.YumMessage'); YumMessage::write($user, $this->inviter, Yum::t('New friendship request from {username}', array('{username}' => $this->inviter->username)), strtr('A new friendship request from {username} has been made: {message} <a href="{link_friends}">Manage my friends</a><br /><a href="{link_profile}">To the profile</a>', array('{username}' => $this->inviter->username, '{link_friends}' => Yii::app()->controller->createUrl('//friendship/friendship/index'), '{link_profile}' => Yii::app()->controller->createUrl('//profile/profile/view'), '{message}' => $this->message))); } } } return parent::beforeSave(); }
public function authenticate($without_password = false) { $user = YumUser::model()->find('username = :username', array( ':username' => $this->username)); // try to authenticate via email if(!$user && (Yum::module()->loginType & 2) && Yum::hasModule('profile')) { if($profile = YumProfile::model()->find('email = :email', array( ':email' => $this->username))) if($profile->user) $user = $profile->user; } if(!$user) return self::ERROR_STATUS_USER_DOES_NOT_EXIST; if($without_password) $this->credentialsConfirmed($user); else if(YumUser::encrypt($this->password)!==$user->password) $this->errorCode=self::ERROR_PASSWORD_INVALID; else if($user->status == YumUser::STATUS_INACTIVE) $this->errorCode=self::ERROR_STATUS_INACTIVE; else if($user->status == YumUser::STATUS_BANNED) $this->errorCode=self::ERROR_STATUS_BANNED; else if($user->status == YumUser::STATUS_REMOVED) $this->errorCode=self::ERROR_STATUS_REMOVED; else $this->credentialsConfirmed($user); return !$this->errorCode; }
<?php if (isset($actions)) { foreach ($actions as $action) { printf('<h2>%s</h2>', $action->title); echo Yum::t('The following users have permission to perform the action {action}:', array('{action}' => $action->title)); if ($action->permissions) { foreach ($action->permissions as $permission) { echo '<ul>'; if ($permission->type == 'user') { $user = YumUser::model()->findByPk($permission->principal_id); printf('<li>%s</li>', CHtml::link($user->username, array('/user/view', 'id' => $user->id))); } if ($permission->type == 'role') { $role = YumRole::model()->findByPk($permission->principal_id); printf('<li>role %s</li>', CHtml::link($role->title, array('/role/view', 'id' => $role->id))); } echo '</ul>'; } } } } else { echo Yum::t('No user has permission'); } ?>
?> <div class="row-fluid"> <div class="span5 loginform"> <p> <?php echo Yum::t('Please fill out the following form with your login credentials:'); ?> </p> <?php printf('<label for="YumUserLogin_username">%s: <span class="required">*</span></label>', Yum::t('Login as')); ?> <?php echo CHtml::activeDropDownList($model, 'username', CHtml::listData(YumUser::model()->findAll('status > 0'), 'username', 'username')); printf('<p class="hint">%s</p>', Yum::t('No password necessary since debug mode is active')); ?> </div> </div> <?php if (Yum::module()->loginType & UserModule::LOGIN_BY_HYBRIDAUTH && Yum::module()->hybridAuthProviders) { ?> <div class="row-fluid"> <div class="span5 hybridauth"> <?php echo Yum::t('You can also login by') . ': <br />'; foreach (Yum::module()->hybridAuthProviders as $provider) { echo CHtml::link(CHtml::image(Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('user.assets.images') . '/' . strtolower($provider) . '.png'), $provider) . $provider, $this->createUrl('//user/auth/login', array('hybridauth' => $provider)), array('class' => 'social')) . '<br />'; }
<?php $user = YumUser::model()->findByPk(Yii::app()->user->id); if ($user->friendship_requests) { $this->beginWidget('zii.widgets.CPortlet', array('title' => Yum::t('New friendship requests'))); foreach ($user->friendship_requests as $friendship) { printf('<li> %s: %s </li>', date(Yum::module()->dateTimeFormat, $friendship->requesttime), CHtml::link($friendship->inviter->username, array('//profile/profile/view', 'id' => $friendship->inviter->id))); } echo CHtml::link(Yum::t('Manage friends'), array('//friendship/friendship/admin')); $this->endWidget(); } ?>