Example #1
0
def sms_login(track_id,guest_track,landing_site,guest_device):
    ''' Function to called if the site is configured with SMS login    
    
    '''     
    sms_form = generate_smsform(landing_site)
    if sms_form.validate_on_submit():
        #check if number validation is needed
        #TO DO
        #check_auth = Smsdata.query.filter_by(site_id=landing_site.id,phonenumber=sms_form.phonenumber.data,authcode=sms_form.authcode.data).first()
        #if check_auth and check_auth.status != SMS_CODE_USED :
        guest_check = Guest()
        guest_check.populate_from_email_form(sms_form,landing_site.emailformfields)
        guest_check.site_id     = landing_site.id
        guest_check.demo        = guest_track.demo
        db.session.add(guest_check)
        #New guest added create task for API export
        celery_export_api.delay(guest_check.id)            
        #mark sessions as authorized
        guest_track.state   = GUESTRACK_SMS_AUTH
        guest_device.state  = DEVICE_AUTH
        guest_device.guest  = guest_check
        guest_check.devices.append(guest_device)
        #check_auth.status = SMS_CODE_USED
        db.session.commit()
        current_app.logger.debug('Wifiguest Log - Site ID:%s sms_login new guest ID :%s for track ID:%s'%(guest_track.site_id,guest_check.id,guest_track.id))
        return redirect(url_for('guest.authorize_guest',track_id=guest_track.track_id),code=302)       
    #else:
        #print_errors(form)            
    
    landing_page = Landingpage.query.filter_by(id=landing_site.default_landing).first()
    return render_template('guest/%s/sms_landing.html'%landing_site.template,landing_site=landing_site,landing_page=landing_page,sms_form=sms_form)
Example #2
0
def email_login(track_id,guest_track,landing_site,guest_device):
    ''' Function to called if the site is configured with Social login    
    
    '''    

    #Check if the device already has a valid auth
    if  guest_device.state == DEVICE_AUTH and guest_device.demo == 0:
        #Device has a guest element and is authorized
        guest_track.state   = GUESTRACK_PREAUTH
        db.session.commit()
        #redirect to authorize_guest
        return redirect(url_for('guest.authorize_guest',track_id=guest_track.track_id),code=302)
    else:
        #show the configured landing page
        email_form = generate_emailform(landing_site)
        if email_form.validate_on_submit():
            newguest = Guest()
            newguest.populate_from_email_form(email_form,landing_site.emailformfields)
            newguest.site = landing_site
            db.session.add(newguest)
            db.session.commit()
            #New guest added create task for API export
            celery_export_api.delay(newguest.id)
            guest_track.state   = GUESTRACK_EMAIL_AUTH
            guest_device.guest  = newguest
            newguest.demo       = guest_track.demo
            newguest.devices.append(guest_device)
            guest_device.state  = DEVICE_AUTH
            db.session.commit()
            current_app.logger.debug('Wifiguest Log - Site ID:%s email_login  new guest track ID:%s'%(guest_track.site_id,guest_track.id))
            return redirect(url_for('guest.authorize_guest',track_id=guest_track.track_id),code=302)
        landing_page = Landingpage.query.filter_by(id=landing_site.default_landing).first()
        return render_template('guest/%s/email_landing.html'%landing_site.template,landing_site=landing_site,landing_page=landing_page,email_form=email_form)   
Example #3
0
def voucher_login(track_id,guest_track,landing_site,guest_device):
    ''' Function to called if the site is configured with Voucher login    
    
    '''
        
    #Check if the device already has a valid auth
    if  guest_device.state == DEVICE_VOUCHER_AUTH and guest_device.demo == False:
        #Device has a guest element and is authorized before
        #check if the voucher is valid still
        #get latest voucher 
        voucher = Voucher.query.filter(and_(Voucher.device_id==guest_device.id,Voucher.site_id==landing_site.id)).first()
        if voucher and voucher.check_validity() :
            guest_track.duration = voucher.time_available()
            guest_track.state   = GUESTRACK_VOUCHER_AUTH
            db.session.commit()
            #redirect to authorize_guest
            current_app.logger.debug('Wifiguest Log - Site ID:%s voucher_login MAC:%s already authenticated voucher for track ID:%s'%(guest_track.site_id,guest_device.mac,guest_track.id))
            return redirect(url_for('guest.authorize_guest',track_id=guest_track.track_id),code=302)
        else:
            current_app.logger.debug('Wifiguest Log - Site ID:%s voucher_login MAC:%s expired previous voucher for track ID:%s'%(guest_track.site_id,guest_device.mac,guest_track.id))
            guest_device.state = DEVICE_INIT
            db.session.commit()
            flash("Looks like your Voucher have expired", 'danger')
            
    voucher_form = generate_voucherform(landing_site)
    if voucher_form.validate_on_submit():
        #validate voucher
        voucher = Voucher.query.filter(and_(Voucher.site_id== landing_site.id,Voucher.voucher==voucher_form.voucher.data,Voucher.used==False)).first()
        if voucher:
            #valid voucher available
            newguest = Guest()
            newguest.populate_from_email_form(voucher_form,landing_site.emailformfields)
            newguest.site = landing_site
            db.session.add(newguest)
            db.session.commit()
            #New guest added create task for API export
            celery_export_api.delay(newguest.id)            
            #mark sessions as authorized
            guest_track.duration = voucher.time_available()
            guest_track.state   = GUESTRACK_VOUCHER_AUTH
            guest_device.guest  = newguest
            newguest.demo        = guest_track.demo
            newguest.devices.append(guest_device)
            voucher.device_id = guest_device.id
            voucher.used = True
            voucher.used_at = arrow.utcnow().datetime
            guest_device.state  = DEVICE_VOUCHER_AUTH
            db.session.commit()
            current_app.logger.debug('Wifiguest Log - Site ID:%s voucher_login MAC:%s new guest:%s  for track ID:%s'%(guest_track.site_id,guest_device.mac,newguest.id,guest_track.id))           
            return redirect(url_for('guest.authorize_guest',track_id=guest_track.track_id),code=302)
        else:           
            current_app.logger.debug('Wifiguest Log - Site ID:%s voucher_login MAC:%s  in valid vouher value:%s for track ID:%s'%(guest_track.site_id,guest_device.mac,voucher_form.voucher.data,guest_track.id))
            flash(u'Invalid Voucher ID', 'danger')
       
    
    landing_page = Landingpage.query.filter_by(id=landing_site.default_landing).first()
    return render_template('guest/%s/voucher_landing.html'%landing_site.template,landing_site=landing_site,landing_page=landing_page,voucher_form=voucher_form)   
