Example #1
0
 /**
  * 权限验证
  */
 public function checkRestAuth()
 {
     if (!isset($_SERVER['HTTP_WEXKEY']) || !isset($_SERVER['HTTP_WEXTOKEN'])) {
         // Error: Unauthorized
         $this->sendResponse(401, 'No Token');
     }
     $wexkey = $_SERVER['HTTP_WEXKEY'];
     $wextoken = $_SERVER['HTTP_WEXTOKEN'];
     $wexuser = null;
     $salt = 'restyougouwxg1qw23er4';
     $token;
     $suffix = ' by user request ';
     if (isset($_SERVER['HTTP_WEXUSER'])) {
         $wexuser = $_SERVER['HTTP_WEXUSER'];
         $token = md5($wexkey . $salt . $wexuser);
     } else {
         $today = date("Ymd");
         $token = md5($wexkey . $salt . $today);
         $suffix = ' by normal request ';
     }
     if ($wextoken != $token) {
         $this->sendResponse(401, 'Token is invalid' . $suffix);
         Yii::app()->end();
     }
     if ($wexuser != null) {
         $user = User::model()->findByPk($wexuser);
         if ($user == null || $user->archived == 0) {
             $this->sendResponse(403, 'User Token is invalid');
             Yii::app()->end();
         }
         return $user;
     } else {
         return null;
     }
 }
Example #2
0
	/**
	 * Authenticates a user.
	 * The example implementation makes sure if the username and password
	 * are both 'demo'.
	 * In practical applications, this should be changed to authenticate
	 * against some persistent user identity storage (e.g. database).
	 * @return boolean whether authentication succeeds.
	 */
	public function authenticate()
	{
		if (strpos($this->username,"@")) {
			$user=User::model()->notsafe()->findByAttributes(array('email'=>$this->username));
		} else {
			$user=User::model()->notsafe()->findByAttributes(array('username'=>$this->username));
		}
		if($user===null)
			if (strpos($this->username,"@")) {
				$this->errorCode=self::ERROR_EMAIL_INVALID;
			} else {
				$this->errorCode=self::ERROR_USERNAME_INVALID;
			}
		else if(Y::module('users')->encrypting($this->password)!==$user->password)
			$this->errorCode=self::ERROR_PASSWORD_INVALID;
		else if($user->status==0&&Y::module('users')->loginNotActiv==false)
			$this->errorCode=self::ERROR_STATUS_NOTACTIV;
		else if($user->status==-1)
			$this->errorCode=self::ERROR_STATUS_BAN;
		else {
			$this->_id=$user->id;
			$this->username=$user->username;
			$this->errorCode=self::ERROR_NONE;
		}
		return !$this->errorCode;
	}
 /** 
  * Edit a karma record
  */
 public function actionEdit()
 {
     $_POST = Yii::app()->input->stripClean($_POST);
     $id = (int) Yii::app()->request->getQuery('id');
     $user = User::model()->resetScope()->findByPk($id);
     $karma = Karma::model()->resetScope()->findByPk($id);
     if ($karma == null) {
         throw new CHttpException(404, "Karma record not found!");
     }
     // Build Form Definition
     $definition = array();
     $definition['elements'] = array();
     $groupModels = Group::model()->findAll(array('order' => 'name'));
     // Define Form Eleements
     $definition['elements']['Karma'] = array('type' => 'form', 'title' => 'Karma', 'elements' => array('name' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'points' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 10), 'description' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 1000)));
     // Get Form Definition
     $definition['buttons'] = array('save' => array('type' => 'submit', 'label' => 'Save', 'class' => 'btn btn-primary'), 'delete' => array('type' => 'submit', 'label' => 'Delete', 'class' => 'btn btn-danger'));
     $form = new HForm($definition);
     $form['Karma']->model = $karma;
     if ($form->submitted('save') && $form->validate()) {
         $this->forcePostRequest();
         if ($form['Karma']->model->save()) {
             $this->redirect($this->createUrl('edit', array('id' => $karma->id)));
             return;
         }
     }
     if ($form->submitted('delete')) {
         $this->redirect(Yii::app()->createUrl('karma/admin/delete', array('id' => $user->id)));
     }
     $this->render('edit', array('form' => $form));
 }
