Joomla component development-Logon jump of Member points management component

Source: Internet
Author: User

Today, we recorded a small problem encountered during the construction of a 3C apartment in Lanzhou. As a result of the website's need, I found a membership point system for use. alphauserpoints, the overall feeling is very good. Let's take a look at the background.

Okay? Very powerful.

As a result, I created a menu> member center and directed it to the personal page of alphauserpoints. However, when I click it on the front-end, the problem occurs. The error message is: you are not authorized to view this page; yes, no logon. However, if you think about this, the members will be unhappy. At the very least, the webpage can jump directly to the login page. OK. Start to analyze the source code. The following is the file list of this component.

Let's look at the controller,

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

There is nothing in it. Go to the controllers folder and see:

There are several files, analysis URL: http://3c-home.com/index.php? Option = com_alphauserpoints & view = Account & Itemid = 103

We can see that the Account view is used. For the account controller, open the file and view the display function section.

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: _ ('alertnotau'); $ app-> redirect ('index. php', $ MSG);} This code is used to check whether a user has logged on. If no user has logged on, the page will jump to the homepage and display the error message $ MSG. // check referre idif (! $ Userid) {$ referrerid = $ model-> _ checkuser ();} else {$ referrerid = $ userid;} // rule profile viewif ($ referrerid! = @ $ _ Session ['refererid']) {$ 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 = _ second (); $ _ 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 ('referelid', $ 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 ('signature', $ mypointsearnedthismonth); $ view-> assign ('mypointsspentthismonth ', $ mypointsspentthismonth); $ view-> assign ('mypointsearnedthisday', $ interval); $ 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 ('myuponscode', $ resultcoupons); $ view-> assign ('userinfo ', $ _ user_info); $ view-> assign ('average _ age', $ _ average_age); // display $ view-> _ display ();}

Now we have found a place. Let's modify it and change the jump of the following code:

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

Now, the redirection is changed to the logon form, and then the alertnotauth Chinese prompt is changed to a friendly one, that is, the customer is prompted to log on. Continue the test. The test is successful.

Click Log On .....

No. After logging on to the system, it is the user interface that comes with the system. I have to direct it to the new member interface. What should I do? I 'd like to change the user component that comes with the system.

Find the com_user folder and find many files. Take a look at it and start with the Controller,

In the controller. php file under com_user, no event triggered by clicking the login button is found in the user. php file in the controllers folder. Is the login function.

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));}}

The lines in red are the relevant code for jump after successful login. I will jump directly to the page we need to look:

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

Succeeded.

Conclusion: The modified code is implemented on the premise that the component development is not particularly familiar with, and the considerations for modifying the Code are not complete, if you can achieve login and related jumps in the alphauserpoints component, it would be better, but the time is short and will be used first. It is also hoped that this modification will lay a foundation for writing components by yourself next time.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.