Exemple #1
0
 def post(self,id): 
     if id is None:
         if not current_user.type == 'admin':
             current_app.logger.debug("Client trying to access unauthorized URL %s "%(request.url))
             return jsonify({'status': 0,'msg':'Not Authorized'})    
         num_sites = Wifisite.query.filter_by(account_id=current_user.account_id).count()        
         if  current_user.account.sites_allowed <= num_sites :
             return jsonify({'status': 0,'msg':'Not enough credit to create a site'})
          # create a new element
         form1 = self.get_form_obj()
         form1.populate()
         if  form1.validate_on_submit():  
             try:      
                 newitem = self.get_modal_obj()
                 db.session.add(newitem)
                 client = Client.query.filter_by(id=form1.client_id.data).first()
                 newitem.client = client
                 newitem.admin = current_user
                 newitem.account_id = current_user.account_id                
                 newitem.populate_from_form(form1)
                 newlanding = Landingpage()                         
                 db.session.add(newlanding)                   
                 db.session.commit()
                 newlanding.site = newitem
                 newitem.default_landing = newlanding.id      
                 newvoucherdesign = Voucherdesign()
                 newvoucherdesign.site =  newitem
                 db.session.add(newvoucherdesign)             
                 db.session.commit()
             except IntegrityError:
                 return jsonify({'status': 0,'msg':'Value already exists in the database for :%s'%self.entity_name})
             else:
                 return jsonify({'status': 1,'id':newitem.id,'msg':'Added New Entry for:%s into Database'%self.entity_name})
         else:
             return jsonify({'status':0,'msg': get_errors(form1)})
     else:
     # update a single item
         singleitem = self.get_modal_obj().query.filter_by(id=id).first()
         if singleitem:
             form1 = self.get_form_obj()
             form1.populate()
             if form1.validate_on_submit():                                
                 singleitem.populate_from_form(form1)
                 try:
                     db.session.commit()
                 except IntegrityError:
                     return jsonify({'status': 0,'msg':'Value already exists in the database for:%s'%self.entity_name})
                 else:
                     return jsonify({'status': 1,'msg':'Updated :%s'%self.entity_name})
                     
             else:
                 return jsonify({'status':0,'msg': get_errors(form1)})
         return jsonify({'status':0,'err': 'Some Error Occured while processing:%s'%self.entity_name})  
Exemple #2
0
 def post(self, id):
     account = Account.query.filter_by(id=current_user.account_id).first()
     if not account:
         return jsonify({'status': 0, 'msg': 'Not  Valid Account ID'})
     if id is None:
         # create a new element
         form1 = self.get_form_obj()
         form1.populate()
         if form1.validate_on_submit():
             try:
                 newitem = Admin()
                 newitem.populate_from_form(form1)
                 newitem.active = 1
                 newitem.account = account
                 db.session.add(newitem)
                 db.session.commit()
             except IntegrityError:
                 db.session.rollback()
                 db.session.flush()  # for resetting non-commited .add()
                 current_app.logger.error(
                     'Trying to add duplicate Admin Account with email:%s' %
                     newitem.email)
                 return jsonify({
                     'status':
                     0,
                     'msg':
                     'Value already exists in the database'
                 })
             else:
                 return jsonify({'status': 1, 'id': newitem.id})
         return jsonify({'status': 0, 'msg': get_errors(form1)})
     else:
         # update a single item
         singleitem = Admin.query.filter_by(id=id).first()
         if singleitem:
             form1 = self.get_form_obj()
             form1.populate()
             if form1.validate_on_submit():
                 singleitem.populate_from_form(form1)
                 try:
                     db.session.commit()
                 except IntegrityError:
                     return jsonify({
                         'status':
                         None,
                         'msg':
                         'Value already exists in the database'
                     })
                 return jsonify({'status': 1})
             else:
                 return jsonify({'status': 0, 'msg': get_errors(form1)})
         return jsonify({'status': 0, 'msg': 'unknown user'})
