$_SESSION["login_code"]]);
if ($uidinfo["status"] == "ERROR") {
throw new Exception();
}
if (is_numeric($uidinfo['uid'])) {
$user = new User($uidinfo['uid'] * 1);
foreach ($SETTINGS['permissions'] as $perm) {
if (!$user->hasPermission($perm)) {
showHTML("no access permission", "", "");
die();
}
}
$addpassresp = AccountHubApi::get(
"addapppassword",
[
"desc" => $SETTINGS["site_title"] . " - Nextcloud Notes API",
"username" => $user->getUsername()
],
true
);
$_SESSION["login_code"] = null;
$redirecturl = "nc://login/server:" . htmlentities($appurl) . "&user:" . htmlentities($user->getUsername()) . "&password:" . htmlentities($addpassresp["pass"]);
header("Location: $redirecturl");
die("Click here");
} else {
throw new Exception();
}
} catch (Exception $ex) {
$redirecttologin = true;
}
}
if ($redirecttologin) {
try {
$codedata = AccountHubApi::get("getloginkey", ["appname" => $SETTINGS["site_title"], "appicon" => $iconurl]);
if ($codedata['status'] != "OK") {
throw new Exception($Strings->get("login server unavailable", false));
}
$_SESSION["login_code"] = $codedata["code"];
$locationurl = $codedata["loginurl"] . "?code=" . htmlentities($codedata["code"]) . "&redirect=" . htmlentities($thisurl);
header("Location: $locationurl");
showHTML("Continue", "Continue", $locationurl);
die();
} catch (Exception $ex) {
sendError($ex->getMessage());
}
}