Esempio n. 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                     
                 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()
             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})  
Esempio n. 2
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})
Esempio n. 3
0
File: api.py Progetto: crypex/poppet
    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})
Esempio n. 4
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
            })
Esempio n. 5
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
                 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()
             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
         })