Example #1
0
def init_data():
    with app.app_context():
        from sqlalchemy.exc import OperationalError
        from flask_security.utils import encrypt_password
        from unifispot.models import User
        from unifispot.superadmin.models import Account
        from unifispot.admin.models import Admin
        try:
            account = Account.query.filter_by(id=1).first()
        except:
            app.logger.debug(
                "No Account table Entry found,could be running migration ")
        else:
            if not account:
                #create default admin user
                enc_pass = encrypt_password('password')
                account = Account()
                db.session.add(account)
                admin_user = Admin(email='*****@*****.**',
                                   password=enc_pass,
                                   displayname="Admin User",
                                   active=1)
                admin_user.account = account
                db.session.add(admin_user)
                db.session.commit()
Example #2
0
def populate_admins():
    #add 50 admin elements
    from flask_security.utils import encrypt_password
    from unifispot.superadmin.models import Account
    enc_pass        = encrypt_password('zaqxswcdevfr1')
    account         = Account.query.filter_by(id=3).first()   
    for i in range(50):
        admn = Admin(email='*****@*****.**'%i,password=enc_pass,displayname= "ABC_ADMIN%s"%i)
        admn.account = account
        db.session.add(admn)          
Example #3
0
def populate_admins():
    #add 50 admin elements
    from flask.ext.security.utils import encrypt_password
    from unifispot.superadmin.models import Account
    enc_pass        = encrypt_password('zaqxswcdevfr1')
    account         = Account.query.filter_by(id=3).first()   
    for i in range(50):
        admn = Admin(email='*****@*****.**'%i,password=enc_pass,displayname= "ABC_ADMIN%s"%i)
        admn.account = account
        db.session.add(admn)          
Example #4
0
 def get(self, id):
     if id is None:
         modal_filter = {'account_id': current_user.account_id}
         # return a list of all elements
         results = self.datatable_obj(request, self.columns,
                                      self.index_column, db, Admin(),
                                      modal_filter).output_result()
         return jsonify(results)
     else:
         #Returns a single element
         singleitem = Admin.query.filter_by(id=id).first()
         if singleitem:
             return jsonify({
                 'status':
                 1,
                 'data':
                 singleitem.to_dict(),
                 'msg':
                 'Successfully returning :%s' % self.entity_name
             })
         else:
             return jsonify({
                 'status':
                 0,
                 'msg':
                 'Invalid ID Specified for %s' % self.entity_name
             })
Example #5
0
 def get(self, id):
     if id is None:
         modal_filter = None
         # return a list of all elements
         results = self.datatable_obj(request, self.columns,
                                      self.index_column, db, Admin(),
                                      modal_filter).output_result()
         return jsonify(results)
     return super(AdminAPI, self).get(id)
Example #6
0
def init_data():
    with app.app_context():
        from  sqlalchemy.exc import OperationalError    
        from flask_security.utils import encrypt_password
        from unifispot.models import User  
        from unifispot.superadmin.models import Account
        from unifispot.admin.models import Admin       
        try:
            account = Account.query.filter_by(id=1).first()
        except :
            app.logger.debug( "No Account table Entry found,could be running migration ")
        else:
            if not account:
                #create default admin user
                enc_pass        = encrypt_password('password')
                account         = Account()
                db.session.add(account)
                admin_user = Admin(email='*****@*****.**',password=enc_pass,displayname= "Admin User",active=1)
                admin_user.account = account
                db.session.add(admin_user)
                db.session.commit()
Example #7
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'})            
Example #8
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'})     
Example #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'})
Example #10
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'})
Example #11
0
 def get_modal_obj(self):
     return Admin()
