我想设计一个交互式登录程序,这是工作流程:
def login(username, password)
// 1. get login url
// 2. check captcha
has_captcha = check_captcha()
// deal with captcha if necessary
if has_captcha
// 3. return captcha to client
// 4. I should wait until user input the captcha
end
// 5. finally, post login
end
我的问题出在step 3 and step 4
,我的方式是:
server
写信给验证码给mongodb并等待。client
检查mongodb数据是否每5秒更新一次server
还会每隔5秒检查一次mongodb,如果服务器找到mongodb已经被客户端更新,那么从mongodb获取客户端数据,继续登录。但这不是那么优雅,我该如何轻松实现呢?