Email.php 2.27 KB
<?php

/**
 * 
 * @author tongdesheng
 *
 */
class EmailController extends QLib_Actions_Passport
{
	
	
	/**
	 * 注册
	 */
	public function regAction() {
		$code = Q_Utils_Function::base64_url_decode($this->_get('code'));
		$strData = Q_Utils_AuthCode::decode($code, YHMConfig_Email::secret_key);
		$data = json_decode($strData, true);
		//解析后示例:{"email":"393936906@qq.com","type":"emailReg","create_time":1410320588}
		$data = json_decode($strData, true);
		if(!empty($data)) {
			$authInfo = YHMPassport_Models_Auth_Client::getProfileByEmail($data['email']);
			if(!empty($authInfo)) {
				$ret = YHMPassport_Models_Auth_Client::setActive($authInfo['uid'], $authInfo['profile']);
			}
		} 
	}
	
	/**
	 * 绑定
	 */
	public function bindAction() {
		$code = $this->_get('code');
		$strCode = Q_Utils_Function::base64_url_decode($code);
		$strData = Q_Utils_AuthCode::decode($strCode, YHMConfig_Email::secret_key);
		$data = json_decode($strData, true);
		if(!empty($data)) {
			//Array ( [email] => 21650828@qq.com [type] => emailBind [create_time] => 1410442907 [uid] => 1 [password] => 123123 )
			$uid = $data['uid'];
			//只做激活操作
			$authInfo = YHMPassport_Models_Auth_Client::getProfileByEmail($data['email']);
			if(!empty($authInfo)) {
				$ret = YHMPassport_Models_Auth_Client::setActive($uid, $data['email']);
			}
		}
	}
	
	/**
	 * 找回密码
	 */
	public function findpwdAction() {
		$code = $this->_get('code');
		$strCode = Q_Utils_Function::base64_url_decode($code);
		$strData = Q_Utils_AuthCode::decode($strCode, YHMConfig_Email::secret_key);
		$data = json_decode($strData, true);
		if(!empty($data)) {
			$this->_assign('code', $code);	
		}
	}
	
	/**
	 * 重置密码
	 */
	public function resetpwdAction() {
		$code = $this->_post('code');
		$password = $this->_post('password');
		if(!empty($code)) {
			$strCode = Q_Utils_Function::base64_url_decode($code);
			$strData = Q_Utils_AuthCode::decode($strCode, YHMConfig_Email::secret_key);
			$data = json_decode($strData, true);
			if(!empty($data)) {
					try {
						$authObj = YHMAuth_Factory::profile('web');
						$ret = $authObj->updatePassword(0, $password, $data['email'], YHMConfig_Passport::PROFILE_TYPE_MAIL);
					}catch (Exception $e) {
						$this->_assign('error_msg', $e->getMessage());
					}
				
			}
		}
	}
}