modules/admin-mini: General UI improvements
[project/luci.git] / modules / admin-mini / luasrc / model / cbi / mini / 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                 
31                 if stat then
32                         f.message = translate("a_s_changepw_changed")
33                 else
34                         f.errmessage = translate("unknownerror")
35                 end
36                 
37                 data.pw1 = nil
38                 data.pw2 = nil
39         end
40         return true
41 end
42
43 return f