emacs-collab/lib/emacscollab/user.rb

47 lines
911 B
Ruby
Raw Permalink Normal View History

module EmacsCollab
class User
attr_accessor :id, :keypath, :pw_hash, :salt, :keys
def to_s
"#{@id}"
end
def initialize(id)
@id = id
@keypath = "#{USER_LOCATION}#{id}"
end
def add_key_from_string(keystring)
unless EmacsCollab.valid_pubkey? keystring
raise InvalidSSHPubKey, "Public key not valid"
end
ks = keystring.split(" ");
key = SSHKey.new(ks[0][4..6], ks[1], ks[2])
unless @keys.include? key
@keys << key
else
raise DuplicateSSHPubKey, "Public key is already added to user"
end
p self
flush
EmacsCollab.flush_projects_with_user(self)
end
def remove_key(key)
@keys.delete(key)
flush
EmacsCollab.flush_projects_with_user(self)
end
def flush
$db.update_user(self)
end
end
class UserNotFoundError < StandardError
end
end