CI 묻고 답하기

제목 패스워드 수정 질문좀여..ㅠㅠ
글쓴이 sdfsdf 작성시각 2013/02/24 13:10:35
댓글 : 5 추천 : 0 스크랩 : 0 조회수 : 13500   RSS

////////////////// controller 부분 입니다. /////////

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
 * Created on 2012. 6. 8.
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
 class info extends CI_Controller_Members {

 private $m = ''; //메뉴ID

  public function __construct(){
   parent::__construct();
   
   
  
   
   $this->m = $this->input->get('m', TRUE);
  }

 function index(){
  
  //$required_if = $this->input->post('passowrd')?'|required':'';.reqired_if.
  $this->form_validation->set_rules('current_password','현재 비밀번호','trim|reqired|min_length[4]');
  $this->form_validation->set_rules('change_password','변경 비밀번호','trim|reqired|min_length[4]|matches[confrirm_password]');
  $this->form_validation->set_rules('confrirm_password','변경 비밀번호 확인','trim');
  
  if($this->form_validation->run()==TRUE){
   
   
   $current_password = $this->input->post('current_password');
   $change_password  = $this->input->post('change_password');

   
   $this->load->model('login_model');
   $user = $this->login_model->getUserByIdPw($userId, $userPw);
   
   
   //$result = $this->login_model->chagePassowrd($chageUserPw);
   
   
   if (!isset($user['usr_pw']))
   {
    $this->form_validation->set_message('required', '사용자가 존재하지 않습니다..');
    return FALSE;
   }else{
    
    if (strcmp($user['usr_pw'], $user['chk_pw']) == 0){
     
     
     
     $result = $this->login_model->chagePassword($chageUserPw);
     redirect('mypage/info?m='.$this->m);<br />      <br />     }else{<br />      <br />      $this->form_validation->set_message('required','입력한 비밀번호가 잘못되었습니다.');
    }
   }
 
   
   
  }else{
   $this->load->tile('base','mypage/info/info_form');  
  }


 }
 }
?>

///////////// view 부분 입니다. ////////////////////////////

<?php
$m = $this->input->get('m');
?>
<script type="text/javascript">
 function checkingPw(){
  
  if(document.pwdForm.current_password.value == ""){
   alert("현재 비밀번호를 입력해주세요");
  }else if(document.pwdForm.change_password.value == ""){
   alert("변경할 비밀번호를 입력해주세요");
  }else if(document.pwdForm.change_password.value != document.pwdForm.confrirm_password.value){
   alert("비밀번호 입력이 맞지않습니다. 다시 입력해주세요");
  }else{
   document.pwdForm.submit();
  }

 }
</script>
<?
 $attributes = array('id' => 'pwdForm', 'name' => 'pwdForm');
 echo form_open('/mypage/info?m='.$m, $attributes)<br /> ?></p> <p><br /> <table border=1 cellspacing=3 bordercolor=red align=center></p> <p> <br />  <table class="tbl_basic"></p> <p>  <tr><br />    <th>사용자ID</th><br />    <td><? echo $this->session->userdata['usr_id']?></td>
  </tr>
  <tr>
   <th>소속본부</th>
   <td><?php echo $this->session->userdata['dept_nm'] ?></td>
   <th>현재비밀번호</th>
   <td><input type=password name=current_password value="" size=15></td>
  </tr>
  <tr>
   <th>비밀번호변경</th>
   <td><input type=password name=change_password size=15></td>
   <th>비밀번호변경 확인</th>
   <td><input type=password name=confrirm_password size=15></td>
  </tr>
  <tr>
   <td align=center colspan="4">
    <input type="button" value="변경하기" onclick="checkingPw()"/>
   </td>
   
  </tr>
 
 </table>
<?php echo validation_errors();?>
<?
 echo form_close();
?>
////////////////////////////// model 부분 입니다...//////////////////////////

<?php

class Login_model extends CI_Model{
 public function getUserById($userid){
  $this->db->select('a.usr_sq, a.usr_id, a.usr_nm, a.usr_pw, b.dept_sq, b.dept_nm');
  $this->db->from('users a');
  $this->db->join('departments b', 'b.dept_sq = a.dept_sq');
  $this->db->where('a.usr_id', $userid);
  $this->db->limit(1, 0);
  $query = $this->db->get();
 
//  $query = $this->db->get_where('users', array('usr_id' => $userid), 1, 0);
   $row = $query->row_array();

   return $row;
 }
 
