public function actionUpdate($id = null) { if (!$id) { $id = Yii::app()->user->id; } $user = $this->loadModel($id); $profile = $user->profile; if (isset($_POST['YumUser']) || isset($_POST['YumProfile'])) { $user->attributes = @$_POST['YumUser']; $profile->attributes = @$_POST['YumProfile']; $profile->user_id = $user->id; $profile->validate(); $user->validate(); if (!$user->hasErrors() && !$profile->hasErrors()) { if ($user->save() && $profile->save()) { Yum::setFlash('Your changes have been saved'); $this->redirect(array('//profile/profile/view', 'id' => $user->id)); } } } if (Yii::app()->request->isAjaxRequest) { $this->renderPartial(Yum::module('profile')->profileEditView, array('user' => $user, 'profile' => $profile)); } else { $this->render(Yum::module('profile')->profileEditView, array('user' => $user, 'profile' => $profile)); } }
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 actionDelete() { $permission = YumPermission::model()->findByPk($_GET['id']); if ($permission->delete()) { Yum::setFlash(Yum::t('The permission has been removed')); } else { Yum::setFlash(Yum::t('Error while removing the permission')); } $this->redirect(array('//role/permission/admin')); }
public function actionExtend() { $membership = YumMembership::model()->findByPk($_POST['membership_id']); if (!$membership) { throw new CHttpException(404); } if ($membership->user_id != Yii::app()->user->id) { throw new CHttpException(403); } $subscription = $_POST['subscription']; $membership->subscribed = $subscription == 'cancel' ? -1 : $subscription; $membership->save(false, array('subscribed')); Yum::setFlash('Your subscription setting has been saved'); $this->redirect(Yum::module('membership')->membershipIndexRoute); }
public function actionInvite($user_id = null) { if (isset($_POST['user_id'])) { $user_id = $_POST['user_id']; } if ($user_id == null) { return false; } if (isset($_POST['message']) && isset($user_id)) { $friendship = new YumFriendship(); if ($friendship->requestFriendship(Yii::app()->user->id, $_POST['user_id'], $_POST['message'])) { Yum::setFlash('The friendship request has been sent'); $this->redirect(array('//profile/profile/view', 'id' => $user_id)); } } $this->render('invitation', array('inviter' => YumUser::model()->findByPk(Yii::app()->user->id), 'invited' => YumUser::model()->findByPk($user_id), 'friendship' => isset($friendship) ? $friendship : null)); }
public function actionRegistration() { Yii::import('application.modules.profile.models.*'); $profile = new YumProfile(); if (isset($_POST['Profile'])) { $profile->attributes = $_POST['YumProfile']; if ($profile->save()) { $user = new YumUser(); } $password = YumUser::generatePassword(); // we generate a dummy username here, since yum requires one $user->register(md5($profile->email), $password, $profile); $this->sendRegistrationEmail($user, $password); Yum::setFlash('Thank you for your registration. Please check your email.'); $this->redirect(Yum::module()->loginUrl); } $this->render('/registration/registration', array('profile' => $profile)); }
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 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 actionSubscribeToNewsLetter() { $zipcode = $_POST['zipcode']; $email = $_POST['email']; // check if email already exists in the database $subscObj = Newslettersubscribers::model()->find('email =:email', array(':email' => $email)); if ($subscObj) { Yum::setFlash(Yum::t('Email already added in subscriber list')); $this->redirect(Yum::module()->loginUrl); } $newsSubcModel = new Newslettersubscribers(); $newsSubcModel->setAttribute('zipcode', $zipcode); $newsSubcModel->setAttribute('email', $email); $newsSubobj = $newsSubcModel->save(); if ($newsSubobj) { Yum::setFlash(Yum::t('Your email has been added to the subscriber list')); } else { Yum::setFlash(Yum::t('Error: please try again later')); } $this->redirect(Yum::module()->loginUrl); }
public function actionUpdate() { $model = YumPrivacySetting::model()->findByPk(Yii::app()->user->id); if (isset($_POST['YumPrivacysetting'])) { $model->attributes = $_POST['YumPrivacysetting']; $profile_privacy = 0; foreach ($_POST as $key => $value) { if ($value == 1 && substr($key, 0, 18) == 'privacy_for_field_') { $data = explode('_', $key); $data = (int) $data[3]; $profile_privacy += $data; } } $model->public_profile_fields = $profile_privacy; $model->validate(); if (isset($_POST['YumProfile'])) { $profile = $model->user->profile; $profile->attributes = $_POST['YumProfile']; $profile->validate(); } if (!$model->hasErrors()) { $profile->save(); $model->save(); Yum::setFlash('Your privacy settings have been saved'); $this->redirect(array('//profile/profile/view', 'id' => $model->user_id)); } } // If the user does not have a privacy setting entry yet, create an // empty one if (!$model) { $model = new YumPrivacySetting(); $model->user_id = Yii::app()->user->id; $model->save(); $this->refresh(); } $this->render(Yum::module('profile')->privacySettingView, array('model' => $model, 'profile' => isset($model->user) && isset($model->user->profile) ? $model->user->profile : null)); }
public function actionUpdate($category = null, $message = null, $language = null) { $models = array(); foreach (Yum::getAvailableLanguages() as $language) { $models[] = $this->loadModel($category, $message, $language); } if (isset($_POST['YumTranslation'])) { $category = $_POST['YumTranslation']['category']; $message = $_POST['YumTranslation']['message']; foreach ($_POST as $key => $translation) { if (substr($key, 0, 11) == 'translation') { $lang = explode('_', $key); if (isset($lang[1])) { $lang = $lang[1]; foreach (Yum::getAvailableLanguages() as $language) { if ($language == $lang) { $model = YumTranslation::model()->find('category = :category and message = :message and language = :language ', array(':category' => $category, ':message' => $message, ':language' => $lang)); if (!$model) { $model = new YumTranslation(); } if ($translation != '') { $model->message = $message; $model->category = $category; $model->translation = $translation; $model->language = $lang; $model->save(); } } } } } } Yum::setFlash('Translations have been saved'); $this->redirect(array('admin')); } $this->render('update', array('models' => $models)); }
/** * Password recovery routine. The User will receive an email with an * activation link. If clicked, he will be prompted to enter his new * password. */ public function actionRecovery($email = null, $key = null) { $form = new YumPasswordRecoveryForm(); if ($email != null && $key != null) { if ($profile = YumProfile::model()->find('email = :email', array('email' => $email))) { $user = $profile->user; if ($user->status <= 0) { throw new CHttpException(403, 'User is not active'); } else { if ($user->activationKey == urldecode($key)) { $passwordform = new YumUserChangePassword(); if (isset($_POST['YumUserChangePassword'])) { $passwordform->attributes = $_POST['YumUserChangePassword']; if ($passwordform->validate()) { $user->setPassword($passwordform->password); $user->activationKey = CPasswordHelper::hashPassword(microtime() . $passwordform->password, Yum::module()->passwordHashCost); $user->save(); Yum::setFlash('Your new password has been saved.'); if (Yum::module('registration')->loginAfterSuccessfulRecovery) { $login = new YumUserIdentity($user->username, false); $login->authenticate(true); Yii::app()->user->login($login); $this->redirect(Yii::app()->homeUrl); } else { $this->redirect(Yum::module()->loginUrl); } } } $this->render(Yum::module('registration')->changePasswordView, array('form' => $passwordform)); Yii::app()->end(); } else { $form->addError('login_or_email', Yum::t('Invalid recovery key')); Yum::log(Yum::t('Someone tried to recover a password, but entered a wrong recovery key. Email is {email}, associated user is {username} (id: {uid})', array('{email}' => $email, '{uid}' => $user->id, '{username}' => $user->username))); } } } } else { if (isset($_POST['YumPasswordRecoveryForm'])) { $form->attributes = $_POST['YumPasswordRecoveryForm']; if ($form->validate()) { if ($form->user instanceof YumUser) { if ($form->user->status <= 0) { throw new CHttpException(403, 'User is not active'); } $form->user->generateActivationKey(); $recovery_url = $this->createAbsoluteUrl(Yum::module('registration')->recoveryUrl[0], array('key' => urlencode($form->user->activationKey), 'email' => $form->user->profile->email)); Yum::log(Yum::t('{username} successfully requested a new password in the password recovery form. A email with the password recovery url {recovery_url} has been sent to {email}', array('{email}' => $form->user->profile->email, '{recovery_url}' => $recovery_url, '{username}' => $form->user->username))); $mail = array('from' => Yii::app()->params['adminEmail'], 'to' => $form->user->profile->email, 'subject' => 'You requested a new password', 'body' => strtr('You have requested a new password. Please use this URL to continue: {recovery_url}', array('{recovery_url}' => $recovery_url))); $sent = YumMailer::send($mail); Yum::setFlash('Instructions have been sent to you. Please check your email.'); } else { Yum::log(Yum::t('A password has been requested, but no associated user was found in the database. Requested user/email is: {username}', array('{username}' => $form->login_or_email))); } $this->redirect(Yum::module()->loginUrl); } } } $this->render(Yum::module('registration')->recoverPasswordView, array('form' => $form)); }
public function actionuploadDocuments() { if (!empty(Yii::app()->user->_data)) { $userId = Yii::app()->user->_data->id; } // getting project Id $projectId = Yii::app()->request->getPost('project_id'); if (isset($_POST['YumUserdocuments']) && isset($_POST['YumUserdocuments']['name'])) { $model = new YumUserdocuments(); $model->attributes = $_POST['YumUserdocuments']; $model->name = CUploadedFile::getInstanceByName('YumUserdocuments[name]'); if ($model->name instanceof CUploadedFile) { // $userId =5; // Prepend the id of the user to avoid filename conflicts $fileName = $_FILES['YumUserdocuments']['name']['name']; $filePath = Yum::module('userdocuments')->documentPath . '/' . $userId . '_' . $_FILES['YumUserdocuments']['name']['name']; $model->name->saveAs($filePath); $attrArr = array('name' => $fileName, 'path' => $filePath, 'created_by' => $userId); $model->attributes = $attrArr; if ($model->save(false)) { if ($projectId) { $userProjectDocuments = new YumUserdocumentsprojects(); $attrArrProject = array('project_id' => $projectId, 'userdocuments_id' => $model['userdocuments_id'], 'created_by' => $userId); $userProjectDocuments->attributes = $attrArrProject; if ($userProjectDocuments->save()) { Yum::setFlash(Yum::t('The Document was uploaded successfully')); $this->redirect(array('//userproject/userproject/projectdetails?project_id=' . $projectId)); } } Yum::setFlash(Yum::t('The Document was uploaded successfully')); $this->redirect(array('//userdocuments/userdocuments/index')); } } } }
/** * Password recovery routine. The User will receive an email with an * activation link. If clicked, he will be prompted to enter his new * password. */ public function actionRecovery($email = null, $key = null) { $form = new YumPasswordRecoveryForm; if ($email != null && $key != null) { if($profile = YumProfile::model()->find('email = :email', array( 'email' => $email))) { $user = $profile->user; if($user->activationKey == $key) { $passwordform = new YumUserChangePassword; if (isset($_POST['YumUserChangePassword'])) { $passwordform->attributes = $_POST['YumUserChangePassword']; if ($passwordform->validate()) { $user->password = YumUser::encrypt($passwordform->password); $user->activationKey = YumUser::encrypt(microtime() . $passwordform->password); $user->save(); Yum::setFlash('Your new password has been saved.'); $this->redirect(Yum::module()->loginUrl); } } $this->render( Yum::module('registration')->changePasswordView, array( 'form' => $passwordform)); Yii::app()->end(); } else { $form->addError('login_or_email', Yum::t('Invalid recovery key')); Yum::log(Yum::t( 'Someone tried to recover a password, but entered a wrong recovery key. Email is {email}, associated user is {username} (id: {uid})', array( '{email}' => $email, '{uid}' => $user->id, '{username}' => $user->username))); } } } else { if (isset($_POST['YumPasswordRecoveryForm'])) { $form->attributes = $_POST['YumPasswordRecoveryForm']; if ($form->validate()) { Yum::setFlash( 'Instructions have been sent to you. Please check your email.'); if($form->user instanceof YumUser) { $form->user->generateActivationKey(); $recovery_url = $this->createAbsoluteUrl( Yum::module('registration')->recoveryUrl[0], array( 'key' => $form->user->activationKey, 'email' => $form->user->profile->email)); Yum::log(Yum::t( '{username} successfully requested a new password in the password recovery form. A email with the password recovery url {recovery_url} has been sent to {email}', array( '{email}' => $form->user->profile->email, '{recovery_url}' => $recovery_url, '{username}' => $form->user->username))); $content = YumTextSettings::model()->find( 'language = :lang', array('lang' => Yii::app()->language)); $sent = null; if (is_object($content)) { $mail = array( 'from' => Yii::app()->params['adminEmail'], 'to' => $form->user->profile->email, 'subject' => $content->subject_email_registration, 'body' => strtr($content->text_email_recovery, array( '{recovery_url}' => $recovery_url)), ); $sent = YumMailer::send($mail); } else { throw new CException(Yum::t('The messages for your application language are not defined.')); } } else Yum::log(Yum::t( 'A password has been requested, but no associated user was found in the database. Requested user/email is: {username}', array( '{username}' => $form->login_or_email))); $this->redirect(Yum::module()->loginUrl); } } } $this->render(Yum::module('registration')->recoverPasswordView, array( 'form' => $form)); }
/** * Deletes a user */ public function actionDelete($id = null) { if(!$id) $id = Yii::app()->user->id; $user = YumUser::model()->findByPk($id); if(Yii::app()->user->isAdmin()) { //This is necesary for handling human stupidity. if($user && ($user->id == Yii::app()->user->id)) { Yum::setFlash('You can not delete your own admin account'); $this->redirect(array('//user/user/admin')); } if($user->delete()) { Yum::setFlash('The User has been deleted'); $this->redirect('user/user/admin'); } } else if(isset($_POST['confirmPassword'])) { if($user->encrypt($_POST['confirmPassword']) == $user->password) { if($user->delete()) $this->actionLogout(); else Yum::setFlash('Error while deleting Account. Account was not deleted'); } else { Yum::setFlash('Wrong password confirmation! Account was not deleted'); } $this->redirect(array('//profile/profile/view')); } $this->render('confirmDeletion', array('model' => $user)); }
public function actionAddComment() { /*echo "<pre>"; print_r($_POST); exit;*/ $comment = Yii::app()->request->getPost('comment'); $userId = Yii::app()->request->getPost('userId'); $parentId = Yii::app()->request->getPost('parentId'); $createdFor = Yii::app()->request->getPost('created_for'); if (!isset($parentId)) { $parentId = NULL; } $userComentsModel = new YumUsercomments(); $commentsArr = array('comment' => $comment, 'created_for' => $createdFor, 'created_by' => $userId, 'parent_id' => $parentId); $userComentsModel->attributes = $commentsArr; $userCommentobj = $userComentsModel->save(); if ($userCommentobj) { Yum::setFlash(Yum::t('Comment added successfully')); $this->redirect(array('//usercomments/usercomments/index', 'id' => $createdFor)); } else { Yum::setFlash(Yum::t('Unable to add comment')); } if ($userId) { $this->renderCommentsList(); return; /*$commentModel = new YumUsercomments(); $comentsObj = $commentModel->with('usercommentslikes')->findAll('t.created_by =:created_by', array(':created_by' => $userId)); if($comentsObj) { $this->render('index',array( 'comments'=>$comentsObj, )); // $this->render(Yum::module('usercomments')->index, array( // 'comments'=>$comentsObj, // )); return; }*/ } $this->redirect($this->createUrl('//usercomments/usercomments/index')); }
/** * Deletes a user by setting the status to 'deleted' */ public function actionDelete($id = null) { if (!$id) { $id = Yii::app()->user->id; } $user = YumUser::model()->findByPk($id); if (Yii::app()->user->isAdmin()) { //This is necesary for handling human stupidity. if ($user && $user->id == Yii::app()->user->id) { Yum::setFlash('You can not delete your own admin account'); $this->redirect(array('//user/user/admin')); } if ($user->delete()) { Yum::setFlash('The User has been deleted'); if (!Yii::app()->request->isAjaxRequest) { $this->redirect('//user/user/admin'); } } } else { if (isset($_POST['confirmPassword'])) { if (CPasswordHelper::verifyPassword($_POST['confirmPassword'], $user->password)) { if ($user->delete()) { Yii::app()->user->logout(); $this->actionLogout(); } else { Yum::setFlash('Error while deleting Account. Account was not deleted'); } } else { Yum::setFlash('Wrong password confirmation! Account was not deleted'); } $this->redirect(Yum::module()->deleteUrl); } } $this->render('confirmDeletion', array('model' => $user)); }
public function authenticate($user) { $identity = new YumUserIdentity($user->username, $this->loginForm->password); $identity->authenticate(); switch ($identity->errorCode) { case YumUserIdentity::ERROR_EMAIL_INVALID || YumUserIdentity::ERROR_PASSWORD_INVALID: $this->loginForm->addError("password", Yum::t('Username or Password is incorrect')); $this->logFailedLoginAttempts($user); break; case YumUserIdentity::ERROR_STATUS_INACTIVE: $this->loginForm->addError("status", Yum::t('This account is not activated.')); break; case YumUserIdentity::ERROR_STATUS_BANNED: $this->loginForm->addError("status", Yum::t('This account is blocked.')); break; case YumUserIdentity::ERROR_STATUS_REMOVED: $this->loginForm->addError('status', Yum::t('Your account has been deleted.')); break; case YumUserIdentity::ERROR_NONE: $duration = $this->loginForm->rememberMe ? Yum::module()->cookieDuration : 0; Yii::app()->user->login($identity, $duration); if ($user->failedloginattempts > 0) { Yum::setFlash(Yum::t('Warning: there have been {count} failed login attempts', array('{count}' => $user->failedloginattempts))); $user->failedloginattempts = 0; $user->save(false, array('failedloginattempts')); } return $user; break; } }