<?php
/*
+--------------------------------------------------------------------------
|   TanyaCMS - Question and Answer Sofware
|   -----------------------------------------------------------------------
|   by fbschool dev team
|   (c) 2011 - 2012 FBSCHOOL
|   http://www.fbschool.com/tanyacms
|   -----------------------------------------------------------------------
|   This is NOT a freeware, use is subject to license terms
|   Support: 13455n@gmail.com
+--------------------------------------------------------------------------
*/


if (!defined('IN_TANYACMS'))
{
	die;
}

class find_password extends ASK_CONTROLLER
{

	public function get_access_rule()
	{
		$rule_action['rule_type'] = 'black'; //Blacklist, blacklist check  'white' white list, outside the whitelist check
		$rule_action['guest'] = array();
		$rule_action['user'] = array();
		
		return $rule_action;
	}

	function setup()
	{
		$this->crumb('Find your password', '/account/find_password/');
	}

	function index_action()
	{
		TPL::import_css('css/login.css');
		
		TPL::output('account/find_password/index');
	}
	
	function process_success_action()
	{
		$email = $_SESSION['find_password'];

		TPL::import_css('css/login.css');
		
		TPL::assign('email', $email);
		TPL::assign('common_email', H::get_common_email($email));
		
		TPL::output("account/find_password/process_success");
	}
	
	function modify_action()
	{
		$active_code = $_GET['key'];
		
		$active_code_row = $this->model('active')->get_active_code_row($active_code, 11);
		
		if (!$active_code_row)
		{
			H::redirect_msg('Link has expired, please back to home', '/');
		}
		
		if ($active_code_row['active_time'] || $active_code_row['active_ip'] || $active_code_row['active_expire'])
		{
			H::redirect_msg('Link has expired, please back to home', '/');
		}
		
		TPL::import_css('css/login.css');
		
		TPL::output("account/find_password/modify");
	}
}