public function login($f3, $args) { self::check_configuration(); $params = json_decode($f3->get('BODY')); if ($params->username && $params->password) { $login = new DB\Jig\Mapper($this->db, 'users.json'); $temp = $login->find(array('(isset(@userName) && @userName == ?)', $params->username)); if ($temp) { $first = __::first($temp); if (password_verify($params->password, $first['password'])) { $date = new DateTime(); $date->add(new DateInterval('PT' . F3::get('custom.TTL') . 'H')); $out = array('username' => $first['userName'], 'userid' => $first['_id'], 'ttl' => $date->format('Y-m-d H:i:s'), 'roles' => self::get_roles($first['_id'])); $jwt = JWT::encode($out, F3::get('custom.SUPER-KEY')); echo json_encode(array('token' => $jwt, 'data' => array('firstName' => $first['firstName'], 'lastName' => $first['lastName'], 'userName' => $first['userName']))); } else { self::wrong_login(); } } else { self::wrong_login(); } } else { self::wrong_login(); } }
public function check_uniq_value($value, $table, $field_name) { $table = new DB\Jig\Mapper($this->db, "{$table}.json"); $match = $table->find(array("(isset(@{$field_name}) && @{$field_name} == ?)", $value)); if ($match) { self::show_error("{$field_name} must be unique", 409); } }