Show
Ignore:
Timestamp:
10/01/08 17:35:19 (3 months ago)
Author:
kenji
Message:

Refactoring Follow/Remove

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • events/phpframework/codeigniter/trunk/system/application/controllers/friendships.php

    r20235 r20373  
    1414        } 
    1515 
     16        // Ajax「フォローする」の受信 
    1617        function create() 
    1718        { 
     19                $this->session->keep_flashdata('ticket'); 
     20                header('Content-Type: application/json; charset=UTF-8'); 
     21 
    1822                // CSRF チェック 
    19                 $ticket = $this->session->userdata('ticket'); 
     23                $ticket = $this->session->flashdata('ticket'); 
    2024                if ( ! $this->input->post('ticket')  
    2125                        || $this->input->post('ticket') !== $ticket) 
    2226                { 
    2327                        log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted but Wrong Ticket'); 
     28                        echo json_encode(array('status' => 'ng', 'html' => 'チケットが異なります')); 
    2429                        exit; 
    2530                } 
     
    2934                { 
    3035                        log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted but Not Logged in'); 
     36                        echo json_encode(array('status' => 'ng', 'html' => 'ログインしていません')); 
    3137                        exit; 
    3238                } 
     
    3945                { 
    4046                        log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted but follow_id = 0'); 
     47                        echo json_encode(array('status' => 'ng', 'html' => 'ユーザIDが不正です')); 
    4148                        exit; 
    4249                } 
     
    4451                { 
    4552                        log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted but follow_id = user_id'); 
     53                        echo json_encode(array('status' => 'ng', 'html' => 'ユーザIDが不正です')); 
    4654                        exit; 
    4755                } 
     
    5159                $this->Follower_model->create($user_id, $follow_id); 
    5260 
    53                 header('Content-Type: text/html; charset=UTF-8'); 
    54                 echo '<h1 id="msg">あなたはフォローを開始しました。</h1>'; 
     61                $html = '<h1 id="msg">あなたはフォローを開始しました。</h1>'; 
     62                echo json_encode(array('status' => 'ok', 'html' => $html)); 
    5563        } 
    5664 
     65        // Ajax「フォロー解除する」の受信 
    5766        function destroy() 
    5867        { 
     68                $this->session->keep_flashdata('ticket'); 
     69                header('Content-Type: application/json; charset=UTF-8'); 
     70 
    5971                // CSRF チェック 
    60                 $ticket = $this->session->userdata('ticket'); 
     72                $ticket = $this->session->flashdata('ticket'); 
    6173                if ( ! $this->input->post('ticket')  
    6274                        || $this->input->post('ticket') !== $ticket) 
    6375                { 
    6476                        log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted but Wrong Ticket'); 
     77                        echo json_encode(array('status' => 'ng', 'html' => 'チケットが異なります')); 
    6578                        exit; 
    6679                } 
     
    7083                { 
    7184                        log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted but Not Logged in'); 
     85                        echo json_encode(array('status' => 'ng', 'html' => 'ログインしていません')); 
    7286                        exit; 
    7387                } 
     
    8094                { 
    8195                        log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted but follow_id = 0'); 
     96                        echo json_encode(array('status' => 'ng', 'html' => 'ユーザIDが不正です')); 
    8297                        exit; 
    8398                } 
     
    85100                { 
    86101                        log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted but follow_id = user_id'); 
     102                        echo json_encode(array('status' => 'ng', 'html' => 'ユーザIDが不正です')); 
    87103                        exit; 
    88104                } 
     
    92108                $this->Follower_model->destroy($user_id, $follow_id); 
    93109 
    94                 header('Content-Type: text/html; charset=UTF-8'); 
    95                 echo '<h1 id="msg">あなたはフォローを解除しました。</h1>'; 
    96         } 
    97  
    98         function destroy2() 
    99         { 
    100                 // CSRF チェック 
    101                 $ticket = $this->session->userdata('ticket'); 
    102                 if ( ! $this->input->post('ticket')  
    103                         || $this->input->post('ticket') !== $ticket) 
    104                 { 
    105                         log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted but Wrong Ticket'); 
    106                         exit; 
    107                 } 
    108  
    109                 // ログインチェック 
    110                 if ( ! $this->redux_auth->logged_in()) 
    111                 { 
    112                         log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted but Not Logged in'); 
    113                         exit; 
    114                 } 
    115  
    116                 $user_id   = intval($this->session->userdata('id')); 
    117                 $follow_id = intval($this->input->post('id')); 
    118  
    119                 // バリデーション 
    120                 if ($follow_id == 0) 
    121                 { 
    122                         log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted but follow_id = 0'); 
    123                         exit; 
    124                 } 
    125                 if ($user_id == $follow_id) 
    126                 { 
    127                         log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted but follow_id = user_id'); 
    128                         exit; 
    129                 } 
    130  
    131                 $this->load->model('Follower_model', '', TRUE); 
    132                 log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted Follow: ' . $user_id . ' > ' . $follow_id); 
    133                 $this->Follower_model->destroy($user_id, $follow_id); 
    134  
    135                 header('Content-Type: text/html; charset=UTF-8'); 
    136                 echo '#id' . $follow_id; 
     110                $html = '<h1 id="msg">あなたはフォローを解除しました。</h1>'; 
     111                echo json_encode(array('status' => 'ok', 'html' => $html, 'id' => '#id' . $follow_id)); 
    137112        } 
    138113