root/luci/trunk/modules/admin-full/luasrc/model/cbi/admin_system/passwd.lua @ 3863

Revision 3863, 1.0 KB (checked in by Cyrus, 5 years ago)

System Password: Prevent error when both password fields are empty

  • Property svn:keywords set to Id
Line 
1--[[
2LuCI - Lua Configuration Interface
3
4Copyright 2008 Steven Barth <steven@midlink.org>
5Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
6
7Licensed under the Apache License, Version 2.0 (the "License");
8you may not use this file except in compliance with the License.
9You may obtain a copy of the License at
10
11    http://www.apache.org/licenses/LICENSE-2.0
12
13$Id$
14]]--
15f = SimpleForm("password", translate("a_s_changepw"), translate("a_s_changepw1"))
16
17pw1 = f:field(Value, "pw1", translate("password"))
18pw1.password = true
19pw1.rmempty = false
20
21pw2 = f:field(Value, "pw2", translate("confirmation"))
22pw2.password = true
23pw2.rmempty = false
24
25function pw2.validate(self, value, section)
26    return pw1:formvalue(section) == value and value
27end
28
29function f.handle(self, state, data)
30    if state == FORM_VALID then
31        local stat = luci.sys.user.setpasswd("root", data.pw1) == 0
32       
33        if stat then
34            f.message = translate("a_s_changepw_changed")
35        else
36            f.errmessage = translate("unknownerror")
37        end
38       
39        data.pw1 = nil
40        data.pw2 = nil
41    end
42    return true
43end
44
45return f
Note: See TracBrowser for help on using the browser.