Example #12
0
def demo_init():
    with app.app_context():
        from sqlalchemy.exc import OperationalError
        from flask_security.utils import encrypt_password
        from unifispot.models import User
        from unifispot.superadmin.models import Account
        from unifispot.admin.models import Admin
        from unifispot.client.models import Client, Wifisite, Landingpage, Voucherdesign
        from unifispot.guest.models import Guest
        import arrow
        from random import randint
        from unifispot.analytics.models import Sitestat
        from unifispot.base.utils.helper import get_random_integers
        from faker import Factory
        fake = Factory.create()

        try:
            account = Account.query.filter_by(id=1).first()
        except:
            app.logger.debug(
                "No Account table Entry found,could be running migration ")
        else:
            if not account:
                #create default admin user
                enc_pass = encrypt_password('password')
                account = Account()
                db.session.add(account)
                admin_user = Admin(email='*****@*****.**',
                                   password=enc_pass,
                                   displayname="Admin User1",
                                   active=1)
                admin_user2 = Admin(email='*****@*****.**',
                                    password=enc_pass,
                                    displayname="Admin User2",
                                    active=1)
                admin_user3 = Admin(email='*****@*****.**',
                                    password=enc_pass,
                                    displayname="Admin User3",
                                    active=1)
                admin_user.account = account
                admin_user2.account = account
                admin_user3.account = account
                db.session.add(admin_user)
                db.session.add(admin_user2)
                db.session.add(admin_user3)
                client_user1 = Client(email='*****@*****.**',
                                      password=enc_pass,
                                      displayname="client1",
                                      active=1)
                db.session.add(client_user1)
                client_user1.account = account
                site1 = Wifisite(name='Client1 Site1',
                                 unifi_id='site1',
                                 auth_fb_like=1,
                                 timezone="Europe/Copenhagen",
                                 auth_method=AUTH_TYPE_ALL,
                                 smsauth=1)
                db.session.add(site1)
                site1.account = account
                site1.client = client_user1
                landing1 = Landingpage()
                landing1.site = site1
                site1.landingpages.append(landing1)
                db.session.add(landing1)
                db.session.commit()
                site1.default_landing = landing1.id
                design1 = Voucherdesign()
                design1.site = site1
                db.session.add(design1)
                db.session.commit()
                site2 = Wifisite(name='Client1 Site2',
                                 unifi_id='site1',
                                 auth_fb_like=1,
                                 timezone="Europe/Copenhagen",
                                 auth_method=AUTH_TYPE_ALL,
                                 smsauth=1)
                db.session.add(site2)
                site2.account = account
                site2.client = client_user1
                landing2 = Landingpage()
                landing2.site = site2
                site1.landingpages.append(landing2)
                db.session.add(landing2)
                db.session.commit()
                design2 = Voucherdesign()
                design2.site = site2
                db.session.add(design2)
                site1.default_landing = landing2.id
                db.session.commit()
                ##-----------------------Stats for site1
                now = arrow.now()
                month_start = now.floor('month')
                days = (now.ceil('month') - month_start).days
                for i in range(days):
                    day_key = month_start.replace(days=i).floor('day').naive
                    daystat = Sitestat(site_id=site1.id, date=day_key)
                    num_visits = randint(10, 50)
                    num_logins = randint(5, num_visits)
                    num_newlogins = randint(5, num_logins)
                    logins = get_random_integers(4, num_logins)
                    daystat.num_visits = num_visits
                    daystat.num_likes = randint(1, 10)
                    daystat.num_checkins = randint(1, 10)
                    daystat.num_newlogins = num_newlogins
                    daystat.num_repeats = num_logins - num_newlogins
                    daystat.num_emails = logins[0]
                    daystat.num_fb = logins[1]
                    daystat.num_vouchers = logins[2]
                    daystat.num_phones = logins[3]
                    db.session.add(daystat)
                db.session.commit()
                ##-----------------------Stats for site2
                for i in range(days):
                    day_key = month_start.replace(days=i).floor('day').naive
                    daystat = Sitestat(site_id=site2.id, date=day_key)
                    num_visits = randint(10, 50)
                    num_logins = randint(5, num_visits)
                    num_newlogins = randint(5, num_logins)
                    logins = get_random_integers(4, num_logins)
                    daystat.num_visits = num_visits
                    daystat.num_likes = randint(1, 10)
                    daystat.num_checkins = randint(1, 10)
                    daystat.num_newlogins = num_newlogins
                    daystat.num_repeats = num_logins - num_newlogins
                    daystat.num_emails = logins[0]
                    daystat.num_fb = logins[1]
                    daystat.num_vouchers = logins[2]
                    daystat.num_phones = logins[3]
                    db.session.add(daystat)
                db.session.commit()
                ##------------------guests for site1
                for i in range(100):
                    db.session.add(
                        Guest(firstname=fake.first_name(),
                              lastname=fake.last_name(),
                              email=fake.email()))
                db.session.commit()
