Converted password change form to CBI model
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_system / passwd.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15 f = SimpleForm("password", translate("a_s_changepw"), translate("a_s_changepw1"))
16
17 pw1 = f:field(Value, "pw1", translate("password"))
18 pw1.password = true
19
20 pw2 = f:field(Value, "pw2", translate("confirmation"))
21 pw2.password = true
22
23 function pw2.validate(self, value, section)
24         return pw1:formvalue(section) == value and value
25 end
26
27 function f.handle(self, state, data)
28         if state == FORM_VALID then
29                 local stat = luci.sys.user.setpasswd("root", data.pw1) == 0
30                 local x = f:field(DummyValue, "_stat")
31                 
32                 if stat then
33                         x.value = translate("a_s_changepw_changed")
34                 else
35                         x.value = translate("unknownerror")
36                 end
37                 
38                 pw1.render = function() end
39                 pw2.render = pw1.render
40         end
41         return true
42 end
43
44 return f