Exemplo n.º 1
0
Arquivo: main.py Projeto: daf/ion-ux
def userprofile():
    if not session.has_key('user_id'):
        return redirect('/')
    is_registered = False
    if session.has_key('is_registered'):
        is_registered = session['is_registered']
    user_id = session['user_id']

    if request.is_xhr:
        if request.method == 'GET':
            # determine if this is an update or a new registration
            if is_registered:
                resp_data = ServiceApi.find_user_info(user_id)
            else:
                resp_data = {'contact': {'name': '', 'email': '', 'phone': '', 'address': '', 'city': '', 'postalcode': ''}}
            return jsonify(data=resp_data)
        else:
            form_data = json.loads(request.data)
            if is_registered:
                ServiceApi.update_user_info(form_data)
            else:
                ServiceApi.create_user_info(user_id, form_data)
        
            # indicate user is registered
            session['is_registered'] = True

            resp_data = {"success":True}            
            return jsonify(data=resp_data)
    else:
        return render_app_template(request.path)
Exemplo n.º 2
0
def userprofile():
    if not session.has_key('user_id'):
        return redirect('/')
    is_registered = False
    if session.has_key('is_registered'):
        is_registered = session['is_registered']
    user_id = session['user_id']

    if request.is_xhr:
        if request.method == 'GET':
            # determine if this is an update or a new registration
            if is_registered:
                resp_data = ServiceApi.find_user_info(user_id)
            else:
                resp_data = {
                    'contact': {
                        'name': '',
                        'email': '',
                        'phone': '',
                        'address': '',
                        'city': '',
                        'postalcode': ''
                    }
                }
            return jsonify(data=resp_data)
        else:
            form_data = json.loads(request.data)
            if is_registered:
                ServiceApi.update_user_info(form_data)
            else:
                ServiceApi.create_user_info(user_id, form_data)

            # indicate user is registered
            session['is_registered'] = True

            resp_data = {"success": True}
            return jsonify(data=resp_data)
    else:
        return render_app_template(request.path)
Exemplo n.º 3
0
def userprofile():
    if not session.has_key('user_id'):
        return redirect('/')
    is_registered = False
    if session.has_key('is_registered'):
        is_registered = session['is_registered']
    user_id = session['user_id']

    if request.is_xhr:
        if request.method == 'GET':
            # determine if this is an update or a new registration
            if is_registered:
                resp_data = ServiceApi.find_user_info(session['actor_id'])
            else:
                # try to extract name from UserCredentials
                creds = ServiceApi.find_user_credentials_by_actor_id(
                    session['actor_id'])
                cntoken = creds['name']
                name = ''
                individual_names_given = ''
                individual_name_family = ''

                try:
                    rcn = re.compile(r'CN=(.*)\sA.+')
                    m = rcn.search(cntoken)
                    if m is not None:
                        name = m.groups()[0]

                        individual_names_given, individual_name_family = name.split(
                            ' ', 1)
                except:
                    pass

                resp_data = {
                    'name': name,
                    'contact': {
                        'individual_names_given': individual_names_given,
                        'individual_name_family': individual_name_family
                    }
                }

            return jsonify(data=resp_data)
        else:
            form_data = json.loads(request.data)
            if is_registered:
                resp_data = ServiceApi.update_user_info(form_data)

                if isinstance(resp_data,
                              dict) and resp_data.has_key('GatewayError'):
                    return render_json_response(resp_data)
                else:
                    # only thing that can change here for session is name
                    session['name'] = form_data['name']

            else:
                user_id = ServiceApi.create_user_info(session['actor_id'],
                                                      form_data)

                if isinstance(user_id,
                              dict) and user_id.has_key('GatewayError'):
                    return render_json_response(user_id)
                else:
                    # simulate a signon by setting appropriate session vars
                    session['is_registered'] = True
                    session['user_id'] = user_id
                    session['roles'] = ServiceApi.get_roles_by_actor_id(
                        session['actor_id'])
                    session['name'] = form_data['name']
                    #session['valid_until']  = 0     # @TODO: howto? only in certificate, so logon?

            resp_data = {"success": True}
            return jsonify(data=resp_data)
    else:
        return render_app_template(request.path)
Exemplo n.º 4
0
def userprofile():
    if not session.has_key('user_id'):
        return redirect('/')
    is_registered = False
    if session.has_key('is_registered'):
        is_registered = session['is_registered']
    user_id = session['user_id']

    if request.is_xhr:
        if request.method == 'GET':
            # determine if this is an update or a new registration
            if is_registered:
                resp_data = ServiceApi.find_user_info(session['actor_id'])
            else:
                # try to extract name from UserCredentials
                creds = ServiceApi.find_user_credentials_by_actor_id(session['actor_id'])
                cntoken = creds['name']
                name = ''
                individual_names_given = ''
                individual_name_family = ''

                try:
                    rcn = re.compile(r'CN=(.*)\sA.+')
                    m = rcn.search(cntoken)
                    if m is not None:
                        name = m.groups()[0]

                        individual_names_given, individual_name_family = name.split(' ', 1)
                except:
                    pass

                resp_data = {'name':name,
                             'contact':{'individual_names_given':individual_names_given,
                                        'individual_name_family':individual_name_family}}

            return jsonify(data=resp_data)
        else:
            form_data = json.loads(request.data)
            if is_registered:
                resp_data = ServiceApi.update_user_info(form_data)

                if isinstance(resp_data, dict) and resp_data.has_key('GatewayError'):
                    return render_json_response(resp_data)
                else:
                    # only thing that can change here for session is name
                    session['name'] = form_data['name']

            else:
                user_id = ServiceApi.create_user_info(session['actor_id'], form_data)

                if isinstance(user_id, dict) and user_id.has_key('GatewayError'):
                    return render_json_response(user_id)
                else:
                    # simulate a signon by setting appropriate session vars
                    session['is_registered'] = True
                    session['user_id']       = user_id
                    session['roles']         = ServiceApi.get_roles_by_actor_id(session['actor_id'])
                    session['name']          = form_data['name']
                    #session['valid_until']  = 0     # @TODO: howto? only in certificate, so logon?

            resp_data = {"success":True}
            return jsonify(data=resp_data)
    else:
        return render_app_template(request.path)