Example #4
0
 public function authenticate()
 {
     $user = User::model()->findByAttributes(array('username' => $this->username));
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         // check Auto or Not
         $password = $this->autoLogin == false ? MSecure::password($this->username . $this->password . $user->registered) : $this->password;
         if ($user->password !== $password) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->_id = $user->id;
             if ($user->lastvisited === NULL) {
                 $lastLogin = new CDbExpression('NOW()');
             } else {
                 $lastLogin = $user->lastvisited;
             }
             // RBAC
             $roles = CJSON::decode($user->role);
             $auth = Yii::app()->authManager;
             foreach ($roles as $role) {
                 if (!$auth->isAssigned($role, $this->_id)) {
                     if ($auth->assign($role, $this->_id)) {
                         Yii::app()->authManager->save();
                     }
                 }
             }
             $this->setState('email', $user->email);
             $this->setState('lastvisited', $lastLogin);
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return !$this->errorCode;
 }
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionView($id)
 {
     $model = $this->loadModel($id);
     $propose_by = User::model()->findByPk($model->propose_by_user_id);
     $promentor = User::model()->findByPk($model->project_mentor_user_id);
     $this->renderPartial('view', array('model' => $this->loadModel($id), 'promentor' => $promentor, 'propose_by' => $propose_by));
 }
 /**
  * Authenticates a user.
  * The example implementation makes sure if the username and password
  * are both 'demo'.
  * In practical applications, this should be changed to authenticate
  * against some persistent user identity storage (e.g. database).
  * @return boolean whether authentication succeeds.
  */
 public function authenticate($md5 = true)
 {
     $user = User::model()->find('LOWER(username)=?', array(strtolower($this->username)));
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (($md5 ? md5($this->password) : $this->password) !== $user->password) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             if ($user->banned == User::BANNED_YES) {
                 $this->errorCode = self::ERROR_BANNED;
             } else {
                 if ($user->confirmRegistration) {
                     $this->errorCode = self::ERROR_CONFIRMREGISTRATION;
                 } else {
                     $this->_id = $user->id;
                     $this->setState('username', $user->username);
                     $this->setState('password', $user->password);
                     $this->setState('email', $user->email);
                     $this->setState('status', $user->status);
                     $this->setState('lastlogin', $user->lastlogin);
                     $this->errorCode = self::ERROR_NONE;
                 }
             }
         }
     }
     return !$this->errorCode;
 }
Example #7
0
 /**
  * Create a DB user
  *
  * @return unknown_type
  */
 public function createNewUser()
 {
     // Do nothing if the user to be added is not DB type
     if (flattenText(Yii::app()->request->getPost('user_type')) != 'DB') {
         return;
     }
     $oEvent = $this->getEvent();
     $new_user = flattenText(Yii::app()->request->getPost('new_user'), false, true);
     $new_email = flattenText(Yii::app()->request->getPost('new_email'), false, true);
     if (!validateEmailAddress($new_email)) {
         $oEvent->set('errorCode', self::ERROR_INVALID_EMAIL);
         $oEvent->set('errorMessageTitle', gT("Failed to add user"));
         $oEvent->set('errorMessageBody', gT("The email address is not valid."));
         return;
     }
     $new_full_name = flattenText(Yii::app()->request->getPost('new_full_name'), false, true);
     $new_pass = createPassword();
     $iNewUID = User::model()->insertUser($new_user, $new_pass, $new_full_name, Yii::app()->session['loginID'], $new_email);
     if (!$iNewUID) {
         $oEvent->set('errorCode', self::ERROR_ALREADY_EXISTING_USER);
         $oEvent->set('errorMessageTitle', '');
         $oEvent->set('errorMessageBody', gT("Failed to add user"));
         return;
     }
     Permission::model()->setGlobalPermission($iNewUID, 'auth_db');
     $oEvent->set('newUserID', $iNewUID);
     $oEvent->set('newPassword', $new_pass);
     $oEvent->set('newEmail', $new_email);
     $oEvent->set('newFullName', $new_full_name);
     $oEvent->set('errorCode', self::ERROR_NONE);
 }
