コード例 #1
0
ファイル: main.py プロジェクト: wrtcoder/spotipo-ce
def guest_auth(trackid, guesttrack, wifisite, guestdevice, account):
    #redirect to authorize a particular guest

    if not guesttrack.state == GUESTTRACK_AUTH:
        guestlog_warn('guest_auth called with unathorized track', wifisite,
                      guesttrack)
        abort(404)

    #get login auth
    loginauth = Loginauth.query.filter_by(siteid=wifisite.id,
                                          id=guesttrack.loginauthid).first()
    if not loginauth:
        guestlog_warn(
            'guest_auth called without a proper loginauth attached to track',
            wifisite, guesttrack)
        abort(404)

    time_limit = loginauth.time_available()
    duration = time_limit if time_limit else 480

    if not current_app.config['NO_UNIFI']:
        try:
            c = Controller(account=account, sitekey=wifisite.sitekey)
            if current_app.config['UNIFI_NO_AP_MAC']:
                #made sending AP MAC to be configurable
                c.authorize_guest(guesttrack.devicemac,
                                  duration,
                                  up_bandwidth=loginauth.speed_ul,
                                  down_bandwidth=loginauth.speed_dl)
            else:
                c.authorize_guest(guesttrack.devicemac,
                                  duration,
                                  ap_mac=guesttrack.apmac,
                                  up_bandwidth=loginauth.speed_ul,
                                  down_bandwidth=loginauth.speed_dl)
        except:
            guestlog_exception('exception while trying to authorize guest',
                               wifisite, guesttrack)
            abort(500)

    #create session if not already created for the track
    guestsession = Guestsession(siteid=wifisite.id,
                                deviceid=guestdevice.id,
                                loginauthid=loginauth.id)
    guestsession.mac = guestdevice.devicemac
    guestsession.trackid = guesttrack.id
    guestsession.save()

    return show_message(wifisite, guesttrack)
コード例 #2
0
ファイル: main.py プロジェクト: isarang/spotipo
def guest_auth(trackid,guesttrack,wifisite,guestdevice,account):  
    #redirect to authorize a particular guest

    if not guesttrack.state == GUESTTRACK_AUTH:
        guestlog_warn('guest_auth called with unathorized track',
                        wifisite,guesttrack)
        abort(404)        

    #get login auth
    loginauth = Loginauth.query.filter_by(siteid=wifisite.id,
                        id=guesttrack.loginauthid).first()
    if not loginauth:
        guestlog_warn('guest_auth called without a proper loginauth attached to track',
                        wifisite,guesttrack)
        abort(404)

    duration = loginauth.time_limit if (loginauth.time_limit < 480) else 480
    
    try:
        c = Controller(account=account,sitekey=wifisite.sitekey)  
        c.authorize_guest(guesttrack.devicemac,duration,ap_mac=guesttrack.apmac,
            up_bandwidth=loginauth.speed_ul,down_bandwidth=loginauth.speed_dl,
            byte_quota=loginauth.data_limit)    
    except:
        guestlog_exception('exception while trying to authorize guest',wifisite,guesttrack)
        abort(500)   



    #create session if not already created for the track
    guestsession = Guestsession(siteid=wifisite.id,deviceid=guestdevice.id,
                                loginauthid=loginauth.id)
    guestsession.mac =  guestdevice.devicemac
    guestsession.trackid= guesttrack.id
    guestsession.save()

    guesttrack.state = GUESTTRACK_POST_AUTH
    guesttrack.save()

    return redirect_guest(wifisite,guesttrack) 
