Hi everyone,
I'm developing a custom luci web page for openwrt 19.07,
I want to redirect user to reset their default password after their first login.
So, I add an entry in network.lua
page = entry({"system", "login", "first"}, form("first"), _("Change Password"), nil)
some line in dispatcher.lua
to redirect user to first.lua
,
which I refer to passwd.lua
in luci-mod-admin-mini
.
f = SimpleForm("password", translate("Admin Password"), translate("Change the password of the system administrator (User <code>root</code>)"))
pw1 = f:field(Value, "pw1", translate("Password"))
pw1.password = true
pw1.rmempty = false
pw2 = f:field(Value, "pw2", translate("Confirmation"))
pw2.password = true
pw2.rmempty = false
function pw2.validate(self, value, section)
return pw1:formvalue(section) == value and value
end
function f.handle(self, state, data)
if state == FORM_VALID then
local state = luci.sys.user.setpasswd("root", data.pw1) == 0
if state then
f.message = translate("Password successfully changed")
else
f.errmessage = translate("Unknown Error")
end
data.pw1 = nil
data.pw2 = nil
end
return true
end
return f
The page display normally, but click submit button on this page will cause "Form token mismatch" error.
Can anyone help me find where I did wrong?
Thanks!