Avatar update through ModUserRequest.
This commit is contained in:
parent
6a19ff604a
commit
c642851165
@ -58,7 +58,8 @@ module AuthD
|
||||
class ModUserRequest
|
||||
JSON.mapping({
|
||||
uid: Int32,
|
||||
password: String?
|
||||
password: String?,
|
||||
avatar: String?
|
||||
})
|
||||
end
|
||||
|
||||
@ -143,7 +144,7 @@ module AuthD
|
||||
end
|
||||
end
|
||||
|
||||
def mod_user(uid : Int32, password : String?) : Bool | Exception
|
||||
def mod_user(uid : Int32, password : String? = nil, avatar : String? = nil) : Bool | Exception
|
||||
payload = Hash(String, String|Int32).new
|
||||
payload["uid"] = uid
|
||||
|
||||
@ -151,6 +152,10 @@ module AuthD
|
||||
payload["password"] = password
|
||||
end
|
||||
|
||||
avatar.try do |avatar|
|
||||
payload["avatar"] = avatar
|
||||
end
|
||||
|
||||
send RequestTypes::ModUser, payload.to_json
|
||||
|
||||
response = read
|
||||
|
@ -133,7 +133,9 @@ IPC::Service.new "auth" do |event|
|
||||
Passwd.hash_password s
|
||||
end
|
||||
|
||||
passwd.mod_user request.uid, password_hash: password_hash
|
||||
avatar = request.avatar
|
||||
|
||||
passwd.mod_user request.uid, password_hash: password_hash, avatar: avatar
|
||||
|
||||
client.send ResponseTypes::Ok, ""
|
||||
end
|
||||
|
@ -1,5 +1,6 @@
|
||||
require "csv"
|
||||
require "uuid"
|
||||
require "base64"
|
||||
|
||||
require "./user.cr"
|
||||
require "./group.cr"
|
||||
@ -175,7 +176,7 @@ class Passwd
|
||||
end
|
||||
|
||||
# FIXME: Edit other important fields.
|
||||
def mod_user(uid, password_hash : String? = nil)
|
||||
def mod_user(uid, password_hash : String? = nil, avatar : String? = nil)
|
||||
new_passwd = passwd_as_array.map do |line|
|
||||
user = AuthD::User.new line
|
||||
|
||||
@ -184,6 +185,10 @@ class Passwd
|
||||
user.password_hash = hash
|
||||
end
|
||||
|
||||
avatar.try do |avatar|
|
||||
user.avatar = avatar
|
||||
end
|
||||
|
||||
user.to_csv
|
||||
else
|
||||
line.join(':') + "\n"
|
||||
@ -222,7 +227,15 @@ class AuthD::User
|
||||
@office_phone_number = gecos[2]?
|
||||
@home_phone_number = gecos[3]?
|
||||
@other_contact = gecos[4]?
|
||||
@avatar = gecos[5]? # CAUTION: NON-STANDARD EXTENSION
|
||||
|
||||
# CAUTION: NON-STANDARD EXTENSION
|
||||
@avatar = gecos[5]?.try do |x|
|
||||
if x != ""
|
||||
Base64.decode_string x
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# FIXME: What about those two fields? Keep them, remove them?
|
||||
@ -235,7 +248,7 @@ class AuthD::User
|
||||
end
|
||||
|
||||
def gecos
|
||||
unless @location || @office_phone_number || @home_phone_number || @other_contact
|
||||
unless @location || @office_phone_number || @home_phone_number || @other_contact || @avatar
|
||||
if @full_name
|
||||
return @full_name
|
||||
else
|
||||
@ -243,7 +256,7 @@ class AuthD::User
|
||||
end
|
||||
end
|
||||
|
||||
[@full_name || "", @location || "", @office_phone_number || "", @home_phone_number || "", @other_contact || ""].join ","
|
||||
[@full_name || "", @location || "", @office_phone_number || "", @home_phone_number || "", @other_contact || "", Base64.strict_encode(@avatar || "")].join ","
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2,10 +2,10 @@
|
||||
require "json"
|
||||
|
||||
class AuthD::User
|
||||
getter login : String
|
||||
getter password_hash : String
|
||||
getter uid : Int32
|
||||
getter gid : Int32
|
||||
getter login : String
|
||||
getter password_hash : String
|
||||
getter home : String = "/"
|
||||
getter shell : String = "/bin/nologin"
|
||||
getter groups = Array(String).new
|
||||
@ -27,7 +27,8 @@ class AuthD::User
|
||||
full_name: String?,
|
||||
office_phone_number: String?,
|
||||
home_phone_number: String?,
|
||||
other_contact: String?
|
||||
other_contact: String?,
|
||||
avatar: String?
|
||||
})
|
||||
|
||||
def initialize(@login, @password_hash, @uid, @gid, @home, @shell)
|
||||
|
Loading…
Reference in New Issue
Block a user