首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

joomla组件开发——会员积分治理组件的登陆跳转

2013-11-08 
joomla组件开发——会员积分管理组件的登陆跳转今天记录3c之家网站建设过程中遇到的一点小问题。由于网站需要

joomla组件开发——会员积分管理组件的登陆跳转

今天记录3c之家网站建设过程中遇到的一点小问题。由于网站需要,找了个会员积分系统来用用,AlphaUserPoints,总体感觉很是不错,先来看看后台

joomla组件开发——会员积分治理组件的登陆跳转

还可以吧?功能很是强大。

于是,我新建了一个菜单->会员中心,指向了AlphaUserPoints的个人页面,然而在前台点击后问题出现了,错误提示:您没有权限观看此页面;是啊,没有登录。可是想想这样的话会员肯定会不高兴的,最起码让网页直接能跳转到登录页面呢。好,开始分析源代码,下面是此组件的文件列表

joomla组件开发——会员积分治理组件的登陆跳转

我们来看看控制器,

class alphauserpointsController extends JController{    function display() {                                parent::display();    }}


里面没有东西,进controllers文件夹看看:

joomla组件开发——会员积分治理组件的登陆跳转

有这几个文件,分析url:http://3c-home.com/index.php?option=com_alphauserpoints&view=account&Itemid=103

可知此应该使用的是account视图,对于的也就是account控制器,打开文件查看display函数部分

