'Login a user'

@gen.coroutine
def login_user(self, data=None):

    auth_timer = self.statsd.timer('login.authenticate').start()
    authenticated = (yield self.authenticate(data))
    auth_timer.stop(send=False)
    if authenticated:
        username = authenticated['name']
        auth_state = authenticated.get('auth_state')
        user = self.user_from_username(username)
        if (not self.authenticator.enable_auth_state):
            auth_state = None
        (yield user.save_auth_state(auth_state))
        self.db.commit()
        self.set_login_cookie(user)
        self.statsd.incr('login.success')
        self.statsd.timing('login.authenticate.success', auth_timer.ms)
        self.log.info('User    logged    in:    %s', username)
        return user
    else:
        self.statsd.incr('login.failure')
        self.statsd.timing('login.authenticate.failure', auth_timer.ms)
        self.log.warning('Failed    login    for    %s', data.get('username', 'unknown    user'))
