/** * 登录函数 * @method login * @access private * @author NewFuture[newfuture@yunyin.org] * @param [string] $password [md5密码] * @return [bool/int] [用户id] */ private function login($number, $password, $sch_id = null) { $conditon = ['number' => $number]; //指定学校 $sch_id and $conditon['sch_id'] = $sch_id; $users = UserModel::where($conditon)->select('id,password,sch_id,name'); if (empty($users)) { /*未注册*/ return null; } else { /*验证结果*/ $password = Encrypt::encryptPwd($password, $number); $reg_schools = []; foreach ($users as &$user) { if ($user['password'] == $password) { /*登录成功*/ $user['number'] = $number; $token = Auth::token($user); $sessionid = Session::start(); unset($user['password']); Session::set('user', $user); Cookie::set('token', $token); // $user['school'] = SchoolModel::getName($user['sch_id']); $result = ['sid' => $sessionid, 'user' => $user, 'msg' => '登录成功!', 'token' => $token]; $this->response(1, $result); return true; } else { /*验证失败*/ $sid = $user['sch_id']; $reg_schools[$sid] = School::getAbbr($sid); } } $this->reg_schools = $reg_schools; return false; } }
private function parse(&$s) { /*如果是字符切成数组*/ if (is_string($s)) { $s = explode(',', $s); } /*id转成缩写*/ if (is_numeric(end($s))) { array_walk($s, function (&$v) { $v = School::getAbbr($v); }); } return $s; }