Problem: credentials were only set implicitly on first :CP submit. There was no way to update wrong credentials, log out, or set credentials ahead of time without editing the cache JSON manually. Solution: add :CP login [platform] which always prompts for username and password and overwrites any saved credentials for that platform. Omitting the platform falls back to the active platform. Wire the command through constants, parse_command, handle_command, and add tab-completion (suggests platform names). Document in vimdoc under the SUBMIT section and in the commands reference.
32 lines
943 B
Lua
32 lines
943 B
Lua
local M = {}
|
|
|
|
local cache = require('cp.cache')
|
|
local logger = require('cp.log')
|
|
local state = require('cp.state')
|
|
|
|
function M.login(platform)
|
|
platform = platform or state.get_platform()
|
|
if not platform then
|
|
logger.log('No platform specified. Usage: :CP login <platform>', vim.log.levels.ERROR)
|
|
return
|
|
end
|
|
|
|
vim.ui.input({ prompt = platform .. ' username: ' }, function(username)
|
|
if not username or username == '' then
|
|
logger.log('Login cancelled', vim.log.levels.WARN)
|
|
return
|
|
end
|
|
vim.fn.inputsave()
|
|
local password = vim.fn.inputsecret(platform .. ' password: ')
|
|
vim.fn.inputrestore()
|
|
if not password or password == '' then
|
|
logger.log('Login cancelled', vim.log.levels.WARN)
|
|
return
|
|
end
|
|
cache.load()
|
|
cache.set_credentials(platform, { username = username, password = password })
|
|
logger.log(platform .. ' credentials saved', vim.log.levels.INFO)
|
|
end)
|
|
end
|
|
|
|
return M
|