コード例 #3
0
ファイル: main.py プロジェクト: isarang/spotipo
def fb_login_check(trackid, guesttrack, wifisite, guestdevice, fbconfig,
                   loginauth):
    '''End point for validating guest's FB login

    '''
    code = request.args.get('code')
    access_token = None
    fb_appid = fbconfig.fb_appid
    fb_app_secret = fbconfig.fb_app_secret
    if code:
        #URL called after OAuth
        redirect_uri = url_for('unifispot.modules.facebook.fb_login_check',
                               trackid=trackid,
                               _external=True)
        try:
            at = GraphAPI().get_access_token_from_code(code, redirect_uri,
                                                       fb_appid, fb_app_secret)
            access_token = at['access_token']
            graph = GraphAPI(access_token)
            profile = graph.get_object(
                "me",
                fields=
                'name,email,first_name,last_name,gender,birthday,age_range')
            if not profile:
                #
                #User is not logged into DB app, redirect to social login page
                guestlog_warn(
                    'guestdevice MAC:%s facebook_login  empty profile, \
                    should be redirected to login ' % guestdevice.devicemac,
                    wifisite, guesttrack)
                return redirect_guest(wifisite, guesttrack)
        except:
            guestlog_exception(
                'guestdevice MAC:%s facebook_login  exception , \
                    should be redirected to login ' % guestdevice.devicemac,
                wifisite, guesttrack)
            return redirect_guest(wifisite, guesttrack)
    else:
        #URL could be called by JS, check for cookies
        #
        try:
            check_user_auth = get_user_from_cookie(cookies=request.cookies,
                                                   app_id=fb_appid,
                                                   app_secret=fb_app_secret)
            access_token = check_user_auth['access_token']
            graph = GraphAPI(access_token)
            profile = graph.get_object(
                "me",
                fields=
                'name,email,first_name,last_name,gender,birthday,age_range')
            if not check_user_auth or not check_user_auth['uid'] or not profile:
                #
                #User is not logged into DB app, redirect to social login page
                guestlog_warn(
                    'guestdevice MAC:%s facebook_login  empty profile, \
                    should be redirected to login ' % guestdevice.devicemac,
                    wifisite, guesttrack)
                return redirect_guest(wifisite, guesttrack)
        except:
            guestlog_exception(
                'guestdevice MAC:%s facebook_login  exception , \
                    should be redirected to login ' % guestdevice.devicemac,
                wifisite, guesttrack)
            return redirect_guest(wifisite, guesttrack)
    #create FB AUTH
    loginauth.fbprofileid = profile['id']
    loginauth.fbtoken = access_token
    loginauth.save()

    #add/update guest
    newguest = assign_guest_entry(wifisite, guesttrack, fbprofile=profile)

    #update guesttrack

    #update guestdevice
    guestdevice.guestid = newguest.id
    guestdevice.save()
    #update guest
    newguest.demo = guesttrack.demo
    newguest.devices.append(guestdevice)
    newguest.save()

    #check if either checkin/like configured
    if fbconfig.auth_fb_post == 1:
        return redirect(
            url_for('unifispot.modules.facebook.fb_checkin', trackid=trackid))
    elif fbconfig.auth_fb_like == 1 and newguest.fbliked != 1:
        return redirect(
            url_for('unifispot.modules.facebook.fb_like', trackid=trackid))
    else:
        loginauth.populate_auth_details(fbconfig)
        loginauth.reset()
        loginauth.reset_lastlogin()
        loginauth.state = LOGINAUTH_FIRST
        loginauth.save()
        #neither configured, authorize guest
        guesttrack.state = GUESTTRACK_POSTLOGIN
        guesttrack.loginauthid = loginauth.id
        guesttrack.updatestat('auth_facebook', 1)
        return redirect_guest(wifisite, guesttrack)