Example #8
0
 public function actionAssignAllMembers($args)
 {
     if (!isset($args[0])) {
         print "Error: Space guid parameter required!\n\n";
         print $this->getHelp();
         return;
     }
     $space = Space::model()->findByAttributes(array('guid' => $args[0]));
     if ($space == null) {
         print "Error: Space not found! Check guid!\n\n";
         return;
     }
     $countMembers = 0;
     $countAssigns = 0;
     foreach (User::model()->findAllByAttributes(array('status' => User::STATUS_ENABLED)) as $user) {
         if ($space->isMember($user->id)) {
             #print "Already Member!";
             $countMembers++;
         } else {
             print "Add member " . $user->displayName . "\n";
             Yii::app()->user->setId($user->id);
             $space->addMember($user->id);
             $countAssigns++;
         }
     }
     print "\nAdded " . $countAssigns . " new members to space " . $space->name . "\n";
 }
Example #9
0
 public function run($code)
 {
     if (Yii::app()->request->isAjaxRequest) {
         $user = User::model()->findByAttributes(array('id' => Yii::app()->user->id));
         $result = Coding::isValidCode($code);
         $hasused = Coding::hasUsedCode($code);
         if ($result['code'] == 200 && $user->status >= 3 && !$hasused) {
             $code = Code::model()->findByAttributes(array('code' => $code));
             $code->times--;
             $code->save();
             $codeused = new CodeUsed();
             $codeused->codeId = $code->id;
             $codeused->userId = Yii::app()->user->id;
             $codeused->createTime = date('YmdHis');
             $codeused->save();
             $user->status = 4;
             $user->save();
             $ccode = new CCode();
             $result = $ccode->getproduct($code->code);
             echo CJSON::encode(array('code' => 200, 'mes' => 'success', 'data' => $result['data']));
         } else {
             echo CJSON::encode(array('code' => 500, 'mes' => 'fail'));
         }
     }
 }
 public function actionDelete($id)
 {
     $user = User::model()->findByPk($id);
     $user->group = 1;
     $user->update();
     $this->redirect(Yii::app()->request->getUrlReferrer());
 }
