<?php
/**
 * class account_controller
 *
 * Description for class account_controller
 *
 * @author:
*/
namespace area\presenter\controller;

use core\response;
use core\user;
use area\presenter\form\account_form;
use area\presenter\form\password_form;

class account_controller extends _controller {
	public function index_action() {
		$model = array(
			"userName" => user::name(),
			"userEmail" => user::email()
		);

		return $this->view($model);
	}

	public function data_action() {
		if(!isset($_POST["__action"])) {
			$this->viewError("404");
		}

		$form = new account_form();
		if($form->valid()) {
			if($form->save()) {
				response::json(array("status" => "success"));
			}
		}

		response::json(array("status" => "error", "errors" => $form->getAllErrors()));
	}

	public function password_action() {
		if(!isset($_POST["__action"])) {
			$this->viewError("404");
		}

		$form = new password_form();
		if($form->valid()) {
			if($form->save()) {
				response::json(array("status" => "success"));
			}
		}

		response::json(array("status" => "error", "errors" => $form->getAllErrors()));
	}
}
?>