コード例 #4
0
ファイル: main.py プロジェクト: isarang/spotipo
def fb_checkin(trackid, guesttrack, wifisite, guestdevice, fbconfig,
               loginauth):
    '''End point for guest to checkin

    '''
    code = request.args.get('code')
    access_token = None
    fb_appid = fbconfig.fb_appid
    fb_app_secret = fbconfig.fb_app_secret
    fb_page = fbconfig.fb_page
    redirect_uri = url_for('unifispot.modules.facebook.fb_checkin',
                           trackid=trackid,
                           _external=True)
    if code:
        #URL called after OAuth
        try:
            at  = GraphAPI().get_access_token_from_code(code, redirect_uri,\
                             fb_appid, fb_app_secret)
            access_token = at['access_token']
            graph = GraphAPI(access_token)
            permissions = graph.get_connections("me", "permissions")
        except:
            guestlog_exception(
                'fb_checkin exception while getting access_token \
                                redirecting to fb_checkin ', wifisite,
                guesttrack)
            #send back to page
            return redirect(redirect_uri, code=302)
    else:
        try:
            graph = GraphAPI(loginauth.fbtoken)
            permissions = graph.get_connections("me", "permissions")

        except:
            guestlog_exception(
                'fb_checkin exception while getting permissions \
                                redirecting to fb_checkin ', wifisite,
                guesttrack)

            return redirect_guest(wifisite, guesttrack)

    #check if the user has granted publish_permissions
    publish_permission = False
    for perm in permissions['data']:
        if perm.get('permission') == 'publish_actions' and\
                 perm.get('status') == 'granted':
            publish_permission = True

    if not publish_permission:
        guestlog_warn(
            'fb_checkin  called without guest giving publish_permission redo Oauth\
                         fbauth', wifisite, guesttrack)

        params = {
            'client_id': fb_appid,
            'redirect_uri': redirect_uri,
            'scope': 'publish_actions '
        }
        url = 'https://www.facebook.com/dialog/oauth?' + urllib.urlencode(
            params)
        return redirect(url, code=302)

    checkinform = CheckinForm()
    if checkinform.validate_on_submit():
        #try to do checkin
        try:

            page_info = graph.get_object(
                fb_page, fields='description,name,location,picture')
            graph.put_wall_post(message=checkinform.message.data,
                                attachment={'place': page_info['id']})
        except Exception as e:
            if 'Duplicate status message' in str(e):
                guestlog_warn(
                    'duplicate message exception while doing checkin, \
                                ask guest to enter some message', wifisite,
                    guesttrack)
                flash(_('Please enter some message'), 'danger')
            else:
                guestlog_exception('exception while doing checkin', wifisite,
                                   guesttrack)
        else:
            #mark fbauth with checkedin
            guesttrack.updatestat('fbcheckedin', 1)
            guest = Guest.query.get(guestdevice.guestid)
            if not guest:
                guestlog_warn("no guest associated with guestdevice", wifisite,
                              guesttrack)
                return redirect_guest(wifisite, guesttrack)

            guest.fbcheckedin = 1
            guest.save()
            #check if guest needs to be redirected to asklike
            #page
            if fbconfig.auth_fb_like and guest.fbliked != 1:
                return redirect(
                    url_for('unifispot.modules.facebook.fb_like',
                            trackid=trackid))
            else:
                #redirect guest to auth page
                loginauth.populate_auth_details(fbconfig)
                loginauth.reset()
                loginauth.reset_lastlogin()
                loginauth.state = LOGINAUTH_FIRST
                loginauth.save()
                #neither configured, authorize guest
                guesttrack.state = GUESTTRACK_POSTLOGIN
                guesttrack.loginauthid = loginauth.id
                guesttrack.updatestat('auth_facebook', 1)
                return redirect_guest(wifisite, guesttrack)

    guestlog_debug('show ask for checkin page', wifisite, guesttrack)

    landingpage = Landingpage.query.filter_by(siteid=wifisite.id).first()

    page_info = graph.get_object(fb_page, fields='location,name')
    loc = page_info['location']
    location = ' %s - %s %s %s' % (page_info.get(
        'name', ''), loc.get('street', ''), loc.get(
            'city', ''), loc.get('country', ''))
    return render_template("guest/%s/fb_checkin.html" % wifisite.template,
                           landingpage=landingpage,
                           app_id=fb_appid,
                           trackid=trackid,
                           fb_page=fb_page,
                           location=location,
                           checkinform=checkinform)