Example #13
0
def init_data(session):

    account1 = Account(name='Account1')
    account2 = Account(name='Account2')
    account3 = Account(name='Account3')
    account4 = Account(name='Account4')
    account5 = Account(name='Account5')
    session.add(account1)
    session.add(account2)
    session.add(account3)
    session.add(account4)
    session.add(account5)
    ##----------------Add users which will be used always---------
    enc_pass        = encrypt_password('zaqxswcdevfr1')
    admin_user1      = Admin(email='*****@*****.**',password=enc_pass,displayname= "Admin1",active=1)
    admin_user2      = Admin(email='*****@*****.**',password=enc_pass,displayname= "Admin2",active=1)
    admin_user3      = Admin(email='*****@*****.**',password=enc_pass,displayname= "TEST Admin1",active=1)
    admin_user4      = Admin(email='*****@*****.**',password=enc_pass,displayname= "TEST Admin2",active=1)
    admin_user5      = Admin(email='*****@*****.**',password=enc_pass,displayname= "TEST Admin3",active=1)
    admin_user6      = Admin(email='*****@*****.**',password=enc_pass,displayname= "TEST Admin4",active=1)
    session.add(admin_user1)
    session.add(admin_user2)
    session.add(admin_user3)
    session.add(admin_user4)
    session.add(admin_user5)
    session.add(admin_user6)
    admin_user1.account = account1
    admin_user2.account = account1
    admin_user3.account = account2
    admin_user4.account = account2
    admin_user5.account = account2
    admin_user6.account = account2

    enc_pass        = encrypt_password('zaqxswcdevfr1')
    client_user1      = Client(email='*****@*****.**',password=enc_pass,displayname= "client1",active=1)
    client_user2      = Client(email='*****@*****.**',password=enc_pass,displayname= "client2",active=1)
    client_user3      = Client(email='*****@*****.**',password=enc_pass,displayname= "client2",active=1)
    session.add(client_user1)
    session.add(client_user2)
    session.add(client_user3)
    client_user1.account = account1
    client_user2.account = account2
    client_user3.account = account1



    #
    #------------site1 will be configured with some basic settings for the landing page--
    #Used to test social landing
    site1           = Wifisite(name='Client1 Site1',unifi_id='site1',auth_fb_like=1,timezone="Europe/Copenhagen",auth_method= AUTH_TYPE_ALL)    
    site2           = Wifisite(name='Client1 Site2',unifi_id='site2',timezone="Europe/Copenhagen",auth_method= AUTH_TYPE_ALL)
    site3           = Wifisite(name='Client2 Site1',unifi_id='site3',timezone="Europe/Copenhagen",auth_method= AUTH_TYPE_ALL)
    session.add(site1)
    session.add(site2)
    session.add(site3)
    site1.account   = account1
    site2.account   = account1
    site3.account   = account2
    site1.client    = client_user1
    site2.client    = client_user1
    site3.client    = client_user2
    session.commit()
    
    
     
    landing1        = Landingpage()   
    landing1.site           = site1
    site1.landingpages.append(landing1) 
    session.add(landing1)
    session.commit()    
    site1.default_landing = landing1.id    
    landing2        = Landingpage()
    landing2.site   = site2
    session.add(landing2)
    session.commit()
    site2.landingpages.append(landing2)
    session.add(landing2)
    site2.default_landing = landing2.id 
    session.commit()

    landing3        = Landingpage()
    landing3.site   = site3
    session.add(landing3)
    session.commit()  
    site3.landingpages.append(landing3)
    session.add(landing3)
    site3.default_landing = landing3.id 
    session.commit()    