Exemple #3
0
    def post(self, id):
        account = Account.query.filter_by(id=current_user.account_id).first()

        if not account:
            return jsonify({'status': 0, 'msg': 'Not  Valid Account ID'})
        if id is None:

            # create a new element
            form1 = self.get_form_obj()
            form1.populate()
            if form1.validate_on_submit():
                try:
                    newitem = Client()
                    newitem.populate_from_form(form1)
                    newitem.active = 1
                    newitem.account = account
                    db.session.commit()

                    db.session.commit()
                except IntegrityError:
                    return jsonify({
                        'status':
                        0,
                        'msg':
                        'Value already exists in the database'
                    })
                return jsonify({'status': 1, 'id': newitem.id})
            return jsonify({'status': 0, 'msg': get_errors(form1)})
        else:
            # update a single item
            singleitem = Client.query.filter_by(id=id).first()
            if singleitem:
                form1 = self.get_form_obj()
                form1.populate()
                if form1.validate_on_submit():
                    singleitem.populate_from_form(form1)
                    try:
                        db.session.commit()
                    except IntegrityError:
                        return jsonify({
                            'status':
                            None,
                            'msg':
                            'Value already exists in the database'
                        })
                    return jsonify({'status': 1})
                else:
                    return jsonify({'status': 0, 'msg': get_errors(form1)})
            return jsonify({'status': 0, 'msg': 'unknown user'})
Exemple #4
0
 def post(self, id):
     if id is None:
         form1 = self.get_form_obj()
         form1.populate()
         if form1.validate_on_submit():
             account = Account.query.filter_by(
                 id=form1.account.data).first()
             if not account:
                 return jsonify({'status': None, 'err': 'Invalid Account'})
             newitem = Admin()
             newitem.populate_from_form(form1)
             newitem.active = 1
             newitem.account = account
             db.session.commit()
             try:
                 db.session.add(newitem)
                 db.session.commit()
             except IntegrityError:
                 return jsonify({
                     'status':
                     None,
                     'err':
                     'Value already exists in the database'
                 })
             return jsonify({'status': 1, 'id': newitem.id})
         return jsonify({'status': 0, 'err': get_errors(form1)})
     else:
         # update a single item
         singleitem = Admin.query.filter_by(id=id).first()
         if singleitem:
             form1 = self.get_form_obj()
             form1.populate()
             if form1.validate_on_submit():
                 singleitem.populate_from_form(form1)
                 singleitem.account_id = form1.account.data
                 try:
                     db.session.commit()
                 except IntegrityError:
                     return jsonify({
                         'status':
                         None,
                         'err':
                         'Value already exists in the database'
                     })
                 return jsonify({'status': 1})
             else:
                 return jsonify({'status': 0, 'err': get_errors(form1)})
         return jsonify({'status': 0, 'err': 'unknown user'})
Exemple #5
0
 def post(self, id):
     if id is None:
         return jsonify({'status': 0, 'msg': 'Not Authorized'})
     else:
         # update a single item
         singleitem = User.query.filter_by(id=id).first()
         if singleitem:
             form1 = self.get_form_obj()
             form1.populate()
             if form1.validate_on_submit():
                 singleitem.populate_from_form(form1)
                 try:
                     db.session.commit()
                 except IntegrityError:
                     return jsonify({
                         'status':
                         None,
                         'msg':
                         'Value already exists in the database'
                     })
                 return jsonify({'status': 1})
             else:
                 print form1.errors
                 return jsonify({'status': 0, 'msg': get_errors(form1)})
         return jsonify({'status': 0, 'msg': 'unknown user'})
Exemple #6
0
def authenticate_sms(track_id,guest_track,landing_site,guest_device):
    ''' View for authenticating guest's phone number before proceeding with further auth 
    
    '''
    #Check if the device already validated
    if  guest_device.sms_confirm == 1 and guest_device.demo == 0:
        return redirect(url_for('guest.multi_login',track_id=guest_track.track_id),code=302) 

    phoneform = PhonenumberForm()
    if phoneform.validate_on_submit():
        phonenumber   = phoneform.phonenumber.data
        authcode   = phoneform.authcode.data
        smsdata  = Smsdata.query.filter_by(device_id=guest_device.id,phonenumber=phonenumber,authcode=authcode).first()
        if smsdata:
            guest_device.sms_confirm = 1
            db.session.commit()
            current_app.logger.debug('Wifiguest Log - Site ID:%s authenticate_sms MAC:%s valid Phonenumber:%s \
                        authcode:%s'%(landing_site.id,guest_track.device_mac,phonenumber,authcode))   
            return redirect(url_for('guest.multi_login',track_id=guest_track.track_id),code=302) 

        else:
            current_app.logger.debug('Wifiguest Log - Site ID:%s authenticate_sms MAC:%s no SMSDATA found'%(landing_site.id,guest_track.device_mac))   
            flash("Wrong Phonenumber/auth code", 'danger')
    else:
        form_errors = get_errors(phoneform)
        current_app.logger.debug('Wifiguest Log - Site ID:%s authenticate_sms MAC:%s phoneform.errors:%s'%(landing_site.id,guest_track.device_mac,form_errors))   

    landing_page = Landingpage.query.filter_by(id=landing_site.default_landing).first()

    return render_template('guest/%s/sms_auth.html'%landing_site.template,landing_site=landing_site,landing_page=landing_page,phoneform=phoneform,track_id=track_id)          