Example #4
0
def email_login(track_id):
    ''' Function to called if the site is configured with Social login    
    
    '''
    #
    #Validate track id and get all the needed variables
    guest_track = Guesttrack.query.filter_by(track_id=track_id).first()
    if not guest_track:
        current_app.logger.error("Called email_login with wrong track ID:%s"%track_id)
        abort(404)
        
    #validate session associated with this track ID
    guest_session   = Guestsession.query.filter_by(id=guest_track.session_id).first()
    if not guest_session:
        current_app.logger.error("Called email_login with wrong Session from track ID:%s"%track_id)
        abort(404)   

    guest_device    = Device.query.filter_by(id=guest_session.device_id).first()
    landing_site    = Wifisite.query.filter_by(id=guest_session.site_id).first()    
    if  not guest_device or not landing_site:
        current_app.logger.error("Called email_login with wrong Session/Device/Wifisite from track ID:%s"%track_id)
        abort(404) 
    current_app.logger.debug('Wifiguest Log - Site ID:%s email_login for track ID:%s'%(guest_track.site_id,guest_track.id))
    #
    #Check if the device already has a valid auth
    if  guest_device.state == DEVICE_AUTH and guest_device.demo == 0:
        #Device has a guest element and is authorized
        guest_session.state = SESSION_AUTHORIZED
        guest_track.state   = GUESTRACK_SOCIAL_PREAUTH
        guest_device.state  = DEVICE_AUTH
        db.session.commit()
        #redirect to authorize_guest
        return redirect(url_for('guest.authorize_guest',track_id=guest_track.track_id),code=302)
    else:
        #show the configured landing page
        email_form = generate_emailform(landing_site.emailformfields)

        if email_form.validate_on_submit():
            newguest = Guest()
            newguest.populate_from_email_form(email_form,landing_site.emailformfields)
            newguest.site = landing_site
            db.session.add(newguest)
            db.session.commit()
            #New guest added create task for API export
            celery_export_api.delay(newguest.id)
            #mark sessions as authorized
            guest_session.state = SESSION_AUTHORIZED
            guest_track.state   = GUESTRACK_NEW_AUTH
            guest_device.guest  = newguest
            newguest.demo       = guest_session.demo
            newguest.devices.append(guest_device)
            guest_device.state  = DEVICE_AUTH
            db.session.commit()
            current_app.logger.debug('Wifiguest Log - Site ID:%s email_login  new guest track ID:%s'%(guest_track.site_id,guest_track.id))
            return redirect(url_for('guest.authorize_guest',track_id=guest_track.track_id),code=302)
        landing_page = Landingpage.query.filter_by(id=landing_site.default_landing).first()
        return render_template('guest/%s/email_landing.html'%landing_site.template,landing_site=landing_site,landing_page=landing_page,email_form=email_form)   
Example #5
0
def sms_login(track_id):
    ''' Function to called if the site is configured with SMS login    
    
    '''
    #
    #Validate track id and get all the needed variables
    guest_track = Guesttrack.query.filter_by(track_id=track_id).first()
    if not guest_track:
        current_app.logger.error("Called email_login with wrong track ID:%s"%track_id)
        abort(404)
        
    #validate session associated with this track ID
    guest_session   = Guestsession.query.filter_by(id=guest_track.session_id).first()
    if not guest_session:
        current_app.logger.error("Called email_login with wrong Session from track ID:%s"%track_id)
        abort(404)   

    guest_device    = Device.query.filter_by(id=guest_session.device_id).first()
    landing_site    = Wifisite.query.filter_by(id=guest_session.site_id).first()    
    if  not guest_device or not landing_site:
        current_app.logger.error("Called email_login with wrong Session/Device/Wifisite from track ID:%s"%track_id)
        abort(404) 
    #
    #
    current_app.logger.debug('Wifiguest Log - Site ID:%s sms_login for track ID:%s'%(guest_track.site_id,guest_track.id))
    sms_form = generate_smsform(landing_site.emailformfields)
    if sms_form.validate_on_submit():
        #check if number validation is needed
        #TO DO
        #check_auth = Smsdata.query.filter_by(site_id=landing_site.id,phonenumber=sms_form.phonenumber.data,authcode=sms_form.authcode.data).first()
        #if check_auth and check_auth.status != SMS_CODE_USED :
        guest_check = Guest()
        guest_check.populate_from_email_form(sms_form,landing_site.emailformfields)
        guest_check.site_id    = guest_session.site_id
        guest_check.demo        = guest_session.demo
        db.session.add(guest_check)
        #New guest added create task for API export
        celery_export_api.delay(guest_check.id)            
        #mark sessions as authorized
        guest_session.state = SESSION_AUTHORIZED
        guest_track.state   = GUESTRACK_NEW_AUTH
        guest_device.state  = DEVICE_SMS_AUTH
        guest_device.guest  = guest_check
        guest_check.devices.append(guest_device)
        #check_auth.status = SMS_CODE_USED
        db.session.commit()
        current_app.logger.debug('Wifiguest Log - Site ID:%s sms_login new guest ID :%s for track ID:%s'%(guest_track.site_id,guest_check.id,guest_track.id))
        return redirect(url_for('guest.authorize_guest',track_id=guest_track.track_id),code=302)       
    #else:
        #print_errors(form)            
    
    landing_page = Landingpage.query.filter_by(id=landing_site.default_landing).first()
    return render_template('guest/%s/sms_landing.html'%landing_site.template,landing_site=landing_site,landing_page=landing_page,sms_form=sms_form)
