def temp_authorize_guest(track_id): '''Function for giving temporary internet access for a client This function send API commands to controller, return ok ''' guest_track = Guesttrack.query.filter_by(track_id=track_id).first() if not guest_track: current_app.logger.error("Called temp_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 temp_authorize_guest with wrong Session from track ID:%s"%track_id) abort(404) guest_track.state =GUESTRACK_TEMP_AUTH db.session.commit() #get details from track ID and authorize if not current_app.config['NO_UNIFI'] : try: c = Controller(current_app.config['LANDINGSITE']['unifihost'], current_app.config['LANDINGSITE']['unifiadmin'], current_app.config['LANDINGSITE']['unifipass'],current_app.config['LANDINGSITE']['unifiport'],current_app.config['LANDINGSITE']['unifiversion'],current_app.config['LANDINGSITE']['unifisiteid']) c.authorize_guest(guest_track.device_mac,5,ap_mac=guest_track.ap_mac) except: current_app.logger.exception('Exception occured while trying to authorize User') return jsonify({'status':0,'msg': "Error!!"}) return jsonify({'status':1,'msg': "DONE"}) else: return jsonify({'status':1,'msg': "DEBUG enabled"})
def authorize_guest(track_id): '''Function called after respective auth mechanisms are completed This function send API commands to controller, redirect user to correct URL ''' # #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) #Check if the session is authorized if not guest_session.state == SESSION_AUTHORIZED: current_app.logger.error("Called authorize_guest with wrong Non Authorized session with track ID:%s"%track_id) abort(404) #Send unifi API commands if the user has completed login if not current_app.config['NO_UNIFI'] : #code to send auth command to controller try: c = Controller(current_app.config['LANDINGSITE']['unifihost'], current_app.config['LANDINGSITE']['unifiadmin'], current_app.config['LANDINGSITE']['unifipass'],current_app.config['LANDINGSITE']['unifiport'],current_app.config['LANDINGSITE']['unifiversion'],current_app.config['LANDINGSITE']['unifisiteid']) c.authorize_guest(guest_track.device_mac,guest_session.duration,ap_mac=guest_track.ap_mac) except: current_app.logger.exception('Exception occured while trying to authorize User') return "Error Occured!" #Code to handle guest after successful login if current_app.config['LANDINGSITE']['redirecturl']: return redirect(format_url(current_app.config['LANDINGSITE']['redirecturl'])) elif guest_track.orig_url is not None: #redirect User's URL return redirect(format_url(guest_track.orig_url)) else: #redirect user to google.com return redirect(format_url("www.google.com"),code=302)