Example #11
0
 /**
  * Run method for EMailing System
  *
  * @param type $args
  */
 public function run($args)
 {
     $this->printHeader('E-Mail Interface');
     if (!isset($args[0]) || $args[0] != "daily" && $args[0] != 'hourly') {
         print "\n Run with parameter:\n" . "\t daily - for Daily Mailings\n" . "\t hourly - for Hourly Mailings\n";
         print "\n\n";
         exit;
     }
     $this->mode = $args[0];
     Yii::import("application.modules_core.wall.*", true);
     $users = User::model()->with('httpSessions')->findAllByAttributes(array('status' => User::STATUS_ENABLED));
     foreach ($users as $user) {
         print "Processing : " . $user->email . ": ";
         $notificationContent = $this->getNotificationContent($user);
         $activityContent = $this->getActivityContent($user);
         // Something new?
         if ($notificationContent == "" && $activityContent == "") {
             print "Nothing new! \n";
             continue;
         }
         $message = new HMailMessage();
         $message->view = 'application.views.mail.EMailing';
         $message->addFrom(HSetting::Get('systemEmailAddress', 'mailing'), HSetting::Get('systemEmailName', 'mailing'));
         $message->addTo($user->email);
         if ($this->mode == 'hourly') {
             $message->subject = Yii::t('base', "Latest news");
         } else {
             $message->subject = Yii::t('base', "Your daily summary");
         }
         $message->setBody(array('notificationContent' => $notificationContent, 'activityContent' => $activityContent, 'user' => $user), 'text/html');
         Yii::app()->mail->send($message);
         print "Sent! \n";
     }
     print "\nEMailing completed.\n";
 }
 /**
  * Update permission
  */
 public function actionUpdate($id)
 {
     // Check Access
     checkAccessThrowException('op_permission_update');
     $model = AuthItem::model()->findByPk($id);
     if ($model) {
         if (isset($_POST['AuthItem'])) {
             $old_name = $model->name;
             $model->setAttributes($_POST['AuthItem']);
             if ($model->save()) {
                 // Update parent name and child name in the auth child table
                 AuthItemChild::model()->updateAll(array('parent' => $model->name), 'parent=:name', array(':name' => $old_name));
                 AuthItemChild::model()->updateAll(array('child' => $model->name), 'child=:name', array(':name' => $old_name));
                 AuthAssignment::model()->updateAll(array('bizrule' => $model->bizrule, 'data' => $model->data, 'itemname' => $model->name), 'itemname=:name', array(':name' => $old_name));
                 User::model()->updateAll(array('role' => $model->name), 'role=:name', array(':name' => $old_name));
                 fok(at('Permission Updated!'));
                 // Log Message
                 alog(at("Updated permission: '{name}'.", array('{name}' => $model->name)));
                 $this->redirect(array('index'));
             }
         }
         // Add Breadcrumb
         $this->addBreadCrumb(at('Update Permission'));
         $this->title[] = at('Update Permission');
         $this->render('form', array('model' => $model));
     } else {
         throw new CHttpException(404, at('Sorry, That record was not found.'));
     }
 }
 protected function renderContent()
 {
     if (!user()->isGuest) {
         $model = new UserChangePassForm();
         // if it is ajax validation request
         if (isset($_POST['ajax']) && $_POST['ajax'] === 'userchangepass-form') {
             echo CActiveForm::validate($model);
             Yii::app()->end();
         }
         // collect user input data
         if (isset($_POST['UserChangePassForm'])) {
             $model->attributes = $_POST['UserChangePassForm'];
             // validate user input password
             if ($model->validate()) {
                 $u = User::model()->findbyPk(user()->id);
                 if ($u !== null) {
                     $u->password = PassHash::hash($model->new_password_1);
                     if ($u->save()) {
                         user()->setFlash('success', t('cms', 'Changed Password Successfully!'));
                     }
                 }
                 $model = new UserChangePassForm();
             }
         }
         $this->render('cmswidgets.views.user.user_change_pass_widget', array('model' => $model));
     } else {
         Yii::app()->request->redirect(user()->returnUrl);
     }
 }
 /**
  * Duplicated from the admin controller to give a user list
  *
  * (there's also a method on the UserController that could be used, so would be worth consolidating)
  */
 public function actionUserFind()
 {
     $res = array();
     if (\Yii::app()->request->isAjaxRequest && !empty($_REQUEST['search'])) {
         $criteria = new \CDbCriteria();
         $criteria->compare("LOWER(username)", strtolower($_REQUEST['search']), true, 'OR');
         $criteria->compare("LOWER(first_name)", strtolower($_REQUEST['search']), true, 'OR');
         $criteria->compare("LOWER(last_name)", strtolower($_REQUEST['search']), true, 'OR');
         $words = explode(" ", $_REQUEST['search']);
         if (count($words) > 1) {
             // possibly slightly verbose approach to checking first and last name combinations
             // for searches
             $first_criteria = new \CDbCriteria();
             $first_criteria->compare("LOWER(first_name)", strtolower($words[0]), true);
             $first_criteria->compare("LOWER(last_name)", strtolower(implode(" ", array_slice($words, 1, count($words) - 1))), true);
             $last_criteria = new \CDbCriteria();
             $last_criteria->compare("LOWER(first_name)", strtolower($words[count($words) - 1]), true);
             $last_criteria->compare("LOWER(last_name)", strtolower(implode(" ", array_slice($words, 0, count($words) - 2))), true);
             $first_criteria->mergeWith($last_criteria, 'OR');
             $criteria->mergeWith($first_criteria, 'OR');
         }
         foreach (\User::model()->findAll($criteria) as $user) {
             $res[] = array('id' => $user->id, 'label' => $user->getFullNameAndTitle(), 'value' => $user->getFullName(), 'username' => $user->username);
         }
     }
     echo \CJSON::encode($res);
 }