Example #6
0
def facebook_login(track_id,guest_track,landing_site,guest_device):
    ''' Function to called after guest has logged in using JS/oauth

    '''
    code  = request.args.get('code')
    access_token = None
    fb_appid = landing_site.fb_appid or current_app.config['FB_APP_ID']   
    fb_app_secret = landing_site.fb_app_secret or current_app.config['FB_APP_SECRET']    
    if code:
        #URL called after OAuth
        redirect_uri = url_for('guest.facebook_login',track_id=track_id,_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')
            if not profile:
                #
                #User is not logged into DB app, redirect to social login page
                current_app.logger.debug('Wifiguest Log - Site ID:%s guest_device MAC:%s facebook_login  empty profile, redirecting to social_login %s'%(landing_site.id,guest_track.device_mac,request.url))            
                return redirect(url_for('guest.multi_login',track_id=track_id),code=302)
        except:
            current_app.logger.exception('Wifiguest Log - Site ID:%s guest_device MAC:%s facebook_login exception while getting access_token redirecting to social_login %s'%(landing_site.id,guest_track.device_mac,request.url))            
            return redirect(url_for('guest.multi_login',track_id=track_id),code=302)
        
    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')
            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
                current_app.logger.debug('Wifiguest Log - Site ID:%s guest_device MAC:%s facebook_login  Used not logged in, redirecting to social_login %s'%(landing_site.id,guest_track.device_mac,request.url))            
                return redirect(url_for('guest.multi_login',track_id=track_id),code=302)
        except:
            current_app.logger.exception('Wifiguest Log - Site ID:%s guest_device MAC:%s facebook_login exception while get_user_from_cookie redirecting to social_login %s'%(landing_site.id,guest_track.device_mac,request.url))            
            return redirect(url_for('guest.multi_login',track_id=track_id),code=302)

    #check this FB profile already added into our DB,else add it
    profile_check = Facebookauth.query.filter(and_(Facebookauth.profile_id==profile['id'],Facebookauth.site_id==landing_site.id)).first()
    if not profile_check:
        profile_check = Facebookauth()
        profile_check.profile_id    = profile['id']
        profile_check.token         = access_token
        profile_check.site = landing_site
        db.session.add(profile_check)
        db.session.commit()
        current_app.logger.debug('Wifiguest Log - Site ID:%s facebook_login  adding new FB profile ID:%s for track ID:%s'%(guest_track.site_id,profile_check.id,guest_track.id))
    else:
        #update access token
        profile_check.token         = access_token
        
        db.session.commit()
        current_app.logger.debug('Wifiguest Log - Site ID:%s facebook_login  already added FB profile ID:%s for track ID:%s'%(guest_track.site_id,profile_check.id,guest_track.id))
    #profile already added to DB, check if the user had already authorized the site
    guest_check = Guest.query.filter(and_(Guest.site_id==landing_site.id,Guest.fb_profile==profile_check.id)).first()
    if not guest_check:
        guest_check = Guest()
        guest_check.firstname   = profile.get('first_name')
        guest_check.lastname    = profile.get('last_name')
        guest_check.email       = profile.get('email')       
        gender                  = profile.get('gender')
        if gender:
            guest_check.gender  = 1 if gender == 'male' else 2
        dob                     = profile.get('birthday')
        if dob:
            #convert MM-DD-YYY to DD-MM-YYYY
            guest_check.dob = arrow.get(dob,'MM/DD/YYYY').format('DD/MM/YYYY')

        guest_check.site_id     = landing_site.id
        guest_check.facebookauth = profile_check           
        profile_check.guests.append(guest_check)
        db.session.add(guest_check)
        db.session.commit()
        #New guest added create task for API export
        celery_export_api.delay(guest_check.id)     
        current_app.logger.debug('Wifiguest Log - Site ID:%s facebook_login  adding new Guest:%s for track ID:%s'%(guest_track.site_id,guest_check.id,guest_track.id))       
    else:
        current_app.logger.debug('Wifiguest Log - Site ID:%s facebook_login  already added Guest:%s for track ID:%s'%(guest_track.site_id,guest_check.id,guest_track.id))          
    #
    #even if guest entry was already added, assign the guest to device
    guest_device.guest  = guest_check
    guest_check.devices.append(guest_device)
    db.session.commit()   
    #check if checkin is enabled and/or like is enabled
    if landing_site.auth_fb_post == 1:
        #redirect to checkin
        return redirect(url_for('guest.social_action_checkin',track_id=guest_track.track_id),code=302)
    elif landing_site.auth_fb_like == 1 and guest_check.fb_liked !=1:
        #redirect to like
        return redirect(url_for('guest.social_action_like',track_id=guest_track.track_id),code=302)
    else:
        #redirect to 
        #mark sessions as authorized
        guest_track.state   = GUESTRACK_SOCIAL_AUTH
        guest_device.state  = DEVICE_AUTH
        db.session.commit()
        return redirect(url_for('guest.authorize_guest',track_id=guest_track.track_id),code=302)
Example #7
0
def voucher_login(track_id):
    ''' Function to called if the site is configured with Voucher login    
    
    '''
    #
    #Validate track id and get all the needed variables
    guest_track = Guesttrack.query.filter_by(track_id=track_id).first()
    if not guest_track:
        current_app.logger.error("Called email_login with wrong track ID:%s"%track_id)
        abort(404)
        
    #validate session associated with this track ID
    guest_session   = Guestsession.query.filter_by(id=guest_track.session_id).first()
    if not guest_session:
        current_app.logger.error("Called email_login with wrong Session from track ID:%s"%track_id)
        abort(404)   

    guest_device    = Device.query.filter_by(id=guest_session.device_id).first()
    landing_site    = Wifisite.query.filter_by(id=guest_session.site_id).first()    
    if  not guest_device or not landing_site:
        current_app.logger.error("Called email_login with wrong Session/Device/Wifisite from track ID:%s"%track_id)
        abort(404) 
    current_app.logger.debug('Wifiguest Log - Site ID:%s voucher_login  for track ID:%s'%(guest_track.site_id,guest_track.id))
    #
    #Check if the device already has a valid auth
    if  guest_device.state == DEVICE_VOUCHER_AUTH and guest_device.demo == 0:
        #Device has a guest element and is authorized before
        #check if the voucher is valid still
        expiry = arrow.get(guest_device.expires_at).timestamp
        time_now = arrow.utcnow().timestamp
        available_time = expiry - time_now
        if available_time > 60 : #atleast one minute is available
            #check if atleast one hour of time remaining in the voucher, else modify the session duration
            if available_time < 3600: 
                guest_session.duration = (available_time/60)
            guest_session.state = SESSION_AUTHORIZED
            guest_track.state   = GUESTRACK_VOUCHER_AUTH
            db.session.commit()
            #redirect to authorize_guest
            current_app.logger.debug('Wifiguest Log - Site ID:%s voucher_login already authenticated voucher for track ID:%s'%(guest_track.site_id,guest_track.id))
            return redirect(url_for('guest.authorize_guest',track_id=guest_track.track_id),code=302)
            
    voucher_form = generate_voucherform(landing_site.emailformfields)
    if voucher_form.validate_on_submit():
        #validate voucher
        voucher = Voucher.query.filter(and_(Voucher.site_id== landing_site.id,Voucher.voucher==voucher_form.voucher.data,Voucher.used==False)).first()
        if voucher:
            #valid voucher available
            newguest = Guest()
            newguest.populate_from_email_form(voucher_form,landing_site.emailformfields)
            newguest.site = landing_site
            db.session.add(newguest)
            db.session.commit()
            #New guest added create task for API export
            celery_export_api.delay(newguest.id)            
            #mark sessions as authorized
            guest_session.state = SESSION_AUTHORIZED
            guest_track.state   = GUESTRACK_VOUCHER_AUTH
            guest_device.guest  = newguest
            newguest.demo        = guest_session.demo
            newguest.devices.append(guest_device)
            #update device with voucher expirty time
            expiry = arrow.get(arrow.utcnow().timestamp + voucher.duration_t)
            guest_device.expires_at = expiry.datetime
            voucher.device_id = guest_device.id
            voucher.used = True
            voucher.used_at = arrow.utcnow().datetime
            guest_device.state  = DEVICE_VOUCHER_AUTH
            db.session.commit()
            current_app.logger.debug('Wifiguest Log - Site ID:%s voucher_login new guest:%s for track ID:%s'%(guest_track.site_id,newguest.id,guest_track.id))
            return redirect(url_for('guest.authorize_guest',track_id=guest_track.track_id),code=302)
        else:           
            current_app.logger.debug('Wifiguest Log - Site ID:%s voucher_login  in valid vouher value:%s for track ID:%s'%(guest_track.site_id,voucher_form.voucher.data,guest_track.id))
            flash(u'Invalid Voucher ID', 'danger')
       
    
    landing_page = Landingpage.query.filter_by(id=landing_site.default_landing).first()
    return render_template('guest/%s/voucher_landing.html'%landing_site.template,landing_site=landing_site,landing_page=landing_page,voucher_form=voucher_form)   
Example #8
0
def facebook_login(track_id):
    ''' Function to called if the site is configured for advanced facebook authentication.
    
    '''
    #fbtrackform = FacebookTrackForm()
    auth_like = None
    auth_post = None
    #if fbtrackform.validate_on_submit():
    if request.method == 'POST':
        auth_like = request.form['authlike']
        auth_post = request.form['authpost']
    #Validate track id and get all the needed variables
    guest_track = Guesttrack.query.filter_by(track_id=track_id).first()
    if not guest_track:
        current_app.logger.error("Called authorize_guest with wrong track ID:%s"%track_id)
        abort(404)
        
    #validate session associated with this track ID
    guest_session   = Guestsession.query.filter_by(id=guest_track.session_id).first()
    if not guest_session:
        current_app.logger.error("Called authorize_guest with wrong Session from track ID:%s"%track_id)
        abort(404)         
    guest_device    = Device.query.filter_by(id=guest_session.device_id).first()
    landing_site    = Wifisite.query.filter_by(id=guest_session.site_id).first()    
    if  not guest_device or not landing_site:
        current_app.logger.error("Called authorize_guest with wrong Session/Device/Wifisite from track ID:%s"%track_id)
        abort(404) 

    # Attempt to get the short term access token for the current user.
    current_app.logger.debug('Wifiguest Log - Site ID:%s facebook_login for track ID:%s'%(guest_track.site_id,guest_track.id))
    if  auth_like != '1': #ensure this is first time visit, not the visit after like/post
        fb_appid= landing_site.fb_appid or current_app.config['FB_APP_ID']   
        fb_app_secret = landing_site.fb_app_secret or current_app.config['FB_APP_SECRET']
        check_user_auth = get_user_from_cookie(cookies=request.cookies, app_id=fb_appid,app_secret=fb_app_secret)      
        if not check_user_auth or not check_user_auth['uid']:
            #
            #User is not logged into DB app, redirect to social login page
            current_app.logger.debug('Wifiguest Log - Site ID:%s facebook_login  Used not logged in, redirecting to social_login for track ID:%s'%(guest_track.site_id,guest_track.id))
            return redirect(url_for('guest.social_login',track_id=track_id),code=302)

        #check this FB profile already added into our DB,else add it
        profile_check = Facebookauth.query.filter(and_(Facebookauth.profile_id==check_user_auth['uid'],Facebookauth.site_id==landing_site.id)).first()
        if not profile_check:

            profile_check = Facebookauth()
            profile_check.profile_id    = check_user_auth['uid']
            profile_check.token         = check_user_auth['access_token']
            profile_check.site = landing_site
            db.session.add(profile_check)
            db.session.commit
            current_app.logger.debug('Wifiguest Log - Site ID:%s facebook_login  adding new FB profile ID:%s for track ID:%s'%(guest_track.site_id,profile_check.id,guest_track.id))
            
        #profile already added to DB, check if the user had already authorized the site
        guest_check = Guest.query.filter(and_(Guest.site_id==guest_session.site_id,Guest.fb_profile==profile_check.id)).first()
        if not guest_check:
            #Guest entry for this user is not available in DB,add the same.
            try:
                graph = GraphAPI(check_user_auth['access_token'])
                profile = graph.get_object(profile_check.profile_id +'?locale=en_US&fields=name,email,first_name,last_name')
            except:
                #Exception while calling graph API, redirect user to same page to try again
                current_app.logger.exception('Wifiguest Log - Site ID:%s facebook_login  exception while API FB profile ID:%s for track ID:%s'%(guest_track.site_id,guest_track.id,profile_check.id))
                return redirect(url_for('guest.facebook_login',track_id=track_id),code=302)
            else:
                guest_check = Guest()
                guest_check.firstname    = profile.get('first_name')
                guest_check.lastname    = profile.get('last_name')
                guest_check.email   = profile.get('email')
                guest_check.site_id = guest_session.site_id
                guest_check.facebookauth = profile_check           
                profile_check.guests.append(guest_check)
                db.session.add(guest_check)
                db.session.commit()
                #New guest added create task for API export
                celery_export_api.delay(guest_check.id)     
                current_app.logger.debug('Wifiguest Log - Site ID:%s facebook_login  adding new Guest:%s for track ID:%s'%(guest_track.site_id,guest_check.id,guest_track.id))       
        #
        #even if guest entry was already added, assign the guest to device
        guest_device.guest  = guest_check
        guest_check.devices.append(guest_device)
        db.session.commit()
    else:
        guest_check = Guest.query.filter_by(id=guest_device.guest_id).first()
        if not guest_check:
            #
            #User is not logged into DB app, redirect to social login page
            current_app.logger.debug('Wifiguest Log - Site ID:%s facebook_login  Used not logged in after like/post, redirecting to social_login for track ID:%s'%(guest_track.site_id,guest_track.id))
            return redirect(url_for('guest.social_login',track_id=track_id),code=302)            

    if landing_site.auth_fb_like == 1:
        if guest_track.fb_liked !=1:
            if guest_check.fb_liked:
                # if the guest has liked the page already, mark guesttrack as liked
                current_app.logger.debug('Wifiguest Log - Site ID:%s facebook_login  guest already liked for track ID:%s'%(guest_track.site_id,guest_track.id))              
                guest_track.fb_liked = 1
                db.session.commit()
            elif auth_like == '1' :
                #quick hack to test for liking and posting, guest has skipped the liking, allow
                #internet for now and ask next time
                current_app.logger.debug('Wifiguest Log - Site ID:%s facebook_login  guest decided to skip  like for track ID:%s'%(guest_track.site_id,guest_track.id))
                guest_track.fb_liked = 1
                db.session.commit()
            elif auth_like == '2':
                #user has liked the page mark track and guest as liked               
                current_app.logger.debug('Wifiguest Log - Site ID:%s facebook_login  guest liked now for track ID:%s'%(guest_track.site_id,guest_track.id))
                guest_track.fb_liked = 1
                guest_check.fb_liked = 1
                db.session.commit()
            else:
                # show page asking user to like
                current_app.logger.debug('Wifiguest Log - Site ID:%s facebook_login  new guest show page to like for track ID:%s'%(guest_track.site_id,guest_track.id))
                landing_page = Landingpage.query.filter_by(id=landing_site.default_landing).first()
                fb_page = landing_site.fb_page or current_app.config['FB_PAGE_URL']
                return render_template("guest/%s/fb_like.html"%landing_site.template,landing_page = landing_page,font_list=font_list,app_id=fb_appid,track_id=track_id,fb_page=fb_page)


    #mark sessions as authorized
    guest_session.state = SESSION_AUTHORIZED
    guest_track.state   = GUESTRACK_NEW_AUTH
    if guest_check.fb_liked == 1 : # if guest has full filled all the social login criterias,mark the device as authed
        guest_device.state  = DEVICE_AUTH
    db.session.commit()
    return redirect(url_for('guest.authorize_guest',track_id=guest_track.track_id),code=302)
Example #9
0
def sms_login(track_id):
    ''' Function to called if the site is configured with SMS login    
    
    '''
    #
    #Validate track id and get all the needed variables
    guest_track = Guesttrack.query.filter_by(track_id=track_id).first()
    if not guest_track:
        current_app.logger.error("Called email_login with wrong track ID:%s" %
                                 track_id)
        abort(404)

    #validate session associated with this track ID
    guest_session = Guestsession.query.filter_by(
        id=guest_track.session_id).first()
    if not guest_session:
        current_app.logger.error(
            "Called email_login with wrong Session from track ID:%s" %
            track_id)
        abort(404)

    guest_device = Device.query.filter_by(id=guest_session.device_id).first()
    landing_site = Wifisite.query.filter_by(id=guest_session.site_id).first()
    if not guest_device or not landing_site:
        current_app.logger.error(
            "Called email_login with wrong Session/Device/Wifisite from track ID:%s"
            % track_id)
        abort(404)
    #
    #
    current_app.logger.debug(
        'Wifiguest Log - Site ID:%s sms_login for track ID:%s' %
        (guest_track.site_id, guest_track.id))
    sms_form = generate_smsform(landing_site.emailformfields)
    if sms_form.validate_on_submit():
        #check if number validation is needed
        #TO DO
        #check_auth = Smsdata.query.filter_by(site_id=landing_site.id,phonenumber=sms_form.phonenumber.data,authcode=sms_form.authcode.data).first()
        #if check_auth and check_auth.status != SMS_CODE_USED :
        guest_check = Guest()
        guest_check.populate_from_email_form(sms_form,
                                             landing_site.emailformfields)
        guest_check.site_id = guest_session.site_id
        guest_check.demo = guest_session.demo
        db.session.add(guest_check)
        #New guest added create task for API export
        celery_export_api.delay(guest_check.id)
        #mark sessions as authorized
        guest_session.state = SESSION_AUTHORIZED
        guest_track.state = GUESTRACK_NEW_AUTH
        guest_device.state = DEVICE_SMS_AUTH
        guest_device.guest = guest_check
        guest_check.devices.append(guest_device)
        #check_auth.status = SMS_CODE_USED
        db.session.commit()
        current_app.logger.debug(
            'Wifiguest Log - Site ID:%s sms_login new guest ID :%s for track ID:%s'
            % (guest_track.site_id, guest_check.id, guest_track.id))
        return redirect(url_for('guest.authorize_guest',
                                track_id=guest_track.track_id),
                        code=302)
    #else:
    #print_errors(form)

    landing_page = Landingpage.query.filter_by(
        id=landing_site.default_landing).first()
    return render_template('guest/%s/sms_landing.html' % landing_site.template,
                           landing_site=landing_site,
                           landing_page=landing_page,
                           sms_form=sms_form)
Example #10
0
def voucher_login(track_id):
    ''' Function to called if the site is configured with Voucher login    
    
    '''
    #
    #Validate track id and get all the needed variables
    guest_track = Guesttrack.query.filter_by(track_id=track_id).first()
    if not guest_track:
        current_app.logger.error("Called email_login with wrong track ID:%s" %
                                 track_id)
        abort(404)

    #validate session associated with this track ID
    guest_session = Guestsession.query.filter_by(
        id=guest_track.session_id).first()
    if not guest_session:
        current_app.logger.error(
            "Called email_login with wrong Session from track ID:%s" %
            track_id)
        abort(404)

    guest_device = Device.query.filter_by(id=guest_session.device_id).first()
    landing_site = Wifisite.query.filter_by(id=guest_session.site_id).first()
    if not guest_device or not landing_site:
        current_app.logger.error(
            "Called email_login with wrong Session/Device/Wifisite from track ID:%s"
            % track_id)
        abort(404)
    current_app.logger.debug(
        'Wifiguest Log - Site ID:%s voucher_login  for track ID:%s' %
        (guest_track.site_id, guest_track.id))
    #
    #Check if the device already has a valid auth
    if guest_device.state == DEVICE_VOUCHER_AUTH and guest_device.demo == 0:
        #Device has a guest element and is authorized before
        #check if the voucher is valid still
        expiry = arrow.get(guest_device.expires_at).timestamp
        time_now = arrow.utcnow().timestamp
        available_time = expiry - time_now
        if available_time > 60:  #atleast one minute is available
            #check if atleast one hour of time remaining in the voucher, else modify the session duration
            if available_time < 3600:
                guest_session.duration = (available_time / 60)
            guest_session.state = SESSION_AUTHORIZED
            guest_track.state = GUESTRACK_VOUCHER_AUTH
            db.session.commit()
            #redirect to authorize_guest
            current_app.logger.debug(
                'Wifiguest Log - Site ID:%s voucher_login already authenticated voucher for track ID:%s'
                % (guest_track.site_id, guest_track.id))
            return redirect(url_for('guest.authorize_guest',
                                    track_id=guest_track.track_id),
                            code=302)

    voucher_form = generate_voucherform(landing_site.emailformfields)
    if voucher_form.validate_on_submit():
        #validate voucher
        voucher = Voucher.query.filter(
            and_(Voucher.site_id == landing_site.id,
                 Voucher.voucher == voucher_form.voucher.data,
                 Voucher.used == False)).first()
        if voucher:
            #valid voucher available
            newguest = Guest()
            newguest.populate_from_email_form(voucher_form,
                                              landing_site.emailformfields)
            newguest.site = landing_site
            db.session.add(newguest)
            db.session.commit()
            #New guest added create task for API export
            celery_export_api.delay(newguest.id)
            #mark sessions as authorized
            guest_session.state = SESSION_AUTHORIZED
            guest_track.state = GUESTRACK_VOUCHER_AUTH
            guest_device.guest = newguest
            newguest.demo = guest_session.demo
            newguest.devices.append(guest_device)
            #update device with voucher expirty time
            expiry = arrow.get(arrow.utcnow().timestamp + voucher.duration_t)
            guest_device.expires_at = expiry.datetime
            voucher.device_id = guest_device.id
            voucher.used = True
            voucher.used_at = arrow.utcnow().datetime
            guest_device.state = DEVICE_VOUCHER_AUTH
            db.session.commit()
            current_app.logger.debug(
                'Wifiguest Log - Site ID:%s voucher_login new guest:%s for track ID:%s'
                % (guest_track.site_id, newguest.id, guest_track.id))
            return redirect(url_for('guest.authorize_guest',
                                    track_id=guest_track.track_id),
                            code=302)
        else:
            current_app.logger.debug(
                'Wifiguest Log - Site ID:%s voucher_login  in valid vouher value:%s for track ID:%s'
                % (guest_track.site_id, voucher_form.voucher.data,
                   guest_track.id))
            flash(u'Invalid Voucher ID', 'danger')

    landing_page = Landingpage.query.filter_by(
        id=landing_site.default_landing).first()
    return render_template('guest/%s/voucher_landing.html' %
                           landing_site.template,
                           landing_site=landing_site,
                           landing_page=landing_page,
                           voucher_form=voucher_form)
Example #11
0
def email_login(track_id):
    ''' Function to called if the site is configured with Social login    
    
    '''
    #
    #Validate track id and get all the needed variables
    guest_track = Guesttrack.query.filter_by(track_id=track_id).first()
    if not guest_track:
        current_app.logger.error("Called email_login with wrong track ID:%s" %
                                 track_id)
        abort(404)

    #validate session associated with this track ID
    guest_session = Guestsession.query.filter_by(
        id=guest_track.session_id).first()
    if not guest_session:
        current_app.logger.error(
            "Called email_login with wrong Session from track ID:%s" %
            track_id)
        abort(404)

    guest_device = Device.query.filter_by(id=guest_session.device_id).first()
    landing_site = Wifisite.query.filter_by(id=guest_session.site_id).first()
    if not guest_device or not landing_site:
        current_app.logger.error(
            "Called email_login with wrong Session/Device/Wifisite from track ID:%s"
            % track_id)
        abort(404)
    current_app.logger.debug(
        'Wifiguest Log - Site ID:%s email_login for track ID:%s' %
        (guest_track.site_id, guest_track.id))
    #
    #Check if the device already has a valid auth
    if guest_device.state == DEVICE_AUTH and guest_device.demo == 0:
        #Device has a guest element and is authorized
        guest_session.state = SESSION_AUTHORIZED
        guest_track.state = GUESTRACK_SOCIAL_PREAUTH
        guest_device.state = DEVICE_AUTH
        db.session.commit()
        #redirect to authorize_guest
        return redirect(url_for('guest.authorize_guest',
                                track_id=guest_track.track_id),
                        code=302)
    else:
        #show the configured landing page
        email_form = generate_emailform(landing_site.emailformfields)

        if email_form.validate_on_submit():
            newguest = Guest()
            newguest.populate_from_email_form(email_form,
                                              landing_site.emailformfields)
            newguest.site = landing_site
            db.session.add(newguest)
            db.session.commit()
            #New guest added create task for API export
            celery_export_api.delay(newguest.id)
            #mark sessions as authorized
            guest_session.state = SESSION_AUTHORIZED
            guest_track.state = GUESTRACK_NEW_AUTH
            guest_device.guest = newguest
            newguest.demo = guest_session.demo
            newguest.devices.append(guest_device)
            guest_device.state = DEVICE_AUTH
            db.session.commit()
            current_app.logger.debug(
                'Wifiguest Log - Site ID:%s email_login  new guest track ID:%s'
                % (guest_track.site_id, guest_track.id))
            return redirect(url_for('guest.authorize_guest',
                                    track_id=guest_track.track_id),
                            code=302)
        landing_page = Landingpage.query.filter_by(
            id=landing_site.default_landing).first()
        return render_template('guest/%s/email_landing.html' %
                               landing_site.template,
                               landing_site=landing_site,
                               landing_page=landing_page,
                               email_form=email_form)
Example #12
0
def facebook_login(track_id):
    ''' Function to called if the site is configured for advanced facebook authentication.
    
    '''
    #fbtrackform = FacebookTrackForm()
    auth_like = None
    auth_post = None
    #if fbtrackform.validate_on_submit():
    if request.method == 'POST':
        auth_like = request.form['authlike']
        auth_post = request.form['authpost']
    #Validate track id and get all the needed variables
    guest_track = Guesttrack.query.filter_by(track_id=track_id).first()
    if not guest_track:
        current_app.logger.error(
            "Called authorize_guest with wrong track ID:%s" % track_id)
        abort(404)

    #validate session associated with this track ID
    guest_session = Guestsession.query.filter_by(
        id=guest_track.session_id).first()
    if not guest_session:
        current_app.logger.error(
            "Called authorize_guest with wrong Session from track ID:%s" %
            track_id)
        abort(404)
    guest_device = Device.query.filter_by(id=guest_session.device_id).first()
    landing_site = Wifisite.query.filter_by(id=guest_session.site_id).first()
    if not guest_device or not landing_site:
        current_app.logger.error(
            "Called authorize_guest with wrong Session/Device/Wifisite from track ID:%s"
            % track_id)
        abort(404)

    # Attempt to get the short term access token for the current user.
    current_app.logger.debug(
        'Wifiguest Log - Site ID:%s facebook_login for track ID:%s' %
        (guest_track.site_id, guest_track.id))
    if auth_like != '1':  #ensure this is first time visit, not the visit after like/post
        fb_appid = landing_site.fb_appid or current_app.config['FB_APP_ID']
        fb_app_secret = landing_site.fb_app_secret or current_app.config[
            'FB_APP_SECRET']
        check_user_auth = get_user_from_cookie(cookies=request.cookies,
                                               app_id=fb_appid,
                                               app_secret=fb_app_secret)
        if not check_user_auth or not check_user_auth['uid']:
            #
            #User is not logged into DB app, redirect to social login page
            current_app.logger.debug(
                'Wifiguest Log - Site ID:%s facebook_login  Used not logged in, redirecting to social_login for track ID:%s'
                % (guest_track.site_id, guest_track.id))
            return redirect(url_for('guest.social_login', track_id=track_id),
                            code=302)

        #check this FB profile already added into our DB,else add it
        profile_check = Facebookauth.query.filter(
            and_(Facebookauth.profile_id == check_user_auth['uid'],
                 Facebookauth.site_id == landing_site.id)).first()
        if not profile_check:

            profile_check = Facebookauth()
            profile_check.profile_id = check_user_auth['uid']
            profile_check.token = check_user_auth['access_token']
            profile_check.site = landing_site
            db.session.add(profile_check)
            db.session.commit()
            current_app.logger.debug(
                'Wifiguest Log - Site ID:%s facebook_login  adding new FB profile ID:%s for track ID:%s'
                % (guest_track.site_id, profile_check.id, guest_track.id))

        #profile already added to DB, check if the user had already authorized the site
        guest_check = Guest.query.filter(
            and_(Guest.site_id == guest_session.site_id,
                 Guest.fb_profile == profile_check.id)).first()
        if not guest_check:
            #Guest entry for this user is not available in DB,add the same.
            try:
                graph = GraphAPI(check_user_auth['access_token'])
                profile = graph.get_object(
                    profile_check.profile_id +
                    '?locale=en_US&fields=name,email,first_name,last_name')
            except:
                #Exception while calling graph API, redirect user to same page to try again
                current_app.logger.exception(
                    'Wifiguest Log - Site ID:%s facebook_login  exception while API FB profile ID:%s for track ID:%s'
                    % (guest_track.site_id, guest_track.id, profile_check.id))
                return redirect(url_for('guest.facebook_login',
                                        track_id=track_id),
                                code=302)
            else:
                guest_check = Guest()
                guest_check.firstname = profile.get('first_name')
                guest_check.lastname = profile.get('last_name')
                guest_check.email = profile.get('email')
                guest_check.site_id = guest_session.site_id
                guest_check.facebookauth = profile_check
                profile_check.guests.append(guest_check)
                db.session.add(guest_check)
                db.session.commit()
                #New guest added create task for API export
                celery_export_api.delay(guest_check.id)
                current_app.logger.debug(
                    'Wifiguest Log - Site ID:%s facebook_login  adding new Guest:%s for track ID:%s'
                    % (guest_track.site_id, guest_check.id, guest_track.id))
        #
        #even if guest entry was already added, assign the guest to device
        guest_device.guest = guest_check
        guest_check.devices.append(guest_device)
        db.session.commit()
    else:
        guest_check = Guest.query.filter_by(id=guest_device.guest_id).first()
        if not guest_check:
            #
            #User is not logged into DB app, redirect to social login page
            current_app.logger.debug(
                'Wifiguest Log - Site ID:%s facebook_login  Used not logged in after like/post, redirecting to social_login for track ID:%s'
                % (guest_track.site_id, guest_track.id))
            return redirect(url_for('guest.social_login', track_id=track_id),
                            code=302)

    if landing_site.auth_fb_like == 1:
        if guest_track.fb_liked != 1:
            if guest_check.fb_liked:
                # if the guest has liked the page already, mark guesttrack as liked
                current_app.logger.debug(
                    'Wifiguest Log - Site ID:%s facebook_login  guest already liked for track ID:%s'
                    % (guest_track.site_id, guest_track.id))
                guest_track.fb_liked = 1
                db.session.commit()
            elif auth_like == '1':
                #quick hack to test for liking and posting, guest has skipped the liking, allow
                #internet for now and ask next time
                current_app.logger.debug(
                    'Wifiguest Log - Site ID:%s facebook_login  guest decided to skip  like for track ID:%s'
                    % (guest_track.site_id, guest_track.id))
                guest_track.fb_liked = 1
                db.session.commit()
            elif auth_like == '2':
                #user has liked the page mark track and guest as liked
                current_app.logger.debug(
                    'Wifiguest Log - Site ID:%s facebook_login  guest liked now for track ID:%s'
                    % (guest_track.site_id, guest_track.id))
                guest_track.fb_liked = 1
                guest_check.fb_liked = 1
                db.session.commit()
            else:
                # show page asking user to like
                current_app.logger.debug(
                    'Wifiguest Log - Site ID:%s facebook_login  new guest show page to like for track ID:%s'
                    % (guest_track.site_id, guest_track.id))
                landing_page = Landingpage.query.filter_by(
                    id=landing_site.default_landing).first()
                fb_page = landing_site.fb_page or current_app.config[
                    'FB_PAGE_URL']
                return render_template("guest/%s/fb_like.html" %
                                       landing_site.template,
                                       landing_page=landing_page,
                                       font_list=font_list,
                                       app_id=fb_appid,
                                       track_id=track_id,
                                       fb_page=fb_page)

    #mark sessions as authorized
    guest_session.state = SESSION_AUTHORIZED
    guest_track.state = GUESTRACK_NEW_AUTH
    if guest_check.fb_liked == 1:  # if guest has full filled all the social login criterias,mark the device as authed
        guest_device.state = DEVICE_AUTH
    db.session.commit()
    return redirect(url_for('guest.authorize_guest',
                            track_id=guest_track.track_id),
                    code=302)