Esempio n. 1
0
def index():
    web.template.create('Maidstone Hackspace - User profile')
    #~ header('User Profile', url='/profile')
    user = get_user_details({'id': current_user.get_id()}).get()

    name = '%s %s' % (user.get('first_name', ''), user.get('last_name', ''))
    web.page.create('%s - Profile' % name)
    web.columns.create()
    
    web.paragraph.create(
        web.images.create(user.get('profile_image', '/static/images/hackspace.png'), name).add_attributes('width', '200').render()
    )
    web.paragraph.add(name)
    web.paragraph.add('%s' % (user.get('email')))
    web.paragraph.add('Last Login %s' % (user.get('last_login', '')))
    web.paragraph.add('Member since %s' % (user.get('created', '')))
    web.paragraph.add('Description %s' % (user.get('description', '')))
    web.columns.append(web.paragraph.render())

    web.paragraph.create(
        web.link.create(
            'Edit Description',
            'Edit Description',
            '/profile/details'
        ).set_classes('ajaxPopup').render())

    web.columns.append(web.paragraph.render())
    web.page.section(web.columns.render())
    web.template.body.append(web.page.render())

    return web.render()
Esempio n. 2
0
def edit_profile():
    user = get_user_details({'id': current_user.get_id()}).get()
    web.form.create('Update your details', '/profile/update')
    web.form.append(name='description', label='Description', placeholder='This is me i am great')
    web.form.append(name='skills', label='skills', placeholder='python, arduino, knitting')
    web.paragraph.create(web.form.render())
    return web.paragraph.render()
 def __init__(self, user_id, active=True):
     self.id = None
     user_details = site_user.get_user_details({'id': user_id}).get()
     self.active = False
     if user_details:
         self.active = True
         #~ self.check_password(user_details.get('password'))
         self.id = user_id
         self.name = user_details.get('username')
def edit_profile():
    user_details = get_user_details({'id': current_user.get_id()}).get() or {}
    if not user_details:
        print('create')
        create_description().execute({'user_id': current_user.get_id()})
    web.form.create('Update your details', '/profile/update')
    web.form.append(name='description', label='Description', placeholder='This is me i am great', value=user_details.get('description') or '')
    web.form.append(name='skills', label='skills', placeholder='python, arduino, knitting', value=user_details.get('skills') or '')
    return web.form.render()
Esempio n. 5
0
def edit_profile():
    user = get_user_details({'id': current_user.get_id()}).get()
    web.form.create('Update your details', '/profile/update')
    web.form.append(name='description',
                    label='Description',
                    placeholder='This is me i am great')
    web.form.append(name='skills',
                    label='skills',
                    placeholder='python, arduino, knitting')
    return web.form.render()
Esempio n. 6
0
 def __init__(self, user_id, active=True):
     print 'logged in ###########'
     print user_id
     user_details = site_user.get_user_details({'id': user_id}).get()
     self.active = False
     print user_details
     if user_details:
         #~ self.check_password(user_details.get('password'))
         self.id = user_id
         self.name = user_details.get('username')
         self.team_id = user_details.get('team_id', 1)
         self.active = active
def update_profile():
    """ handle form submit to update description and skills"""
    data = {
        'user_id': current_user.get_id(),
        'skills': request.form.get('skills'),
        'description': request.form.get('description')}
    user_details = get_user_details({'id': current_user.get_id()}).get() or {}
    if user_details.get('user_detail_id', None) is None:
        create_description().execute(data)
    else:
        update_description().execute(data)
    return redirect('/profile')
def cancel_membership():
    user = get_user_details({'id': current_user.get_id()}).get()
    user_code = str(user.get('user_id')).zfill(5)
    
    subscription = members.fetch_member_subscription({'user_id': current_user.get_id()}).get()
    print(subscription.get('provider_id'))
    print(subscription.get('subscription_reference'))
    
    
    provider = payment(provider='paypal', style='payment')
    provider.lookup_provider_by_id(1)
    url = provider.unsubscribe(reference=subscription.get('subscription_reference'))

    members.update_membership_status().execute({'user_id':current_user.get_id(), 'status': '0'})

    return redirect('/profile')
def pay_membership():
    user = get_user_details({'id': current_user.get_id()}).get()
    user_code = str(user.get('user_id')).zfill(5)

    selected_provider = request.form.get('provider', 'gocardless')
    provider = payment(provider=selected_provider, style='payment')
    success_url = '%s/profile/membership/%s/success' % (app_domain, selected_provider)
    failure_url = '%s/profile/membership/%s/failure' % (app_domain, selected_provider)
    url = provider.subscribe(
        amount=request.form.get('amount'),
        name="Membership your membership id is MH%s" % user_code,
        redirect_success=success_url,
        redirect_failure=failure_url
        )


    return redirect(url)
