Login refactor for iOS and Rails

@fzf @drn