2017-06-04 18:42:43 +00:00
|
|
|
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)
|
2017-06-15 00:20:13 +00:00
|
|
|
unless EmacsCollab.valid_pubkey? keystring
|
2017-06-04 18:42:43 +00:00
|
|
|
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
|
2017-06-15 00:20:13 +00:00
|
|
|
p self
|
2017-06-04 18:42:43 +00:00
|
|
|
flush
|
2017-06-15 00:20:13 +00:00
|
|
|
EmacsCollab.flush_projects_with_user(self)
|
2017-06-04 18:42:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove_key(key)
|
|
|
|
@keys.delete(key)
|
|
|
|
flush
|
2017-06-15 00:20:13 +00:00
|
|
|
EmacsCollab.flush_projects_with_user(self)
|
2017-06-04 18:42:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def flush
|
2017-06-15 00:20:13 +00:00
|
|
|
$db.update_user(self)
|
2017-06-04 18:42:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class UserNotFoundError < StandardError
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|