Exemple #7
0
    def post(self,siteid,id):             
        if id is None:
        # create a new element
            form1 = self.get_form_obj()
            form1.populate()
            if  form1.validate_on_submit():                        
                wifisite = Wifisite.query.filter_by(id=siteid).first()
                #generate batch id
                batchid = str(uuid.uuid4())
                cnt = 0
                try:
                    while cnt < int(form1.number.data):  
                        cnt = cnt + 1  
                        newitem = self.get_modal_obj()   
                        newitem.populate_from_form(form1)          
                        #create voucher
                        random = randint(100, 999)  # randint is inclusive at both ends
                        hashid = Hashids(salt=current_app.config['HASH_SALT'],min_length=10)
                        newitem.voucher = hashid.encode(random,wifisite.id,wifisite.client_id)
                        newitem.batchid = batchid
                        newitem.site = wifisite                           
                        db.session.add(newitem)
                    db.session.commit()
                except :
                    current_app.logger.exception('Exception while trying create vouchers')
                    return jsonify({'status': 0,'msg':'Error while trying to create vouchers'})
                else:
                    return jsonify({'status': 1,'msg':'Added New Entry for:%s into Database'%self.entity_name})
            else:
                return jsonify({'status':0,'msg': get_errors(form1)})

        else:
            return jsonify({'status':0,'err': 'Voucher Editing is not allowed'})
Exemple #8
0
    def post(self,siteid,id):             
        if id is None:
        # create a new element
            form1 = self.get_form_obj()
            form1.populate(siteid)
            if  form1.validate_on_submit():        
                newitem = self.get_modal_obj()
                if form1.site_id.data != siteid:
                    current_app.logger.error("Wrong site_id is specified in form value!! Someone is trying to mess!! URL:%s"%request.url)
                    return jsonify({'status': 0,'msg':'Wrong Site ID specified!!'})

                newitem.populate_from_form(form1)
                try:
                    db.session.add(newitem)
                    db.session.commit()
                except IntegrityError:
                    return jsonify({'status': 0,'msg':'Value already exists in the database for :%s'%self.entity_name})
                else:
                    return jsonify({'status': 1,'id':newitem.id,'msg':'Added New Entry for:%s into Database'%self.entity_name})
            else:
                print_errors(form1)
                return jsonify({'status':0,'msg': get_errors(form1)})

        else:
        # update a single item
            singleitem = self.get_modal_obj().query.filter_by(id=id).first()
            if singleitem:
                form1 = self.get_form_obj()
                form1.populate(siteid)
                if form1.validate_on_submit():
                    if form1.site_id.data != siteid:
                        current_app.logger.error("Wrong site_id is specified in form value!! Someone is trying to mess!! URL:%s"%request.url)
                        return jsonify({'status': 0,'msg':'Wrong Site ID specified!!'})                    
                    singleitem.populate_from_form(form1)
                    try:
                        db.session.commit()
                    except IntegrityError:
                        return jsonify({'status': 0,'msg':'Value already exists in the database for:%s'%self.entity_name})
                    else:
                        return jsonify({'status': 1,'msg':'Updated :%s'%self.entity_name,'id':singleitem.id})
                else:
                    return jsonify({'status':0,'msg': get_errors(form1)})
            return jsonify({'status':0,'err': 'Some Error Occured while processing:%s'%self.entity_name})
