public function login($uname, $str) { //取出随机数列 $login_key = $this->session->userdata('key'); $this->session->unset_userdata('key'); /*获得用户信息*/ if (parent::count(array('uname' => $uname)) == 1) { //$q=$this->db->get_where('user',array('uname'=>$uname))->row_array(); $q = end(parent::find(array('uname' => $uname))); //检查用户是否已经过期 if (isset($q['expire_time']) && $q['expire_time'] < time()) { //验证待激活用户是否过期,过期则删除,并返回登陆失败 if (parent::deleteByPk($q['id'])) { return $this->set_err(101, 'Expired User!'); } else { return FALSE; } } /*检验用户是否已经激活*/ if (!$q['active']) { return $this->set_err(102, 'Please activate the user first'); } /*产生服务器端的hash数据*/ $ser = sha1($q['pword'] . $login_key); /*验证*/ if ($str == $ser) { /*更新最后登陆时间以及登陆状态*/ /* $this->db->where('id',$q['id']); $this->db->update('hfi_user',array('latest_login'=>time())); */ parent::updateByPk(array('latest_login' => time()), $q['id']); //更新session $s_data = array('rsc_login' => TRUE, 'uid' => $q['id']); $this->session->set_userdata($s_data); //set security session $this->session->set_userdata('security', TRUE); $this->session->set_userdata('sec_time', time() + 60); //设置登陆数据 $this->uid = $q['id']; return TRUE; /*登陆成功*/ } else { return $this->set_err(104, 'Wrong user name and password combination.'); } } else { return $this->set_err(104, 'Wrong user name and password combination.'); } }
/** * set the atm id for current user * [precondition] Has never setted the ATM yet * @param string The Amazon Mechanical Turk ID * @return boolean Whether successfully set the Amazon Mechanical Turk ID */ public function setatmid($atm_id) { if (!$this->is_login(FALSE)) { $this->set_err(400, "No permission."); return FALSE; } // will generate a pay pin if the atm id doesn't exist $pid = $this->get_parti_id(); $query = parent::readByPk($pid); if (empty($query)) { $this->set_err(406, "Data corrupted."); return FALSE; } // use the old pay pin if that doesn't exsits. $pay_pin = $query['pay_pin']; if (empty($pay_pin)) { $this->load->helper('string'); $pay_pin = random_string('alnum', 16); } return parent::updateByPk(["amt_id" => empty($atm_id) ? 0 : $atm_id, "pay_pin" => $pay_pin], $pid); }