Example #15
0
 /**
  * Authenticates a user.
  * The example implementation makes sure if the username and password
  * are both 'demo'.
  * In practical applications, this should be changed to authenticate
  * against some persistent user identity storage (e.g. database).
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     /* $users=array(
     			// username => password
     			'demo'=>'demo',
     			'admin'=>'admin',
     		);
     		if(!isset($users[$this->username]))
     			$this->errorCode=self::ERROR_USERNAME_INVALID;
     		elseif($users[$this->username]!==$this->password)
     			$this->errorCode=self::ERROR_PASSWORD_INVALID;
     		else
     			$this->errorCode=self::ERROR_NONE;
     		return !$this->errorCode; */
     $record = User::model()->findByAttributes(array('email' => $this->username));
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($this->password != $record->password) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->_id = $record->id;
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return !$this->errorCode;
 }
Example #16
0
 public function validateClue($param, $options)
 {
     if ($this->type == "user") {
         $this->foundBuddy = User::model()->byLogin($this->{$param})->find();
         if (!$this->foundBuddy) {
             $this->addError("clue", "Пользователь с таким логином не найден.");
             return;
         } elseif ($this->foundBuddy->can(User::CAN_LOGIN)) {
             $this->addError("clue", "Пользователь {$this->buddy->ahref} уже является членом клуба.");
             return;
         } else {
             $this->to_id = $this->foundBuddy->id;
             $this->to_email = $this->foundBuddy->email;
         }
     } elseif ($this->type == "new") {
         $this->foundBuddy = User::model()->findByAttributes(["email" => $this->{$param}]);
         $this->to_email = $this->{$param};
         if ($this->foundBuddy) {
             if ($this->foundBuddy->can(User::CAN_LOGIN)) {
                 $this->addError("clue", "Этот пользователь уже зарегистрирован на Нотабеноиде и является членом клуба.");
                 return;
             } else {
                 $this->to_id = $this->foundBuddy->id;
             }
         }
     } else {
         $this->addError("type", "Ошибка формы");
     }
     // Проверяем, не приглашали ли мы его уже ранее
     $i = Yii::app()->db->createCommand("SELECT 1 FROM reg_invites WHERE from_id = :from_id AND to_id = :to_id")->queryScalar(["from_id" => $this->from_id, "to_id" => $this->foundBuddy->id]);
     if ($i) {
         $this->addError("clue", "Вы уже приглашали этого пользователя.");
         return;
     }
 }
Example #17
0
 public function actionRemove($instagram_id = 0)
 {
     $user = User::model()->findByPk(Yii::app()->user->id);
     $user_child_id = User::instagramIdToId($instagram_id);
     UserChild::model()->deleteAll('user_id=:user_id AND user_child_id=:user_child_id', array(':user_child_id' => $user_child_id, ':user_id' => $user->id));
     $this->redirect('/user/account');
 }