Exemple #9
0
 def post(self,id): 
     account = Account.query.filter_by(id=current_user.account_id).first()
     if not account:
         return jsonify({'status': 0,'msg':'Not  Valid Account ID'})         
     if id is None:
         # create a new element
         form1 = self.get_form_obj()
         form1.populate()
         if  form1.validate_on_submit():
             try:
                 newitem = Admin()
                 newitem.populate_from_form(form1)
                 newitem.active = 1
                 newitem.account = account
                 db.session.add(newitem)
                 db.session.commit()
             except IntegrityError:
                 db.session.rollback()
                 db.session.flush() # for resetting non-commited .add()
                 current_app.logger.error('Trying to add duplicate Admin Account with email:%s'%newitem.email)
                 return jsonify({'status': 0,'msg':'Value already exists in the database'})
             else:
                 return jsonify({'status': 1,'id':newitem.id})
         return jsonify({'status': 0,'msg':get_errors(form1)})
     else:
         # update a single item
         singleitem = Admin.query.filter_by(id=id).first()
         if singleitem:
             form1 = self.get_form_obj()
             form1.populate()
             if form1.validate_on_submit():
                 singleitem.populate_from_form(form1)
                 try:
                     db.session.commit()
                 except IntegrityError:
                     return jsonify({'status': None,'msg':'Value already exists in the database'})
                 return jsonify({'status': 1})
             else:
                 return jsonify({'status':0,'msg': get_errors(form1)})
         return jsonify({'status':0,'msg': 'unknown user'})            
Exemple #10
0
 def post(self,id): 
     singleitem = Account().query.filter_by(id=current_user.account_id).first()
     form1 = self.get_form_obj()
     form1.populate()
     if  form1.validate_on_submit(): 
         singleitem.populate_settings(form1)
         try:
             db.session.commit()
         except IntegrityError:
             return jsonify({'status': 0,'msg':'Value already exists in the database'})
         return jsonify({'status': 1})
     else:
         return jsonify({'status':0,'msg': get_errors(form1)})
Exemple #11
0
    def post(self,id): 
        account = Account.query.filter_by(id=current_user.account_id).first()

        if not account:
            return jsonify({'status': 0,'msg':'Not  Valid Account ID'})             
        if id is None:

            # create a new element
            form1 = self.get_form_obj()
            form1.populate()
            if  form1.validate_on_submit():
                try:
                    newitem = Client()
                    newitem.populate_from_form(form1)
                    newitem.active = 1
                    newitem.account = account
                    db.session.commit()               
                    
                    db.session.commit()
                except IntegrityError:
                    return jsonify({'status': 0,'msg':'Value already exists in the database'})
                return jsonify({'status': 1,'id':newitem.id})
            return jsonify({'status': 0,'msg':get_errors(form1)})
        else:
            # update a single item
            singleitem = Client.query.filter_by(id=id).first()
            if singleitem:
                form1 = self.get_form_obj()
                form1.populate()
                if form1.validate_on_submit():
                    singleitem.populate_from_form(form1)
                    try:
                        db.session.commit()
                    except IntegrityError:
                        return jsonify({'status': None,'msg':'Value already exists in the database'})
                    return jsonify({'status': 1})
                else:
                    return jsonify({'status':0,'msg': get_errors(form1)})
            return jsonify({'status':0,'msg': 'unknown user'})            
Exemple #12
0
 def post(self,id):    
     if id is None:
         form1 = self.get_form_obj()
         form1.populate()
         if  form1.validate_on_submit():
             account = Account.query.filter_by(id=form1.account.data).first()
             if not account:
                 return jsonify({'status': None,'err':'Invalid Account'})
             newitem = Admin()
             newitem.populate_from_form(form1)
             newitem.active = 1
             newitem.account = account
             db.session.commit()
             try:
                 db.session.add(newitem)
                 db.session.commit()
             except IntegrityError:
                 return jsonify({'status': None,'err':'Value already exists in the database'})
             return jsonify({'status': 1,'id':newitem.id})
         return jsonify({'status': 0,'err':get_errors(form1)})
     else:
         # update a single item
         singleitem = Admin.query.filter_by(id=id).first()
         if singleitem:
             form1 = self.get_form_obj()
             form1.populate()
             if form1.validate_on_submit():
                 singleitem.populate_from_form(form1)
                 singleitem.account_id = form1.account.data
                 try:
                     db.session.commit()
                 except IntegrityError:
                     return jsonify({'status': None,'err':'Value already exists in the database'})
                 return jsonify({'status': 1})
             else:
                 return jsonify({'status':0,'err': get_errors(form1)})
         return jsonify({'status':0,'err': 'unknown user'})     
