Magento and Discuz (ucenter) Integration of integrated development ideas

Source: Internet
Author: User
Tags set cookie setcookie

Discuz comes with Ucenter, which is mainly used for communication with other programs. We can download the Discuz ucenter Development Manual for Magento and discuz integration. There are some Ucenter interface functions and parameter descriptions, without this document, the template will not be able to do the following:


1, put the API and Uc_client directory in the application directory.

2, modify your own configuration file (Application/config/config.ini), at the end add the following code: code as follows

[Ucenter]
Uc. uc_on = 0
Uc. Uc_connect = MySQL
Uc. Uc_dbhost = localhost
Uc. Uc_dbuser = root
Uc. UC_DBPW = Vertrigo
Uc. Uc_dbname = Ucenter
Uc. Uc_dbcharset = UTF8
Uc. Uc_dbtablepre = ucenter.uc_
Uc. Uc_key = 123456789
Uc. Uc_api = Http://localhost/comsenz/ucenter15
Uc. Uc_charset = Utf-8
Uc. UC_IP =
Uc. Uc_appid = 1

Copy Code

The above items will know what the meaning is, UC. UC_ON is the switch on which the Ucenter sync is turned on in the system, 1: On, 0: off. Pay attention to UC. Uc_key must be set in and Ucenter



The application's key is consistent or the communication failure is displayed.



3, modify the index.php entry file, add configuration resolution, the code is as follows:



The code is as follows

Ucenter Configuration
Zend_registry::set (' uc_on ', $config->ucenter->uc->uc_on);
if (Zend_registry::get (' uc_on ')) {
Define (' Uc_connect ', $config->ucenter->uc->uc_connect); MySQL is directly connected.database, for efficiency, it is recommended to use MySQL
Define (' Uc_dbhost ', $config->ucenter->uc->uc_dbhost); Ucenter Database Host
Define (' Uc_dbuser ', $config->ucenter->uc->uc_dbuser); Ucenter Database user Name
Define (' UC_DBPW ', $config->UCENTER->UC->UC_DBPW); Ucenter Database Password
Define (' Uc_dbname ', $config->ucenter->uc->uc_dbname); Ucenter database name
Define (' Uc_dbcharset ', $config->ucenter->uc->uc_dbcharset); Ucenter Database Character Set
Define (' Uc_dbtablepre ', $config->ucenter->uc->uc_dbtablepre); Ucenter database table prefixes
Define (' Uc_key ', $config->ucenter->uc->uc_key); Communication key with Ucenter, to be consistent with Ucenter
Define (' Uc_api ', $config->ucenter->uc->uc_api); Ucenter URL address, which is dependent on this constant when calling the Avatar
Define (' Uc_charset ', $config->ucenter->uc->uc_charset); Ucenter's character Set
Define (' Uc_ip ', $config->ucenter->uc->uc_ip); IP of Ucenter
Define (' Uc_appid ', $config->ucenter->uc->uc_appid); ID of the current app
Include './uc_client/client.php ';
}

Copy Code

OK, the preparation is finished, the following program development.



4, the implementation of the landing synchronization, the following code is a bit long, because I was not integrated ucenter, and later added Ucenter, so do a compatibility, taking into account that there is no open ucenter



Login.



The code is as follows

If Ucenter is turned on
if ($this->is_uc_on) {
Through the interface to determine the correctness of the login account, the return value for the array
List ($uid, $username, $password, $email) = Uc_user_login ($username, $password);
if ($uid > 0) {
Determines whether the user exists in the user table, does not exist, jumps to the activation page
if ($this->user->checkuservalid ($username)) {
Write these user information to a cookie to activate the page
@setcookie (' Zf_auth ', Uc_authcode ($uid. " T ". $username." T ". $password." T ". $email, ' ENCODE '), Time () +3600, '/');
$this->view->securl = $this->view->domain. ' /user/activation ';
$this->view->msg = ' You need to activate this account in order to enter the application! ';
echo $this->view->render (' success.php ');
Exit
}
User login successful, set Cookie
$udata = array (' id ' = = $uid, ' username ' + = $username, ' role ' = ' member ');
$expire = 86400;
$this->setcookie ($udata, $expire);

Generate code for synchronous logins
$ucsynlogin = Uc_user_synlogin ($uid);
$this->view->securl = $this->view->domain;
$this->view->msg = ' Login successful, is jumping back to the page! ';
echo $this->view->render (' success.php ');
} elseif ($uid = =-1) {
$this->view->error = "User does not exist, or is deleted!";
echo $this->view->render (' error.php '); exit;
} elseif ($uid = =-2) {
$this->view->error = "bad password!";
echo $this->view->render (' error.php '); exit;
} else {
$this->view->error = "System error, please try again later!";
echo $this->view->render (' error.php '); exit;
}
}
else//No UC-based sign-in method
{
$dbAdapter = Zend_registry::get (' dbadapter ');
$authAdapter = new Zend_auth_adapter_dbtable ($dbAdapter);
$authAdapter->settablename (' Bg_user ');
$authAdapter->settablename (Zend_registry::get (' Dbprefix '). User ');
$authAdapter->setidentitycolumn (' username ');
$authAdapter->setcredentialcolumn (' password ');

$authAdapter->setidentity ($username);
$authAdapter->setcredential ($password);

$auth = Zend_auth::getinstance ();
$result = $auth->authenticate ($authAdapter);
if ($result->isvalid ()) {
$data = $authAdapter->getresultrowobject (null, ' password ');
$auth->getstorage ()->write ($data);
Write Cookie
$udata = array (' id ' = = $data->id, ' username ' = + $data->username, ' role ' = $data->role);
$expire = 86400;
$this->setcookie ($udata, $expire);
$this->view->securl = $this->view->domain;
$this->view->msg = ' Login successful, is jumping back to the page! ';
echo $this->view->render (' success.php ');
}else{
User name password
$this->view->error = "User name password is wrong!";
echo $this->view->render (' error.php ');
Exit ();
}
}

OK, synchronization login complete, and then the above to imitate the logout, change the password, modify the user data can be achieved.

Magento and Discuz (ucenter) Integration of integrated development ideas

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.