<?php

/* ========================================================================
 * $Id: setpwd.php 1635 2020-07-08 08:09:26Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
# edit
#请求数据
if($MODE=='$post'){
  $id=onez()->gp('id');
  $action=onez()->gp('action');
  if($action=='data'){
    
    $data=array();
    $data['title']='修改密码';
    $A['pagedata']=$data;
    $form=$this->load('form');
    $form->init($site);
    #$form->form()->set('basename','修改密码');
    
    $tab=false;
    $form->add(array('label'=>'旧密码','type'=>'password','key'=>'password','hint'=>'','notempty'=>'旧密码不能为空','default'=>'','group'=>''),$tab);
    $form->add(array('label'=>'新密码','type'=>'password','key'=>'password1','hint'=>'','notempty'=>'新密码不能为空','default'=>'','group'=>''),$tab);
    $form->add(array('label'=>'确认新密码','type'=>'password','key'=>'password2','hint'=>'','notempty'=>'','default'=>'','group'=>''),$tab);
    
    if($onez=$form->submit()){
      $u=$G['this']->userdb()->open('member')->one("id='$G[userid]'");
      if($u['key3']!=md5($onez['password'])){
        return $this->error('旧密码不正确');
      }
      if($onez['password1']!=$onez['password2']){
        return $this->error('两次密码不一致');
      }
      $item=array();
      $item['key3']=md5($onez['password2']);
      $G['this']->userdb()->open('member')->update($item,"id='$G[userid]'");
      return $this->ok('修改密码成功');
    }
    $form->output($A);
  }
  return;
}
$this->add(array(
  'type'=>'breadcrumb',
  'name'=>'面包屑导航',
  'data'=>'pagedata',
));
?>
<section class="content">
<?php 
$this->add(array(
  'type'=>'pageform',
  'name'=>'表单',
  'data'=>'form',
));
?>
</section>
