Beispiel #1
0
 public function participate($amt_id, $opt_id, $gid, $is_amt_user = FALSE)
 {
     if ($gid === 0 || $gid === "0" || $gid === "") {
         return $this->set_err(104, 'Invalid group id: $gid');
     }
     if (!(empty($amt_id) xor empty($opt_id))) {
         // can't be both true nor both false
         return $this->set_err(105, "Invalid AMTID or NETID information:{$amt_id} , {$opt_id}");
     }
     if ($is_amt_user && empty($amt_id)) {
         return $this->set_err(106, "Use AMT_User login, but doesn't have AMT ID.");
     }
     if (!$is_amt_user && empty($opt_id)) {
         return $this->set_err(107, "Use Guest login, but doesn't provide Participant ID.");
     }
     if ($is_amt_user) {
         $count = parent::count(array('amt_id' => $amt_id, "gid" => $gid));
         if ($count == 0) {
             return $this->addNewParticipant($amt_id, NULL, $gid, $is_amt_user);
         } else {
             return $this->set_err(107, "You have already participated in this experiment. To find more experiments, please visit the AMT page of Cornell Phonetics Lab.");
         }
     } else {
         return $this->addNewParticipant(NULL, $opt_id, $gid, $is_amt_user);
     }
 }
Beispiel #2
0
 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.');
     }
 }
Beispiel #3
0
 public function addGidIntoExpr($expr_id, $gid = NULL)
 {
     if (!isset($gid) || !empty($gid) || parent::count(["gid" => $gid]) > 0) {
         $gid = $this->next_gid();
     }
     $data = parent::readByPk($expr_id, $this->fields);
     if ($data) {
         $data["gid"] = $gid;
         $data["is_forked"] = TRUE;
         // create
         return parent::create($data);
     } else {
         $this->err_msg = "Invalid Experiment ID";
         $this->err_code = 404;
         return FALSE;
     }
 }
 public function count($criteria = array())
 {
     $where = $this->_get_where($criteria);
     return parent::count('alertas', $where);
 }
Beispiel #5
0
 /**
  * Check whether the resource is owned by anyone
  * @param $rsc_type
  * @param $rsc_id
  * @return whether the resources are owned by anyone
  */
 public function is_owned($rsc_type, $rsc_id)
 {
     if (!$this->identity->is_researcher()) {
         return FALSE;
     }
     if (!$this->_check_rsc($rsc_type, $rsc_id)) {
         return FALSE;
     }
     return parent::count(array("rsc_type" => $rsc_type, "rsc_id" => $rsc_id)) != 0;
 }