diff --git a/system/blueprints/user/account.yaml b/system/blueprints/user/account.yaml new file mode 100644 index 000000000..9bfef3f03 --- /dev/null +++ b/system/blueprints/user/account.yaml @@ -0,0 +1,81 @@ +title: Site +form: + validation: loose + fields: + + content: + type: section + title: Account + + fields: + username: + type: unset + + password: + type: password + size: large + label: Password + validate: + required: true + + email: + type: text + size: large + label: Email + validate: + required: true + + fullname: + type: text + size: large + label: Full name + validate: + required: true + + title: + type: text + size: large + label: Title + + admin: + type: section + title: Admin Access + + fields: + access.admin.super: + type: toggle + label: Super user + default: 0 + highlight: 1 + options: + 1: Yes + 0: No + validate: + type: bool + + access.admin.login: + type: toggle + label: Admin login + default: 0 + highlight: 1 + options: + 1: Yes + 0: No + validate: + type: bool + + site: + type: section + title: Site Access + + fields: + access.site.login: + type: toggle + label: Site login + default: 1 + highlight: 1 + options: + 1: Yes + 0: No + validate: + type: bool diff --git a/system/src/Grav/Common/User/User.php b/system/src/Grav/Common/User/User.php index 678085c13..e9626eda4 100644 --- a/system/src/Grav/Common/User/User.php +++ b/system/src/Grav/Common/User/User.php @@ -1,7 +1,9 @@ exists(). + * + * @param string $username + * @return User + */ + public static function load($username) + { + // FIXME: validate directory name + $blueprints = new Blueprints('blueprints://user'); + $blueprint = $blueprints->get('account'); + $file = CompiledYamlFile::instance(ACCOUNTS_DIR . $username . YAML_EXT); + $content = $file->content(); + if (!isset($content['username'])) { + $content['username'] = $username; + } + $user = new User($content, $blueprint); + $user->file($file); + + return $user; + } + /** * Authenticate user. *