Ejemplo n.º 1
0
	/**
	 * Show a user's profile, (Admin view only).
	 *
	 * @return null|int
	 */
	public function view(){
		$view    = $this->getView();
		$request = $this->getPageRequest();

		if(!\Core\user()->checkAccess('p:/user/users/manage')){
			// This check MUST be first, as only admin users should have the ability to lookup full account details.
			// If you need this functionality for another component, with a different permission set,
			// then copy this method and implement it in your own controller with your own access permissions,
			// but only return what data you actually need!
			return View::ERROR_ACCESSDENIED;
		}

		/** @var UserModel $user */
		$user = UserModel::Construct($request->getParameter(0));

		if(!$user->exists()){
			return View::ERROR_NOTFOUND;
		}

		// Grab the login attempts for this user
		$logins = SystemLogModel::Find(
		//['affected_user_id = ' . $user->get('id'), 'code = /user/login'],
			['affected_user_id = ' . $user->get('id')],
			20,
			'datetime DESC'
		);

		if($request->isJSON()){
			$view->mode = View::MODE_PAGEORAJAX;
			$view->contenttype = View::CTYPE_JSON;

			$view->jsondata['user'] = $user->getAsArray();
			$view->jsondata['logins'] = $logins;

			// Massage some user data a bit, and remove things that don't need to be exported.
			unset($view->jsondata['user']['password']);

			return;
		}

		if(!$user->isActive()){
			\Core\set_message('This account is not active!', 'warning');
		}

		$view->controls = ViewControls::DispatchModel($user);

		$view->mastertemplate = 'admin';
		$view->addBreadcrumb('Administration', '/admin');
		$view->addBreadcrumb('User Administration', '/user/admin');
		$view->title = $user->getLabel() . ' Profile';
		$view->assign('user', $user);
		$view->assign('logins', $logins);
		$view->assign('profiles', $user->get('external_profiles'));
	}