Example #18
0
 /**
  * Authenticates a user.
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     $u = User::model()->findByAttributes(array('username' => $this->username));
     if (!$u) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (!$u->matchesPassword($this->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             if ($u->status == UserStatus::STATUS_PENDING) {
                 $this->errorCode = self::ERROR_STATUS_PENDING;
             } else {
                 $this->_id = $u->user_id;
                 if ($u->type == UserType::TYPE_ADVERTISER) {
                     $this->_advertiserId = $this->getAdvertiserIdForUser($u->user_id);
                     if ($this->_advertiserId == null) {
                         $this->errorCode = self::ERROR_ADVERTISER_NOT_FOUND;
                         return !$this->errorCode;
                     }
                 } else {
                     if ($u->type == UserType::TYPE_MEDIABROKER) {
                         $this->_mediabrokerId = $this->getMediabrokerIdForUser($u->user_id);
                         if ($this->_mediabrokerId == null) {
                             $this->errorCode = self::ERROR_MEDIABROKER_NOT_FOUND;
                             return !$this->errorCode;
                         }
                     }
                 }
                 $this->errorCode = self::ERROR_NONE;
             }
         }
     }
     return !$this->errorCode;
 }
Example #19
0
 public function actionBuyApi($item_id, $num)
 {
     $itemList = Util::loadConfig('items');
     $item = $itemList[$item_id];
     if (isset($item)) {
         $user = User::model()->findByPk($this->usr_id);
         if ($user->gold - $item['price'] * $num < 0) {
             throw new PException('余额不足');
         } else {
             $transaction = Yii::app()->db->beginTransaction();
             try {
                 $user->gold -= $item['price'] * $num;
                 $items = unserialize($user->items);
                 if (isset($items[$item_id])) {
                     $items[$item_id] += $num;
                 } else {
                     $items[$item_id] = $num;
                 }
                 $user->items = serialize($items);
                 $user->saveAttributes(array('gold', 'items'));
                 $transaction->commit();
             } catch (Exception $e) {
                 $transaction->rollback();
                 throw $e;
             }
             $this->echoJsonData(array('user_gold' => $user->gold));
         }
     } else {
         throw new PException('商品不存在');
     }
 }
Example #20
0
 /**
  * Authenticates a user.
  * The example implementation makes sure if the username and password
  * are both 'demo'.
  * In practical applications, this should be changed to authenticate
  * against some persistent user identity storage (e.g. database).
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     $session = $this->_facebook->getSession();
     Yii::trace($session, "session");
     $me = null;
     if ($session) {
         try {
             $me = $this->_facebook->api('/me');
             Yii::trace($me, "me");
         } catch (FacebookApiException $e) {
             error_log($e);
         }
         if (!$me) {
             $this->errorCode = self::ERROR_FB_NOT_SIGNIN;
         } else {
             $fb_uid = $this->_facebook->getUser();
             $user = User::model()->find("fb_uid=:fb_uid", array(':fb_uid' => $fb_uid));
             if ($user === null) {
                 $user = new User();
                 $user->name = $me['name'];
                 $user->fb_uid = $fb_uid;
                 $user->reg_time = new CDbExpression('NOW()');
             }
             $user->last_login_time = new CDbExpression('NOW()');
             $user->save();
             $this->_id = $user->id;
             $this->_name = $user->name;
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return !$this->errorCode;
 }
Example #21
0
 public function add($user_follow, $user_followed, $type)
 {
     $check = Relationship::model()->findAllByAttributes(array('user_id_1' => $user_follow, 'user_id_2' => $user_followed));
     $check_2 = Relationship::model()->findAllByAttributes(array('user_id_2' => $user_follow, 'user_id_1' => $user_followed));
     $check_3 = Follow::model()->findByAttributes(array('user_follow' => $user_follow, 'user_followed' => $user_followed));
     if ($check || $check_2 || $check_3 || $user_followed == Yii::app()->session['user_id']) {
         return FALSE;
     }
     $model = new Follow();
     $model->user_follow = $user_follow;
     $model->user_followed = $user_followed;
     $model->created_at = time();
     $model->update_at = time();
     $model->type = $type;
     $user_follow_data = User::model()->findByPk($user_follow);
     $user_followed_data = User::model()->findByPk($user_followed);
     if ($user_follow != Yii::app()->session['user_id']) {
         $arr_noti = array('user_id' => $user_follow, 'content' => "{$user_follow_data->username} vừa theo dõi bạn", 'type' => 'follow', 'recipient_id' => $user_followed_data->id, 'url' => Yii::app()->createAbsoulteUrl('user/profile', array('user_id' => $user_follow_data->id, 'ref' => 'noti')));
         Notifications::model()->add($arr_noti);
     }
     if ($model->save(FALSE)) {
         return TRUE;
     }
     return FALSE;
 }
Example #22
0
 private function getModel()
 {
     if (!$this->isGuest && $this->_model === null) {
         $this->_model = User::model()->findByPk($this->id, array('select' => 'role_id'));
     }
     return $this->_model;
 }
Example #23
0
 /**
  * @return CActiveRecord
  */
 protected function getModel()
 {
     if (!$this->isGuest && $this->_model === null) {
         $this->_model = User::model()->findByPk($this->id);
     }
     return $this->_model;
 }
