예제 #1
0
def api_comsolRegister():
    import flask
    import flask_mail
    import sirepo.util

    global _mail
    if not _mail:
        a = sirepo.util.flask_app()
        a.config.update(
            MAIL_USE_TLS=True,
            MAIL_PORT=587,
            MAIL_SERVER=cfg.mail_server,
            MAIL_USERNAME=cfg.mail_username,
            MAIL_PASSWORD=cfg.mail_password,
        )
        _mail = flask_mail.Mail(a)
    req = http_request.parse_json()
    msg = flask_mail.Message(
        subject='Sirepo / COMSOL Registration',
        sender=cfg.mail_support_email,
        recipients=[cfg.mail_recipient_email],
        body=u'''
Request for access to Sirepo / COMSOL.

Name: {}
Email: {}
'''.format(req.name, req.email),
    )
    _mail.send(msg)
    return http_reply.gen_json_ok()
예제 #2
0
파일: server.py 프로젝트: yeeon/sirepo
def api_copyNonSessionSimulation():
    req = http_request.parse_json()
    sim_type = req['simulationType']
    src = py.path.local(
        simulation_db.find_global_simulation(
            sim_type,
            req['simulationId'],
            checked=True,
        ))
    data = simulation_db.open_json_file(
        sim_type,
        src.join(simulation_db.SIMULATION_DATA_FILE),
    )
    if 'report' in data:
        del data['report']
    data['models']['simulation']['isExample'] = False
    data['models']['simulation']['outOfSessionSimulationId'] = req[
        'simulationId']
    res = _save_new_and_reply(data)
    target = simulation_db.simulation_dir(sim_type,
                                          simulation_db.parse_sid(data))
    template_common.copy_lib_files(
        data,
        simulation_db.lib_dir_from_sim_dir(src),
        simulation_db.lib_dir_from_sim_dir(target),
    )
    template = sirepo.template.import_module(data)
    if hasattr(template, 'copy_related_files'):
        template.copy_related_files(data, str(src), str(target))
    return res
예제 #3
0
def _verify_confirm(sim_type, token, need_complete_registration):
    m = flask.request.method
    if m == 'GET':
        raise sirepo.util.Redirect(
            sirepo.uri.local_route(
                sim_type,
                'loginWithEmailConfirm',
                PKDict(
                    token=token,
                    needCompleteRegistration=need_complete_registration,
                ),
            ), )
    assert m == 'POST', 'unexpect http method={}'.format(m)
    d = http_request.parse_json()
    if d.get('token') != token:
        raise sirepo.util.Error(
            PKDict(
                error='unable to confirm login',
                sim_type=sim_type,
            ),
            'Expected token={} in data but got data.token={}',
            token,
            d,
        )
    return d.get('displayName')
예제 #4
0
def api_authCompleteRegistration():
    # Needs to be explicit, because we would need a special permission
    # for just this API.
    if not _is_logged_in():
        raise util.SRException(LOGIN_ROUTE_NAME, None)
    complete_registration(
        _parse_display_name(http_request.parse_json().get('displayName')), )
    return http_reply.gen_json_ok()
예제 #5
0
파일: server.py 프로젝트: JiayangY/sirepo
def api_getServerData():
    input = http_request.parse_json()
    #TODO(robnagler) validate
    id = input.id if 'id' in input else None
    d = adm.get_server_data(id)
    if d == None or len(d) == 0:
        raise sirepo.util.UserAlert('Data error', 'no data supplied')
    return http_reply.gen_json(d)
예제 #6
0
파일: server.py 프로젝트: yeeon/sirepo
def api_copySimulation():
    """Takes the specified simulation and returns a newly named copy with the suffix ( X)"""
    req = http_request.parse_json()
    sim_type = req.simulationType
    name = req.name
    assert name, util.err(req, 'No name in request')
    folder = req.folder if 'folder' in req else '/'
    data = simulation_db.read_simulation_json(sim_type, sid=req.simulationId)
    data.models.simulation.name = name
    data.models.simulation.folder = folder
    data.models.simulation.isExample = False
    data.models.simulation.outOfSessionSimulationId = ''
    return _save_new_and_reply(data)
예제 #7
0
def api_deleteFile():
    req = http_request.parse_json()
    filename = werkzeug.secure_filename(req['fileName'])
    search_name = _lib_filename(req['simulationType'], filename, req['fileType'])
    err = _simulations_using_file(req['simulationType'], req['fileType'], search_name)
    if len(err):
        return http_reply.gen_json({
            'error': 'File is in use in other simulations.',
            'fileList': err,
            'fileName': filename,
        })
    p = _lib_filepath(req['simulationType'], filename, req['fileType'])
    pkio.unchecked_remove(p)
    return http_reply.gen_json({})
예제 #8
0
파일: bluesky.py 프로젝트: e-carlin/sirepo
def api_blueskyAuth():
    req = http_request.parse_json()
    auth_hash(req, verify=True)
    sid = req.simulationId
    sim_type = req.simulationType
    path = simulation_db.find_global_simulation(
        sim_type,
        sid,
        checked=True,
    )
    cookie.set_user(simulation_db.uid_from_dir_name(path))
    return http_reply.gen_json_ok(dict(
        data=simulation_db.open_json_file(req.simulationType, sid=req.simulationId),
        schema=simulation_db.get_schema(req.simulationType),
    ))
