From 8b03bc4da15b75c0059f5e58c611314ea7dad5b4 Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Wed, 29 May 2019 15:30:23 +0200 Subject: [PATCH] WIP Passwd#mod_user --- src/passwd.cr | 19 +++++++++++++++++++ src/user.cr | 2 ++ 2 files changed, 21 insertions(+) diff --git a/src/passwd.cr b/src/passwd.cr index 40ef618..11bd3fb 100644 --- a/src/passwd.cr +++ b/src/passwd.cr @@ -171,6 +171,25 @@ class Passwd File.write(@group, group.to_csv + "\n", mode: "a") end + + # FIXME: Edit other important fields. + def mod_user(uid, password_hash : String? = nil) + new_passwd = passwd_as_array.map do |line| + user = AuthD::User.new line + + if uid == user.uid + password_hash.try do |hash| + user.password_hash = hash + end + + user.to_csv + else + line.join(':') + "\n" + end + end + + puts new_passwd.join + end end class AuthD::Group diff --git a/src/user.cr b/src/user.cr index a112322..49b27bb 100644 --- a/src/user.cr +++ b/src/user.cr @@ -1,4 +1,6 @@ +require "json" + class AuthD::User getter login : String getter password_hash : String