Example #24
0
 public static function getModel()
 {
     if (!isset(self::$_model)) {
         self::$_model = User::model()->findByPk(Yii::app()->user->id);
     }
     return self::$_model;
 }
 public function actionIndex($email, $spam_id, $key)
 {
     /** @var User $user */
     $user = User::model()->findByAttributes(array('email' => $email));
     /** @var Spam $spam */
     $spam = Spam::model()->findByPk($spam_id);
     if (!$user || !$spam || $key != $spam->getUnsubscribeHash($user)) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $unsubscribed = false;
     $spam_type_id = $spam->type_enum;
     foreach ($user->userUnsubscribes as $unsubscribe) {
         if ($unsubscribe->spam_type_id == $spam_type_id) {
             $unsubscribed = true;
         }
     }
     if (!$unsubscribed) {
         $userUnsubscribe = new UserUnsubscribe();
         $userUnsubscribe->spam_type_id = $spam_type_id;
         $userUnsubscribe->user_id = $user->id;
         if ($userUnsubscribe->save()) {
             $unsubscribed = true;
         } else {
             throw new CException('unsubscribe error:' . var_export($userUnsubscribe->errors, true));
         }
     }
     $this->render('/user/unsubscribe', array('user' => $user, 'spam' => $spam, 'unsubscribed' => $unsubscribed));
 }
 /**
  * Verify Old Password
  */
 public function verifyOldPassword($attribute, $params)
 {
     $password = User::model()->notsafe()->findByPk(Yii::app()->user->id)->password;
     if ($password != Yii::app()->getModule('user')->encrypting($this->{$attribute}, $password)) {
         $this->addError($attribute, UserModule::t("Old Password is incorrect."));
     }
 }
 public function checkEmail($attribute, $params)
 {
     $model = User::model()->find('email = :email', array(':email' => $this->{$attribute}));
     if ($model) {
         $this->addError('email', Yii::t('UserModule.user', 'Email already busy'));
     }
 }
Example #28
0
 /**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function authenticate($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $this->_identity = new UserIdentity($this->username, $this->password);
         $this->_identity->authenticate();
         switch ($this->_identity->errorCode) {
             case UserIdentity::ERROR_NONE:
                 $org = Organisation::model()->findByAttributes(array('id' => $this->organisation_id));
                 $user = User::model()->findByAttributes(array('organisation_id' => $this->organisation_id, 'name' => $this->username));
                 Yii::app()->user->setState("org_name", $org['name']);
                 Yii::app()->user->setState("org_id", $org['id']);
                 Yii::app()->user->setState("user_name", $this->username);
                 Yii::app()->user->setState("user_id", $user['id']);
                 $user->last_login = date('Y-m-d');
                 $user->update();
                 //MyUtility::UpdateStatusOfConsumables($user['id']);
                 break;
             case UserIdentity::ERROR_USERNAME_INVALID:
                 $this->addError('username', 'Invalid USERNAME.');
                 break;
             case UserIdentity::ERROR_PASSWORD_INVALID:
                 $this->addError('password', 'Invalid PASSWORD.');
                 break;
         }
     }
 }
Example #29
0
 public function getModel()
 {
     if ($this->_model === null) {
         $this->_model = User::model()->find(array('condition' => 'id_user = :USER_ID', 'params' => array(':USER_ID' => $this->id)));
     }
     return $this->_model;
 }
Example #30
0
	/**
	 * Activation user account
	 */
	public function actionActivation () {
		$email = $_GET['email'];
		$activkey = $_GET['activkey'];
		if ($email&&$activkey) {
			$find = User::model()->notsafe()->findByAttributes(array('email'=>$email));
			if (isset($find)&&$find->status) {
			    $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("You account is active.")));
			} elseif(isset($find->activkey) && ($find->activkey==$activkey)) {
				$find->activkey = UserModule::encrypting(microtime());
				$find->status = 1;
				$find->save();
                if (!Yii::app()->controller->module->autoLogin) {
                    $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("You account is activated.")));
                } else {
                    $identity=new UserIdentity($find->username, '');
                    $identity->authenticate(true);
                    Yii::app()->user->login($identity,0);
                    Yii::app()->user->setFlash('userActivationSuccess', UserModule::t("You account is activated."));
                    $this->redirect(Yii::app()->controller->module->returnUrl);
                }
			} else {
			    $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("Incorrect activation URL.")));
			}
		} else {
			$this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("Incorrect activation URL.")));
		}
	}