Example #14
0
def demo_init():
    with app.app_context():
        from  sqlalchemy.exc import OperationalError    
        from flask_security.utils import encrypt_password
        from unifispot.models import User  
        from unifispot.superadmin.models import Account
        from unifispot.admin.models import Admin       
        from unifispot.client.models import Client,Wifisite,Landingpage 
        from unifispot.guest.models import Guest
        import arrow
        from random import randint 
        from unifispot.analytics.models import Sitestat  
        from unifispot.base.utils.helper import get_random_integers 
        from faker import Factory
        fake = Factory.create()

        try:
            account = Account.query.filter_by(id=1).first()
        except :
            app.logger.debug( "No Account table Entry found,could be running migration ")
        else:
            if not account:
                #create default admin user
                enc_pass        = encrypt_password('password')
                account         = Account()
                db.session.add(account)
                admin_user  = Admin(email='*****@*****.**',password=enc_pass,displayname= "Admin User1",active=1)
                admin_user2 = Admin(email='*****@*****.**',password=enc_pass,displayname= "Admin User2",active=1)
                admin_user3 = Admin(email='*****@*****.**',password=enc_pass,displayname= "Admin User3",active=1)
                admin_user.account = account
                admin_user2.account = account
                admin_user3.account = account
                db.session.add(admin_user)
                db.session.add(admin_user2)
                db.session.add(admin_user3)
                client_user1      = Client(email='*****@*****.**',password=enc_pass,displayname= "client1",active=1)
                db.session.add(client_user1)
                client_user1.account = account
                site1           = Wifisite(name='Client1 Site1',unifi_id='site1',auth_fb_like=1,timezone="Europe/Copenhagen",
                                        auth_method= AUTH_TYPE_ALL,smsauth=1)    
                db.session.add(site1)
                site1.account   = account
                site1.client    = client_user1
                landing1        = Landingpage()   
                landing1.site           = site1
                site1.landingpages.append(landing1) 
                db.session.add(landing1)
                db.session.commit()    
                site1.default_landing = landing1.id                  
                db.session.commit()
                site2           = Wifisite(name='Client1 Site2',unifi_id='site1',auth_fb_like=1,timezone="Europe/Copenhagen",
                                        auth_method= AUTH_TYPE_ALL,smsauth=1)    
                db.session.add(site2)
                site2.account   = account
                site2.client    = client_user1
                landing2        = Landingpage()   
                landing2.site           = site2
                site1.landingpages.append(landing2) 
                db.session.add(landing2)
                db.session.commit()    
                site1.default_landing = landing2.id                  
                db.session.commit()
                ##-----------------------Stats for site1
                now = arrow.now()
                month_start = now.floor('month')
                days        = (now.ceil('month') - month_start).days
                for i in range(days):
                    day_key = month_start.replace(days=i).floor('day').naive
                    daystat = Sitestat(site_id=site1.id,date=day_key)
                    num_visits             = randint(10,50)
                    num_logins             = randint(5,num_visits)
                    num_newlogins          = randint(5,num_logins) 
                    logins                 = get_random_integers(4,num_logins)
                    daystat.num_visits     = num_visits
                    daystat.num_likes      = randint(1,10)
                    daystat.num_checkins   = randint(1,10)
                    daystat.num_newlogins  = num_newlogins
                    daystat.num_repeats    = num_logins - num_newlogins
                    daystat.num_emails     = logins[0]
                    daystat.num_fb         = logins[1]
                    daystat.num_vouchers   = logins[2]
                    daystat.num_phones     = logins[3]
                    db.session.add(daystat)
                db.session.commit()                
                ##-----------------------Stats for site2
                for i in range(days):
                    day_key = month_start.replace(days=i).floor('day').naive
                    daystat = Sitestat(site_id=site2.id,date=day_key)
                    num_visits             = randint(10,50)
                    num_logins             = randint(5,num_visits)
                    num_newlogins          = randint(5,num_logins) 
                    logins                 = get_random_integers(4,num_logins)
                    daystat.num_visits     = num_visits
                    daystat.num_likes      = randint(1,10)
                    daystat.num_checkins   = randint(1,10)
                    daystat.num_newlogins  = num_newlogins
                    daystat.num_repeats    = num_logins - num_newlogins
                    daystat.num_emails     = logins[0]
                    daystat.num_fb         = logins[1]
                    daystat.num_vouchers   = logins[2]
                    daystat.num_phones     = logins[3]
                    db.session.add(daystat)
                db.session.commit()     
                ##------------------guests for site1
                for i in range(100):
                    db.session.add(Guest(firstname=fake.first_name(),lastname=fake.last_name(),email=fake.email()))
                db.session.commit()