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