|
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 | --[[ |
|---|
| 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 | pw1.rmempty = false |
|---|
| 20 | |
|---|
| 21 | pw2 = f:field(Value, "pw2", translate("confirmation")) |
|---|
| 22 | pw2.password = true |
|---|
| 23 | pw2.rmempty = false |
|---|
| 24 | |
|---|
| 25 | function pw2.validate(self, value, section) |
|---|
| 26 | return pw1:formvalue(section) == value and value |
|---|
| 27 | end |
|---|
| 28 | |
|---|
| 29 | function 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 |
|---|
| 43 | end |
|---|
| 44 | |
|---|
| 45 | return f |
|---|