Exemple #1
0
def api_authGuestLogin(simulation_type):
    """You have to be an anonymous or logged in user at this point"""
    t = sirepo.template.assert_sim_type(simulation_type)
    # if already logged in as guest, just redirect
    if auth.user_if_logged_in(AUTH_METHOD):
        return auth.login_success_redirect(t)
    return auth.login(this_module, sim_type=t)
Exemple #2
0
def api_authGuestLogin(simulation_type):
    """You have to be an anonymous or logged in user at this point"""
    req = http_request.parse_params(type=simulation_type)
    # if already logged in as guest, just redirect
    if auth.user_if_logged_in(AUTH_METHOD):
        auth.login_success_response(req.type)
    auth.login(this_module, sim_type=req.type)
    raise AssertionError('auth.login returned unexpectedly')
Exemple #3
0
def _user_with_email_is_logged_in():
    uid = auth.user_if_logged_in(method='email')
    if not uid:
        return None
    u = AuthEmailUser.search_by(uid=uid)
    if u and u.user_name == u.unverified_email:
        return uid
    return None
Exemple #4
0
def test_migration():
    """See if user gets migrated"""
    from pykern.pkunit import pkeq, pkok, pkexcept, work_dir
    from pykern.pkdebug import pkdp
    from sirepo import auth

    # deprecated methods raise Unauthorized, but still login
    with pkexcept('UNAUTHORIZED'):
        auth.login(auth.github, uid='jeTJR5G4')
    # verify logged in
    pkeq('jeTJR5G4', auth.user_if_logged_in('github'))
    pkok(work_dir().join('db/auth.db').exists(), 'auth.db does not exist')
Exemple #5
0
def api_authEmailAuthorized(simulation_type, token):
    """Clicked by user in an email

    Token must exist in db and not be expired.
    """
    if http_request.is_spider():
        sirepo.util.raise_forbidden('robots not allowed')
    req = http_request.parse_params(type=simulation_type)
    with auth_db.thread_lock:
        u = AuthEmailUser.search_by(token=token)
        if u and u.expires >= srtime.utc_now():
            n = _verify_confirm(req.type, token,
                                auth.need_complete_registration(u))
            u.query.filter(
                (AuthEmailUser.user_name == u.unverified_email),
                AuthEmailUser.unverified_email != u.unverified_email,
            ).delete()
            u.user_name = u.unverified_email
            u.token = None
            u.expires = None
            u.save()
            auth.login(this_module, sim_type=req.type, model=u, display_name=n)
            raise AssertionError('auth.login returned unexpectedly')
        if not u:
            pkdlog('login with invalid token={}', token)
        else:
            pkdlog(
                'login with expired token={}, email={}',
                token,
                u.unverified_email,
            )
        # if user is already logged in via email, then continue to the app
        if auth.user_if_logged_in(AUTH_METHOD):
            pkdlog(
                'user already logged in. ignoring invalid token: {}, user: {}',
                token,
                auth.logged_in_user(),
            )
            raise sirepo.util.Redirect(sirepo.uri.local_route(req.type))
        auth.login_fail_redirect(req.type, this_module, 'email-token')