 public function getUserByIdPw($userId, $userPw){
  $sql = "SELECT a.usr_sq, a.usr_id, a.usr_nm, a.usr_pw, b.dept_sq, b.dept_nm, password(?) chk_pw, a.usr_level, b.depth, c.dept_sq bonbu_sq,c.dept_nm bonbu_nm" .
    " FROM users a" .
    " INNER JOIN departments b ON b.dept_sq = a.dept_sq AND b.use_yn = 'Y'" .
    " LEFT JOIN departments c ON c.lft <= b.lft AND c.rgt >= b.rgt AND c.depth = 1 AND c.use_yn = 'Y'" .
    " WHERE a.usr_id = ?";

  $data = array(
   $userPw,      
   $userId       
  );
  $query = $this->db->query($sql, $data);
  
   $row = $query->row_array();

   return $row;
 }
 
 /**
  * 패스워드 수정
  */
 public function chagePassowrd($chageUserPw){
  $usr_sq = $this->session->userdata('usr_sq');
 
  if($chageUserPw != ""){
  
  $sql = "UPDATE users" .
     " SET usr_pw = password(?)" .
      " WHERE usr_sq = ?";
  
  $data = array(
   $chageUserPw
  );
   
  }
  $res = $this->db->query($sql, $data);
  if (!$res){
   $return['error_number'] = $this->db->_error_number();
   $return['error_message'] = $this->db->_error_message();
  }else{
   $return['error_number'] = 0;
   $return['error_message'] = $this->db->_error_message();
  }
  
  return $return;
 }
}

?>

이렇게 되어 있는데요...  현재 패스워드 입력받고 변경할 패스워드를 입력받아서 패스워드를 변경하는 작업인데요
도저히 어떻게 해야 하는지 모르겠어서 도움 요청 합니다 .ㅜㅜ 알려주시면 감사하겠습니다 ㅠㅠ 도와주세요ㅠㅠ


 

 다음글 싸이트 기능구현 관련질문 (2)
 이전글 sqlite db 읽기가 안되네요 (2)

댓글

변종원(웅파) / 2013/02/25 09:07:10 / 추천 0
실행했을때 어떤에러가 나는지 올려주세요.
sdfsdf / 2013/02/25 09:12:08 / 추천 0

에러메시지 안나오고 아무것도 안나옵니다.ㅠㅠ

변종원(웅파) / 2013/02/25 11:13:35 / 추천 0
 CI_Controller_Members  <- 이게 뭔지 올려주세요. 

일반적인 형태가 아닙니다.

저번 글은 왜 지우셨는지요? 거기 소스에 대한 이런 저런 사항들 적어놨는데요...
(스무고개 다시 시작)
sdfsdf / 2013/02/25 14:18:49 / 추천 0

이거 입니다
class CI_Controller_Members extends CI_Controller_Basic {

 public function __construct() {
  parent::__construct();

   header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
   header('Pragma: no-cache');

   // 메뉴 정보가 없으면 메인페이지로 이동
   $menuId = $this->input->get('m');
   $currentmenu = $this->load->get_var('currentmenu');
   
   if (empty($currentmenu)) redirect('/');

   $defaultUrl = $currentmenu['mnu_url'].'?m='.$currentmenu['mnu_id'];

   if (empty($menuId)) redirect($defaultUrl);

//    권한이 없으면 첫페이지로 이동.
   if (!$this->checkPermission($currentmenu)){
    redirect($defaultUrl);
   }
 }

변종원(웅파) / 2013/02/25 14:47:54 / 추천 0
 성공했을때 이동하는 페이지도 없습니다.

그리고 $this->load->tile('base','mypage/info/info_form');  맞는 구문인지 소스를 찾아보세요.

load->file은 있는데 tile은 ci에 없는겁니다. load->file의 오타라면 사용법이 틀렸구요. (매뉴얼 참고)

이것저것 손을 많이 댄 소스 같습니다.  (수정하시려면 머리 아프실듯..)

2차 상속까지...