예제 #9
0
def api_comsolRegister():
    req = http_request.parse_json()
    msg = flask_mail.Message(
        subject='Sirepo / COMSOL Registration',
        sender=cfg.mail_support_email,
        recipients=[cfg.mail_recipient_email],
        body=u'''
Request for access to Sirepo / COMSOL.

Name: {}
Email: {}
'''.format(req.name, req.email),
    )
    _mail.send(msg)
    return http_reply.gen_json_ok()
예제 #10
0
def api_comsolRegister():
    import sirepo.util

    req = http_request.parse_json()
    smtp.send(
        recipient=cfg.mail_recipient_email,
        subject='Sirepo / COMSOL Registration',
        body=u'''
Request for access to Sirepo / COMSOL.

Name: {}
Email: {}
'''.format(req.name, req.email),
    )
    return http_reply.gen_json_ok()
예제 #11
0
def api_comsolRegister():
    req = http_request.parse_json()
    msg = flask_mail.Message(
        subject='Sirepo / COMSOL Registration',
        sender=cfg.mail_support_email,
        recipients=[cfg.mail_recipient_email],
        body=u'''
Request for access to Sirepo / COMSOL.

Name: {}
Email: {}
'''.format(req.name, req.email),
    )
    _mail.send(msg)
    return http_reply.gen_json_ok()
예제 #12
0
def api_authCompleteRegistration():
    # Needs to be explicit, because we would need a special permission
    # for just this API.
    if not _is_logged_in():
        return http_reply.gen_sr_exception(LOGIN_ROUTE_NAME)
    d = http_request.parse_json()
    t = d.simulationType
    n = _parse_display_name(d)
    u = _get_user()
    with auth_db.thread_lock:
        r = _user_registration(u)
        r.display_name = n
        r.save()
    cookie.set_value(_COOKIE_STATE, _STATE_LOGGED_IN)
    return http_reply.gen_json_ok()
예제 #13
0
def api_errorLogging():
    ip = flask.request.remote_addr
    try:
        pkdlog(
            '{}: javascript error: {}',
            ip,
            simulation_db.generate_json(http_request.parse_json(), pretty=True),
        )
    except ValueError as e:
        pkdlog(
            '{}: error parsing javascript app_error: {} input={}',
            ip,
            e,
            flask.request.data.decode('unicode-escape'),
        )
    return http_reply.gen_json_ok()
예제 #14
0
def api_blueskyAuth():
    req = http_request.parse_json()
    auth_hash(req, verify=True)
    sid = req.simulationId
    sim_type = req.simulationType
    path = simulation_db.find_global_simulation(
        sim_type,
        sid,
        checked=True,
    )
    cookie.set_user(simulation_db.uid_from_dir_name(path))
    return http_reply.gen_json_ok(
        dict(
            data=simulation_db.open_json_file(req.simulationType,
                                              sid=req.simulationId),
            schema=simulation_db.get_schema(req.simulationType),
        ))
예제 #15
0
def api_authBlueskyLogin():
    req = http_request.parse_json()
    auth_hash(req, verify=True)
    sid = req.simulationId
    sim_type = req.simulationType
    path = simulation_db.find_global_simulation(
        sim_type,
        sid,
        checked=True,
    )
    r = auth.login(
        this_module,
        uid=simulation_db.uid_from_dir_name(path),
    )
    if r:
        return r
    return http_reply.gen_json_ok(dict(
        data=simulation_db.open_json_file(req.simulationType, sid=req.simulationId),
        schema=simulation_db.get_schema(req.simulationType),
    ))
예제 #16
0
def api_authEmailLogin():
    """Start the login process for the user.

    User has sent an email, which needs to be verified.
    """
    data = http_request.parse_json()
    email = _parse_email(data)
    t = data.simulationType
    with auth_db.thread_lock:
        u = AuthEmailUser.search_by(unverified_email=email)
        if not u:
            u = AuthEmailUser(unverified_email=email)
        u.token = u.create_token()
        u.save()
    return _send_login_email(
        u,
        uri_router.uri_for_api(
            'authEmailAuthorized',
            dict(simulation_type=t, token=u.token),
        ),
    )
예제 #17
0
def api_copySimulation():
    """Takes the specified simulation and returns a newly named copy with the suffix (copy X)"""
    req = http_request.parse_json()
    sim_type = req['simulationType']
    name = req['name'] if 'name' in req else None
    folder = req['folder'] if 'folder' in req else '/'
    data = simulation_db.read_simulation_json(sim_type, sid=req['simulationId'])
    if not name:
        base_name = data['models']['simulation']['name']
        names = simulation_db.iterate_simulation_datafiles(sim_type, _simulation_name)
        count = 0
        while True:
            count += 1
            name = base_name + ' (copy{})'.format(' {}'.format(count) if count > 1 else '')
            if name in names and count < 100:
                continue
            break
    data['models']['simulation']['name'] = name
    data['models']['simulation']['folder'] = folder
    data['models']['simulation']['isExample'] = False
    data['models']['simulation']['outOfSessionSimulationId'] = ''
    return _save_new_and_reply(data)
예제 #18
0
파일: server.py 프로젝트: yeeon/sirepo
def _parse_data_input(validate=False):
    data = http_request.parse_json(assert_sim_type=False)
    return simulation_db.fixup_old_data(data)[0] if validate else data