function display () {$app = JFactory::getApplication();require_once (JPATH_ROOT.DS.'components'.DS.'com_alphauserpoints'.DS.'helper.php');$com_params = JComponentHelper::getParams( 'com_alphauserpoints' );$model      = &$this->getModel ( 'alphauserpoints' );$view       = $this->getView  ( 'account','html' );// current user$user =  JFactory::getUser();// profil request $userid      = JRequest::getVar( 'userid', '', 'default', 'string' );if ( !$user->id && !$com_params->get( 'allowGuestUserViewProfil', 1 ) ) {$msg = JText::_('ALERTNOTAUTH' );                            $app->redirect('index.php', $msg);}这段代码就是检测是否有用户登录,如果没有用户登录就跳转到首页,并显示错误消息$msg.// check referre IDif ( ! $userid ) {$referrerid = $model->_checkUser();} else  {$referrerid = $userid;}// Rule Profile Viewif ( $referrerid != @$_SESSION['referrerid'] ) {$keyreference  = AlphaUserPointsHelper::buildKeyreference( 'sysplgaup_profile_view', $user->id );$username = ( $user->username ) ? $user->username : JText::_('AUP_GUEST');$datareference = JText::_('AUP_PROFILE_VIEW_REFERENCE') . ' ' . $username;AlphaUserPointsHelper::userpoints ( 'sysplgaup_profile_view' , $referrerid, 0, $keyreference, $datareference );}// End rule Profile View// Get the parameters of the active menu item$params = $model->_getParamsAUP();$num_item_activities = $params->get( 'num_item_activities', 10 );$_get_last_points   = $model->_get_last_points ( $referrerid, $num_item_activities );$_listing_last_points= $_get_last_points[0];$_listing_total= $_get_last_points[1];$_listing_limit= $_get_last_points[2];$_listing_limitstart= $_get_last_points[3];$rowsreferrees= $model->_get_referrees ( $referrerid );$pointsearned = $model->_pointsearned(); // users points earned TOP 10$totalpoints= $model->_totalpoints(); // entire community$mypointsearned = $model->_mypointsearned($referrerid);$mypointsspent = $model->_mypointsspent($referrerid);$mypointsearnedthismonth= $model->_mypointsearnedthismonth($referrerid);$mypointsspentthismonth= $model->_mypointsspentthismonth($referrerid);$mypointsearnedthisday= $model->_mypointsearnedthisday($referrerid);$mypointsspentthisday= $model->_mypointsspentthisday($referrerid);$_average_age= _get_average_age_community();$_user_info = AlphaUserPointsHelper::getUserInfo ( $referrerid );$currenttotalpoints    = $_user_info->points;$lastupdate = $_user_info->last_update;$referraluser = $_user_info->referraluser;$myname = $_user_info->name;$myusername = $_user_info->username;$mybirthday= $_user_info->birthdate;$referralname = "";if ( $referraluser ) {$referralinfo = AlphaUserPointsHelper::getUserInfo ( $referraluser );$referralname = $referralinfo->username;}// get level/rank if exist$userrankinfo = AlphaUserPointsHelper::getUserRank ( $referrerid );// get medals if exist$medalslistuser = AlphaUserPointsHelper::getUserMedals ( $referrerid );// load avatar$useAvatarFrom = $com_params->get('useAvatarFrom');$height = 100;if ( $useAvatarFrom=='alphauserpoints' ) JPlugin::loadLanguage( 'com_media', JPATH_ADMINISTRATOR );$avatar = getAvatar( $useAvatarFrom, $_user_info, $height );// Get coupons code$resultCoupons = $model->_getMyCouponCode( $referrerid );$view->assign('params', $params );$view->assign('cparams', $com_params );$view->assign('referreid', $referrerid );$view->assign('currenttotalpoints', $currenttotalpoints );$view->assign('rowslastpoints', $_listing_last_points );$view->assign('total', $_listing_total );$view->assign('limit', $_listing_limit );$view->assign('limitstart', $_listing_limitstart );$view->assign('lastupdate', $lastupdate );$view->assign('referraluser', $referraluser );$view->assign('referralname', $referralname );$view->assign('rowsreferrees', $rowsreferrees );$view->assign('userid', $user->id);$view->assign('userrankinfo', $userrankinfo);$view->assign('medalslistuser', $medalslistuser);$view->assign('pointsearned', $pointsearned);$view->assign('totalpoints', $totalpoints);$view->assign('mypointsearned', $mypointsearned);$view->assign('mypointsspent', $mypointsspent);$view->assign('mypointsearnedthismonth', $mypointsearnedthismonth);$view->assign('mypointsspentthismonth', $mypointsspentthismonth);$view->assign('mypointsearnedthisday', $mypointsearnedthisday);$view->assign('mypointsspentthisday', $mypointsspentthisday);$view->assign('myname', $myname);$view->assign('myusername', $myusername);$view->assign('avatar', $avatar);$view->assign('birthday', $mybirthday);$view->assign('user_info', $_user_info);$view->assign('useAvatarFrom', $useAvatarFrom);$view->assign('mycouponscode', $resultCoupons);$view->assign('userinfo', $_user_info);$view->assign('average_age', $_average_age);// Display$view->_display();}

现在找到了地方,我们来做修改,把下面代码的跳转改改:

if ( !$user->id && !$com_params->get( 'allowGuestUserViewProfil', 1 ) )
 {$msg = JText::_('ALERTNOTAUTH' ); 
//login first
$app->redirect('index.php?option=com_users&view=login', $msg);}

现在把跳转改到了登录表单,然后把ALERTNOTAUTH对于的汉语提示改改,改成友善一点,就是提示顾客登录。继续测试,成功,窃喜呢。

点登录。。。。。

不对啊,登录以后是系统自带的用户界面啊,我得定向到新的会员界面啊,怎么办呢,我想还是把系统自带的user组件改改吧

找到com_user文件夹,好多文件啊,慢慢看吧,先入手控制器,

com_user下的controller.php文件里面没有点击login按钮触发的事件,最终在controllers文件夹下的user.php文件中找到相关代码。就是login函数

public function login(){JSession::checkToken('post') or jexit(JText::_('JInvalid_Token'));$app = JFactory::getApplication();// Populate the data array:$data = array();$data['return'] = base64_decode(JRequest::getVar('return', '', 'POST', 'BASE64'));$data['username'] = JRequest::getVar('username', '', 'method', 'username');$data['password'] = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);// Set the return URL if empty.if (empty($data['return'])) {$data['return'] = 'index.php?option=com_users&view=profile';                                              }// Set the return URL in the user state to allow modification by plugins$app->setUserState('users.login.form.return', $data['return']);// Get the log in options.$options = array();$options['remember'] = JRequest::getBool('remember', false);$options['return'] = $data['return'];// Get the log in credentials.$credentials = array();$credentials['username'] = $data['username'];$credentials['password'] = $data['password'];// Perform the log in.if (true === $app->login($credentials, $options)) {// Success$app->setUserState('users.login.form.data', array());$app->redirect(JRoute::_($app->getUserState('users.login.form.return'), false));                         } else {// Login failed !$data['remember'] = (int)$options['remember'];$app->setUserState('users.login.form.data', $data);$app->redirect(JRoute::_('index.php?option=com_users&view=login', false));}}

红色的那几行就是成功登陆后的跳转的相关代码,我直接跳转到我们需要的页面看看:

if (empty($data['return'])) {// $data['return'] = 'index.php?option=com_users&view=profile';                        $data['return'] ='index.php?option=com_alphauserpoints&view=account&Itemid=103';                            }

成功了。

总结:本次修改代码是在对组件开发不是特别熟悉的前提下进行的,在修改代码时考虑的不是很完备,如果能在AlphaUserPoints组件中实现登陆及相关的跳转就再好不过了,但时间紧迫,目前先将就使用。也希望通过这次的修改,为下次自己写组件奠定一些基础。


 

热点排行