Skip to content

Commit

Permalink
ちょっと変更したいので保存しておく
Browse files Browse the repository at this point in the history
  • Loading branch information
amashigeseiji committed Mar 28, 2013
1 parent 7b1882d commit f58bfd5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 36 deletions.
4 changes: 3 additions & 1 deletion template/auth.php
Expand Up @@ -8,7 +8,9 @@
</head>
<body>
<form action="#" method="post">

<?php //if ($message = $this->message['auth'] != null): ?>
<?php //echo $message ?>
<?php //endif; ?>
<table>
<tr>
<th>name</th>
Expand Down
97 changes: 62 additions & 35 deletions user.action.class.php
Expand Up @@ -25,36 +25,43 @@ public function initialize()
$this->authusers = array();
$this->usernames = array();
$this->user = null;
$post = null;

$this->baseuserobj = new BaseUser;
$this->setUserNames();


$post = $this->getPostValue('logout');
$cookie = $this->getCookie('token');
var_dump($cookie);

//cookie の破棄が先!!
if (array_key_exists('logout',$_POST))
//if (array_key_exists('logout',$_POST))
if ( null != $post )
{
//ログアウト処理ではクッキーを削除
$this->deleteToken($_COOKIE['token']);
$this->deleteToken($cookie);
$this->user = null;
//ログインページを表示する
$this->callTemplate('template/auth.php');
$action = null;
}

if (array_key_exists('token',$_COOKIE) && $this->getNameByToken($_COOKIE['token']) != null )
//if (array_key_exists('token',$_COOKIE) && $this->getNameByToken($_COOKIE['token']) != null )
if ( null != $cookie )
{
var_dump($_COOKIE); echo 'initialize';
//cookieがtokenと一致すれば自動ログイン
//$name にbool値が入っている…
$name = $this->getNameByToken($_COOKIE['token']);
//$name = $this->getNameByToken($_COOKIE['token']);
$name = $this->getNameByToken($cookie);
$id = $this->baseuserobj->getUserIdByName($name);
//$this->user = $this->baseuserobj->createUser($id);
$this->user = $this->createUser($id);
$this->callTemplate('template/auth.php');
}
elseif (array_key_exists('name',$_POST) && array_key_exists('password',$_POST))
//elseif (array_key_exists('name',$_POST) && array_key_exists('password',$_POST))
elseif ( $this->isWebRequest('name',$_POST) && $this->isWebRequest('password',$_POST) )
{
$this->Authentication($_POST);
//$action = new Action;
$this->callTemplate('template/auth.php');
}
else
Expand All @@ -66,38 +73,58 @@ public function initialize()
//var_dump($this->user);
}

public function getHeaderStatus()
public function isWebRequest($parameter,$request)
{
if (array_key_exists('token',$_COOKIE))
if ( array_key_exists($parameter,$request) )
{
//cookieがtokenと一致すれば自動ログイン
$name = $this->getNameByToken($_COOKIE['token']);
$id = $this->baseuserobj->getUserIdByName($name);
//$this->user = $this->baseuserobj->createUser($id);
$this->user = $this->createUser($id);
$this->callTemplate('template/auth.php');
return true;
}
else
{
$this->callTemplate('template/auth.php');
return false;
}
}

if (array_key_exists('logout',$_POST))
public function getGetValue($parameter)
{
if ( true == $this->isWebRequest($parameter,$_GET) )
{
//ログアウト処理ではクッキーを削除
$this->tetete = 'tetete';
$this->deleteToken($_COOKIE['token']);
$this->user = null;
//ログインページを表示する
//$this->callTemplate('template/auth.php');
//$action = null;
return $_GET[$parameter];
}
else
{
return null;
}
}

if (array_key_exists('name',$_POST) && array_key_exists('password',$_POST))
public function getPostValue($parameter)
{
if ( true == $this->isWebRequest($parameter,$_POST) )
{
$this->Authentication($_POST);
//$action = new Action;
$this->callTemplate('template/auth.php');
if ( '' != $_POST[$parameter] )
{
return $_POST[$parameter];
}
else
{
return null;
}
}
else
{
return null;
}
}

public function getCookie($parameter)
{
if ( true == $this->isWebRequest($parameter,$_COOKIE) )
{
return $_COOKIE[$parameter];
}
else
{
return null;
}
}

Expand All @@ -109,10 +136,7 @@ public function Authentication($post)
$id = $this->baseuserobj->getUserIdByName($name);
if ( $this->auth($post['name'],$post['password']) == true )
{
//$this->user = $this->baseuserobj->createUser($id);
$this->user = $this->createUser($id);
//$action = new Action;
//parent::initialize();
$this->callTemplate('template/auth.php');
}
else
Expand All @@ -121,9 +145,6 @@ public function Authentication($post)
}

}
else
{
}
}

public function auth($name,$password)
Expand Down Expand Up @@ -182,6 +203,12 @@ public function deleteToken($token)
{
unlink("data/token/$token");
}
if ( $_COOKIE['token'] )
{
setcookie("token", '', time() -1800, '/');
$_COOKIE = array();
var_dump($_COOKIE); echo 'deleteToken';
}
}

public function getToken($name)
Expand Down

0 comments on commit f58bfd5

Please sign in to comment.