<?php

namespace Common\Controller;

use Common\Controller\HomebaseController;

class MemberbaseController extends HomebaseController{

	

	function _initialize() {

		parent::_initialize();

		$this->check_login();

		$this->check_user();

	}

	//发送绑定邮箱邮件
	protected  function _send_to_bang($email){
		$option = M('Options')->where(array('option_name'=>'member_email_active'))->find();
		if(!$option){
			$this->error('网站未配置账号激活信息，请联系网站管理员');
		}
		$options = json_decode($option['option_value'], true);
		//邮件标题
		$title = $options['title'];
		$uid=sp_get_current_userid();
		$username=$_SESSION['user']['user_login'];
	
		$activekey=md5($uid.time().uniqid());
		$users_model=M("users_other");
	
		$result=$users_model->where(array("uid"=>$uid))->save(array("user_bang_key"=>$activekey));
		if(!$result){
			$this->error('绑定码生成失败！');
		}
		//生成激活链接
		$webhost = parseHost($_SERVER["HTTP_HOST"]);
		$url = 'http://'.$webhost['2'].U('user/profile/active',array("hash"=>$activekey));
		//邮件内容
		$template = $options['template'];
		$content = str_replace(array('http://#link#','#username#'), array($url,$username),$template);
	
		$send_result=sp_send_email($email, $title, $content);
	
		if($send_result['error']){
			$this->error('绑定邮件发送失败，请联系客服人员！');
		}
	}

}