Esempio n. 10
0
def index():
    web.template.create('Maidstone Hackspace - User profile')
    header('User Profile', url='/profile')
    print current_user
    user = get_user_details({'id': current_user.get_id()}).get()

    name = '%s %s' % (user.get(
        'first_name', '').capitalize(), user.get('last_name', '').capitalize())
    web.page.create('%s - Profile' % name)
    web.columns.create()

    web.paragraph.create(
        web.images.create(
            user.get('profile_image', '/static/images/hackspace.png'),
            name).add_attributes('width', '200').render())
    web.paragraph.add(name)
    web.paragraph.add('%s' % (user.get('email')))
    web.paragraph.add('Last Login %s' % (user.get('last_login', '')))
    web.paragraph.add('Member since %s' % (user.get('created', '')))
    web.paragraph.add('Description %s' % (user.get('description', '')))
    web.columns.append(web.paragraph.render())

    web.paragraph.create(
        web.link.create('Edit Description', 'Edit Description',
                        '/profile/details').set_classes('ajaxPopup').render())

    #~ web.form.create('Join Maidstone Hackspace', '/profile/membership')
    #~ web.form.append(name='amount', label='Subscription Amount', placeholder='20.00', value='20.00')
    #~ web.form.render()

    web.columns.append(web.paragraph.render())
    web.columns.append(
        web.member_card.create(str(user.get('user_id')).zfill(5),
                               name).render())
    web.page.section(web.columns.render())
    web.template.body.append(web.page.render())
    web.template.body.append(web.popup.create('').render())
    return footer()
Esempio n. 11
0
def index():
    web.template.create('Maidstone Hackspace - User profile')
    header('User Profile', url='/profile')
    print current_user
    user = get_user_details({'id': current_user.get_id()}).get()

    name = '%s %s' % (user.get('first_name', '').capitalize(), user.get('last_name', '').capitalize())
    web.page.create('%s - Profile' % name)
    web.columns.create()
    
    web.paragraph.create(
        web.images.create(user.get('profile_image', '/static/images/hackspace.png'), name).add_attributes('width', '200').render()
    )
    web.paragraph.add(name)
    web.paragraph.add('%s' % (user.get('email')))
    web.paragraph.add('Last Login %s' % (user.get('last_login', '')))
    web.paragraph.add('Member since %s' % (user.get('created', '')))
    web.paragraph.add('Description %s' % (user.get('description', '')))
    web.columns.append(web.paragraph.render())

    web.paragraph.create(
        web.link.create(
            'Edit Description',
            'Edit Description',
            '/profile/details'
        ).set_classes('ajaxPopup').render())

    #~ web.form.create('Join Maidstone Hackspace', '/profile/membership')
    #~ web.form.append(name='amount', label='Subscription Amount', placeholder='20.00', value='20.00')
    #~ web.form.render()

    web.columns.append(web.paragraph.render())
    web.columns.append(web.member_card.create(str(user.get('user_id')).zfill(5), name).render())
    web.page.section(web.columns.render())
    web.template.body.append(web.page.render())
    web.template.body.append(web.popup.create('').render())
    return footer()