Exemple #13
0
    def post(self,id):
        if id is None:
        # create a new element
            form1 = self.get_form_obj()
            form1.populate()
            if  form1.validate_on_submit():        
                newitem = self.get_modal_obj()
                newitem.populate_from_form(form1)
                try:
                    db.session.add(newitem)
                    db.session.commit()
                except IntegrityError:
                    return jsonify({'status': None,'msg':'Value already exists in the database for :%s'%self.entity_name})
                else:
                    return jsonify({'status': 1,'id':newitem.id,'msg':'Added New Entry for:%s into Database'%self.entity_name})
            else:
                print_errors(form1)
                return jsonify({'status':0,'msg': get_errors(form1)})

        else:
        # update a single item
            singleitem = self.get_modal_obj().query.filter_by(id=id).first()
            if singleitem:
                form1 = self.get_form_obj()
                form1.populate()
                if form1.validate_on_submit():
                    singleitem.populate_from_form(form1)
                    try:
                        db.session.commit()
                    except IntegrityError:
                        return jsonify({'status': None,'msg':'Value already exists in the database for:%s'%self.entity_name})
                    else:
                        return jsonify({'status': 1,'msg':'Updated :%s'%self.entity_name,'id':singleitem.id})
            else:
                return jsonify({'status':0,'msg': get_errors(form1)})
            return jsonify({'status':0,'err': 'Some Error Occured while processing:%s'%self.entity_name})
Exemple #14
0
 def post(self, id):
     singleitem = Account().query.filter_by(
         id=current_user.account_id).first()
     form1 = self.get_form_obj()
     form1.populate()
     if form1.validate_on_submit():
         singleitem.populate_settings(form1)
         try:
             db.session.commit()
         except IntegrityError:
             return jsonify({
                 'status': 0,
                 'msg': 'Value already exists in the database'
             })
         return jsonify({'status': 1})
     else:
         return jsonify({'status': 0, 'msg': get_errors(form1)})
Exemple #15
0
 def post(self,id): 
     if id is None:
          return jsonify({'status': 0,'msg':'Not Authorized'})    
     else:
         # update a single item
         singleitem = User.query.filter_by(id=id).first()
         if singleitem:
             form1 = self.get_form_obj()
             form1.populate()
             if form1.validate_on_submit():
                 singleitem.populate_from_form(form1)
                 try:
                     db.session.commit()
                 except IntegrityError:
                     return jsonify({'status': None,'msg':'Value already exists in the database'})
                 return jsonify({'status': 1})
             else:
                 print  form1.errors
                 return jsonify({'status':0,'msg': get_errors(form1)})
         return jsonify({'status':0,'msg': 'unknown user'})            
Exemple #16
0
    def post(self, id):
        if id is None:
            # create a new element
            form1 = self.get_form_obj()
            form1.populate()
            if form1.validate_on_submit():
                newitem = self.get_modal_obj()
                newitem.populate_from_form(form1)
                try:
                    db.session.add(newitem)
                    db.session.commit()
                except IntegrityError:
                    return jsonify({
                        'status':
                        None,
                        'msg':
                        'Value already exists in the database for :%s' %
                        self.entity_name
                    })
                else:
                    return jsonify({
                        'status':
                        1,
                        'id':
                        newitem.id,
                        'msg':
                        'Added New Entry for:%s into Database' %
                        self.entity_name
                    })
            else:
                print_errors(form1)
                return jsonify({'status': 0, 'msg': get_errors(form1)})

        else:
            # update a single item
            singleitem = self.get_modal_obj().query.filter_by(id=id).first()
            if singleitem:
                form1 = self.get_form_obj()
                form1.populate()
                if form1.validate_on_submit():
                    singleitem.populate_from_form(form1)
                    try:
                        db.session.commit()
                    except IntegrityError:
                        return jsonify({
                            'status':
                            None,
                            'msg':
                            'Value already exists in the database for:%s' %
                            self.entity_name
                        })
                    else:
                        return jsonify({
                            'status': 1,
                            'msg': 'Updated :%s' % self.entity_name,
                            'id': singleitem.id
                        })
            else:
                return jsonify({'status': 0, 'msg': get_errors(form1)})
            return jsonify({
                'status':
                0,
                'err':
                'Some Error Occured while processing:%s' % self.entity_name
            })