def oauth(provider, start_oauth_login=False):
    oauth_verify = True
    oauth_provider = oauth_conf.get(provider)
    oauth_access_type = ''
    oauth_approval_prompt = ''
    if oauth_live is False:
        print('offline testing')
        oauth_verify = False
        oauth_access_type = 'offline'
        oauth_approval_prompt = "force"
        os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'

    if start_oauth_login:
        oauth_session = OAuth2Session(
            oauth_provider.get('client_id'), 
            scope=oauth_provider.get('scope'), 
            redirect_uri=request.url_root + oauth_provider.get('redirect_uri'))

        if provider == 'facebook':
            oauth_session = facebook_compliance_fix(oauth_session)

        authorization_url, state = oauth_session.authorization_url(
            oauth_provider.get('auth_uri'),
            access_type=oauth_access_type,
            approval_prompt=oauth_approval_prompt)

        # State is used to prevent CSRF, keep this for later, make sure oauth returns to the same url.
        # if testing and oauth_state errors make sure you logged in with localhost and not 127.0.0.1
        session['oauth_state'] = state
        session.modified = True
        return redirect(authorization_url)

    if session.get('oauth_state', None) is None:
        flash('Something went wrong, oauth session not started')
        return redirect('/login')
    
    # allready authorised so lets handle the callback
    oauth_session = OAuth2Session(
        oauth_provider.get('client_id'), 
        state=session['oauth_state'], 
        redirect_uri=request.url_root + oauth_provider.get('redirect_uri'))

    if provider == 'facebook':
        oauth_session = facebook_compliance_fix(oauth_session)
    

    # code error is todo with authorisation response
    oauth_session.fetch_token(
        oauth_provider.get('token_uri'),
        client_secret=oauth_provider.get('client_secret'),
        authorization_response=request.url,
        verify=oauth_verify)

    # Fetch a protected resource, i.e. user profile
    response = oauth_session.get(oauth_provider.get('user_uri'))
    oauth_response = response.json()
    
    oauth_id = oauth_response.get('login') or oauth_response.get('id')
    provider_id = oauth_lookup_id.get(provider)
    oauth_user = site_user.fetch_oauth_login({
        'username': oauth_id or '',
        'provider': provider_id
    }).get()

    if oauth_user: 
        user_details = site_user.get_user_details({
            'id': oauth_user.get('user_id')
        }).get()

        # we have matched a user so login and redirect
        if user_details:
            login_user(User(user_details.get('user_id')))
            # no E-Mail so lets ask the user to set there email before allowing login
            if not user_details.get('email'):
                return redirect('/profile/change_email')
            return redirect('/profile')

    flash('Your new profile has been created, and your now logged in')

    if current_user.get_id():
        # link oauth to users account
        site_user.create_oauth_login().execute({
            'user_id': current_user.get_id(), 
            'username': oauth_id or '', 
            'provider': provider_id})
        return redirect('/profile')

    # create new user from oauth information

    new_user_details = {
        'password': '******', 
        'profile_image': oauth_response.get('picture'),
        'username': oauth_id,
        'first_name': oauth_response.get('given_name') or '',
        'last_name': oauth_response.get('family_name') or ''}

    if  oauth_response.get('email'):
        new_user_details['email']= oauth_response.get('email')

    user_id = site_user.create().execute(new_user_details)

    # register oauth login creation
    site_user.create_oauth_login().execute({
        'user_id': user_id, 
        'username': oauth_id or '', 
        'provider': provider_id})

    login_user(User(user_id))
    site_user.update_last_login().execute({'id': user_id})
    if not user_id:
        flash('Failed to create user')
        return redirect('/login')
    return redirect('/profile')
def index():
    web.template.create('Maidstone Hackspace - User profile')
    header('User Profile', url='/profile')
    user = get_user_details({'id': current_user.get_id()}).get()
    user_oauth_providers = [provider for provider in get_registered_oauth_providers({'user_id': current_user.get_id()})]

    name = '%s %s' % (
        user.get('first_name', '').capitalize(), 
        user.get('last_name', '').capitalize())
    web.page.create('%s - Profile' % name)

    web.paragraph.create(
        web.images.create(user.get('profile_image', '/static/images/hackspace.png'), name).add_attributes('width', '200').render()
    )
    web.paragraph.add(name)
    web.paragraph.add('%s' % (user.get('email', '') if user.get('email', '') else ''))
    web.paragraph.add('Last Login %s' % (user.get('last_login', '')))
    web.paragraph.add('Member since %s' % (user.get('created', '')))
    web.paragraph.add('Description %s' % (user.get('description', '')))
    web.paragraph.add('Skills %s' % (user.get('skills', '')))
    web.div.create(web.paragraph.render())

    web.paragraph.create(
        web.link.create(
            'Edit Description',
            'Edit Description',
            '/profile/details'
        ).set_classes('ajaxPopup').render())

    web.paragraph.append(
        web.link.create(
            'Link a provider to your account like google, by logging in while logged into your account',
            'Link login provider',
            '/login'
        ).render())
        
    web.table.create('', ('Login providers', 'Last login'))
    for provider in user_oauth_providers:
        web.table.append((
            str(oauth_lookup_name.get(int(provider.get('provider')))), 
            provider.get('last_login') if provider.get('last_login') else 'Unknown'))
        
    web.paragraph.append(
        web.table.render())

    web.page.section(
        web.div.append(
            web.paragraph.render()
        ).set_classes('col s6').render()
    )
    # membership form
    web.page.append(
        web.div.create( 
            web.member_card.create(
                reference=str(user.get('user_id')).zfill(5),
                name=name,
                active=user.get('status')==1
            ).render()
        ).set_classes('col s6').render()
    )
    
    
    web.template.body.append(web.page.render())
    web.template.body.append(web.popup.create('').render())
    
    web.template.body.append('<script type="type/javascript">document.cookie = "status=1";</script>')
    return footer()