예제 #1
0
def Register():

    error = None

    if not session.get('username'):

        if request.method == 'POST':

            firstname = request.form['firstname']
            lastname = request.form['lastname']
            email = request.form['email']
            number = request.form['number']

            if len(email) < 5:
                error = 'The email is invalid'
            elif len(firstname) < 1:
                error = 'The firstname cannot be empty'
            elif len(lastname) < 1:
                error = 'The lastname cannot be empty'
            else:
                db.session.commit(
                )  ###### commit to the database to refresh it
                system = System()
                account = system.account()

                response = User(email).register(firstname, lastname, email,
                                                account, number)
                if response == 1:
                    error = 'No record inserted, the email (' + email + ') already exist'

                else:

                    session['username'] = email
                    msg = Message(
                        "Registration successfull, your registration details ",
                        sender=app.config["DEFAULT_MAIL_SENDER"],
                        recipients=[email])
                    msg.html = render_template("reg-email.html",
                                               firstname=firstname,
                                               lastname=lastname,
                                               account=account,
                                               email=email)
                    thr = Thread(target=send_async_email_test, args=[app, msg])
                    thr.start()
                    flash("Logged In")
                    db.session.commit(
                    )  ####### commit to the database to refresh it
                    login_user = system.getUser(session.get('username'))
                    return redirect(url_for('Home'))
        return render_template('register.html', error=error)
    db.session.rollback(
    )  ################ commit to the database to refresh it
    system = System()
    login_user = system.getUser(session.get('username'))
    return redirect('/home')
예제 #2
0
def Login():    

    if not session.get('username'):

        if request.method == 'POST':

            error = None
            email = request.form['email']
            account = request.form['account']
            if len(email) < 5:
                abort(400,'The email address is too short')
            elif len(account) < 1:
                abort(400,'No account number specified')
            response = User(email).login(account)
            if response == 1:
                flash("Logged In")
                session['username'] = email
                login_user = System().getUser(session.get('username'))
                return redirect('/home')
            error = 'Invalid login credentials'
            return render_template('login.html', error=error)
        return render_template('login.html')
    system = System()
    login_user = system.getUser(session.get('username'))
    return render_template('home.html', login_user=login_user)
예제 #3
0
def Login():

    if not session.get('username'):

        if request.method == 'POST':

            error = None
            email = request.form['email']
            account = request.form['account']
            if len(email) < 5:
                abort(400, 'The email address is too short')
            elif len(account) < 1:
                abort(400, 'No account number specified')
            response = User(email).login(account)
            if response == 1:
                flash("Logged In")
                session['username'] = email
                login_user = System().getUser(session.get('username'))
                return redirect('/home')
            error = 'Invalid login credentials'
            return render_template('login.html', error=error)
        return render_template('login.html')
    system = System()
    login_user = system.getUser(session.get('username'))
    return render_template('home.html', login_user=login_user)
예제 #4
0
def user_edit(user_id=None):

    if session.get('username'):

        system = System()
        login_user = system.getUser(session.get('username'))
        user = system.getUserById(user_id)
        error = None
        if not user:
            return redirect('/customers')
        if request.method == 'POST':

            firstname = request.form['first_name']
            lastname = request.form['last_name']
            origin = request.form['number']
            user.first_name =firstname
            user.last_name =lastname
            user.number =origin
            try:
                db.session.commit()
                error = "Update successfull"
            except:
                error = "No update made, check Internet connectivity"
            return render_template('user-edit.html', login_user=login_user, user=user, error=error)
        return render_template('user-edit.html', login_user=login_user, user=user, error=error)

    return redirect('/')
예제 #5
0
def Pin():


    if session.get('username'):

        system = System()
        pins = system.pins()
        login_user = system.getUser(session.get('username'))
        error = None

        if request.method == "POST":

            
            email = session.get('username')
            response = User(email).createPins()

            if type(response) is int:

                error = 'Error ' + str(response)
                return render_template('pin.html', login_user=login_user, error=error, pins=pins)
            else:

                error = response
                return render_template('pin.html', login_user=login_user, error=error, pins=pins)
        return render_template('pin.html', login_user=login_user, error=error, pins=pins)


    return redirect(url_for("Index"))
예제 #6
0
def countries():
    if session.get('username'):

        system = System()
        countries = system.countries()
        login_user = system.getUser(session.get('username'))
        error = None
        if request.method == 'POST':

            country = request.form['country']
            region = request.form['region']

            if len(country) < 1:
                abort(400, 'No country entered')
            elif len(region) < 1:
                abort(400, 'No region selected')

            email = session.get('username')
            response = User(email).createCountry(region,country)
            if response == 0:
                error = country + ' added to region ' + region+', refresh browser to see update'
                flash("Country added Successfully")
                return render_template('country.html', login_user=login_user, error=error,countries=countries)
            if response == 506:

                abort(400,'No data insertion was made, please check Internet connectivity')
            if response == 1:
                error = country + ' already exist'
                return render_template('country.html', login_user=login_user, error=error,countries=countries)
        return render_template('country.html', login_user=login_user, error=error,countries=countries)

    return redirect(url_for("Index"))
예제 #7
0
def Pin():

    if session.get('username'):

        system = System()
        pins = system.pins()
        login_user = system.getUser(session.get('username'))
        error = None

        if request.method == "POST":

            email = session.get('username')
            response = User(email).createPins()

            if type(response) is int:

                error = 'Error ' + str(response)
                return render_template('pin.html',
                                       login_user=login_user,
                                       error=error,
                                       pins=pins)
            else:

                error = response
                return render_template('pin.html',
                                       login_user=login_user,
                                       error=error,
                                       pins=pins)
        return render_template('pin.html',
                               login_user=login_user,
                               error=error,
                               pins=pins)

    return redirect(url_for("Index"))
예제 #8
0
def user_edit(user_id=None):

    if 'username' in session:

        system = System()
        login_user = system.getUser(session.get('username'))
        user = system.getUserById(user_id)
        error = None
        if not user:
            return redirect('/customers')
        if request.method == 'POST':

            firstname = request.form['first_name']
            lastname = request.form['last_name']
            origin = request.form['number']
            user.first_name = firstname
            user.last_name = lastname
            user.number = origin
            try:
                db.session.commit()
                error = "Update successfull"
            except:
                error = "No update made, check Internet connectivity"
            return render_template('user-edit.html',
                                   login_user=login_user,
                                   user=user,
                                   error=error)
        return render_template('user-edit.html',
                               login_user=login_user,
                               user=user,
                               error=error)

    return redirect('/')
예제 #9
0
def Register():

    error = None

    if not session.get('username'):


        if request.method == 'POST':

            firstname = request.form['firstname']
            lastname = request.form['lastname']
            email = request.form['email']
            number = request.form['number']
            

            if len(email) < 5:
                error = 'The email is invalid'
            elif len(firstname) < 1:
                error = 'The firstname cannot be empty'
            elif len(lastname) < 1:
                error = 'The lastname cannot be empty'
            else:
                db.session.commit() ###### commit to the database to refresh it
                system = System()
                account = system.account()

                response = User(email).register(firstname,lastname,email,account,number)
                if response == 1:
                    error = 'No record inserted, the email ('+email+') already exist'
                    
                else:

                    session['username'] = email
                    msg = Message("Registration successfull, your registration details ",sender=app.config["DEFAULT_MAIL_SENDER"],recipients=[email])
                    msg.html = render_template("reg-email.html",firstname=firstname,lastname=lastname,account=account,email=email)
                    thr = Thread(target=send_async_email_test, args=[app, msg])
                    thr.start()
                    flash("Logged In")
                    db.session.commit() ####### commit to the database to refresh it
                    login_user = system.getUser(session.get('username'))
                    return redirect(url_for('Home'))
        return render_template('register.html', error=error)
    db.session.rollback() ################ commit to the database to refresh it
    system = System()
    login_user = system.getUser(session.get('username'))
    return redirect('/home')
예제 #10
0
def users():

    if session.get('username'):
        system = System()
        login_user = system.getUser(session.get('username'))
        customers = system.customers()
        return render_template('users.html', login_user=login_user, customers=customers)
    return redirect('/')
예제 #11
0
def users():

    if 'username' in session:
        db.session.commit() ####### Make recent hit to the
        system = System()
        login_user = system.getUser(session.get('username'))
        customers = system.customers()
        return render_template('users.html', login_user=login_user, customers=customers)
    return redirect('/')
예제 #12
0
def Calls():

    if 'username' in session:

        db.session.commit()
        system = System()
        calls = system.calls()
        login_user = system.getUser(session.get('username'))
        return render_template('calls.html', login_user=login_user, calls=calls)
    return redirect(url_for("Index"))
예제 #13
0
def users():

    if session.get('username'):
        system = System()
        login_user = system.getUser(session.get('username'))
        customers = system.customers()
        return render_template('users.html',
                               login_user=login_user,
                               customers=customers)
    return redirect('/')
예제 #14
0
def Ipfilters():

    if session.get('username'):

        ip = request.environ.get('HTTP_X_FORWARDED_FOR') or request.environ.get('REMOTE_ADDR') 
        system = System()
        ipfilters = system.ipfilters()
        login_user = system.getUser(session.get('username'))
        return render_template('ipfilters.html', login_user=login_user, ip=ip, ipfilters=ipfilters)
    return redirect(url_for("Index"))
예제 #15
0
def Login():

    if not 'username' in session:

        #db.session.commit() ####### commit to the database to refresh it

        if request.method == 'POST':

            error = None
            email = request.form['email']
            account = request.form['account']
            if len(email) < 5:
                abort(400, 'The email address is too short')
            elif len(account) < 1:
                abort(400, 'No account number specified')
            response = User(email).login(account)
            if response == 1:
                session['username'] = email
                db.session.commit(
                )  ####### commit to the database to refresh it
                system = System()
                username = session.get('username')
                login_user = system.getUser(username)
                session.permanent = True

                return redirect('/home')
            elif response == 2:
                error = 'Database server is sleeping... Please try again to wake it up'
            elif response == 0:
                error = 'Invalid login credentials'
            else:
                abort(
                    400,
                    'Something unusual happened, please check Internet connectivity'
                )
            return render_template('login.html', error=error)
        return render_template('login.html')
    db.session.commit()  ####### commit to the database to refresh it
    system = System()
    username = session.get('username')
    login_user = system.getUser(username)
    return redirect('/home')
예제 #16
0
def user(user_id=None):

    if session.get('username'):
        system = System()
        login_user = system.getUser(session.get('username'))
        user = system.getUserById(user_id)
        if not user:
            return redirect('/customers')
        return render_template('user.html', login_user=login_user, user=user)

    return redirect('/') 
예제 #17
0
def Home():

    if session.get('username'):

        #ip = gethostbyname(gethostname()) 
        ip = request.environ.get('HTTP_X_FORWARDED_FOR') or request.environ.get('REMOTE_ADDR') 
        system = System()
        system.defaultAction()
        login_user = system.getUser(session.get('username'))
        return render_template('home.html', login_user=login_user, ip=ip)
    return redirect(url_for("Index"))
예제 #18
0
def user(user_id=None):

    if 'username' in session:
        system = System()
        login_user = system.getUser(session.get('username'))
        user = system.getUserById(user_id)
        if not user:
            return redirect('/customers')
        return render_template('user.html', login_user=login_user, user=user)

    return redirect('/')
예제 #19
0
def users():

    if 'username' in session:
        db.session.commit()  ####### Make recent hit to the
        system = System()
        login_user = system.getUser(session.get('username'))
        customers = system.customers()
        return render_template('users.html',
                               login_user=login_user,
                               customers=customers)
    return redirect('/')
예제 #20
0
def destination_new(user_id):

    if session.get('username'):

        system = System()
        dids = system.available_dids()
        owns = system.owns()
        login_user = system.getUser(session.get('username'))
        user = system.getUserById(user_id)
        error = None
        if not user:
            return redirect('/customers')

        if request.method == 'POST':

            did = request.form['did']
            own = request.form['own']
            record = request.form['record']
            auth_gw = request.form['auth_gw']
            auth_did = request.form['auth_did']
            gateway = request.form['gateway']
            channel = request.form['channel']
            number = request.form['number']
            day = request.form['day']
            month = request.form['month']
            year = request.form['year']
            string_date = year + '-' + month + '-' + day + ' 12:00:00'
            end_date = datetime.datetime.strptime(string_date,
                                                  "%Y-%m-%d %H:%M:%S")
            email = session.get('username')
            response = User(email).destination_new(user_id, did, number,
                                                   record, auth_did, auth_gw,
                                                   gateway, channel, own,
                                                   end_date)
            if response == 0:

                error = "Destination created for origin "
            if response == 1:
                error = " Destination number already exist with origin "
            return render_template('destination-new.html',
                                   login_user=login_user,
                                   user=user,
                                   error=error,
                                   dids=dids,
                                   owns=owns)
        return render_template('destination-new.html',
                               login_user=login_user,
                               user=user,
                               error=error,
                               dids=dids,
                               owns=owns)

    return redirect('/')
예제 #21
0
def Calls():

    if 'username' in session:

        db.session.commit()
        system = System()
        calls = system.calls()
        login_user = system.getUser(session.get('username'))
        return render_template('calls.html',
                               login_user=login_user,
                               calls=calls)
    return redirect(url_for("Index"))
예제 #22
0
def user_create():

    if 'username' in session:
        system = System()
        login_user = system.getUser(session.get('username'))
        error = None

        if request.method == 'POST':

            firstname = request.form['firstname']
            lastname = request.form['lastname']
            email_cust = request.form['email_cust'] or None
            origin = request.form['number']

            if len(firstname) < 1:
                abort(400, 'Enter firstname')
            elif len(lastname) < 1:
                abort(400, 'Enter lastname')
            elif len(origin) < 1:
                abort(400, 'Enter phone number')

            email = session.get('username')
            response = User(email).createCustomer(firstname, lastname,
                                                  email_cust, origin)
            if response == 0:

                error = firstname + ' ' + lastname + ' is added Successfully'
                flash("Customer added Successfully")
                if email_cust is not None:

                    msg = Message(
                        "Registration successfull, your registration details ",
                        sender=app.config["DEFAULT_MAIL_SENDER"],
                        recipients=[email_cust])
                    msg.html = render_template("reg-email.html",
                                               firstname=firstname,
                                               lastname=lastname,
                                               email=email_cust)
                    thr = Thread(target=send_async_email_test, args=[app, msg])
                    thr.start()
                return render_template('user-create.html',
                                       login_user=login_user,
                                       error=error)

            if response == 1:

                error = origin + ' already exist, so no record created'
                return render_template('user-create.html',
                                       login_user=login_user,
                                       error=error)

        return render_template('user-create.html', login_user=login_user)
    return redirect('/')
예제 #23
0
def Home():

    if session.get('username'):

        #ip = gethostbyname(gethostname())
        ip = request.environ.get(
            'HTTP_X_FORWARDED_FOR') or request.environ.get('REMOTE_ADDR')
        system = System()
        system.defaultAction()
        login_user = system.getUser(session.get('username'))
        return render_template('home.html', login_user=login_user, ip=ip)
    return redirect(url_for("Index"))
예제 #24
0
def destination_new(user_id):

    if 'username' in session:
        db.session.commit() ####### Make a recent call to the database
        system = System()
        dids = system.available_dids()
        owns = system.owns()
        login_user = system.getUser(session.get('username'))
        user = system.getUserById(user_id)
        error = None
        if not user:
            return redirect('/customers')

        if request.method == 'POST':
            
            did = request.form['did']
            own = request.form['own']
            gateway = request.form['gateway']
            channel = request.form['channel']
            number = request.form['number']
            day = request.form['day']
            month = request.form['month']
            year = request.form['year']
            string_date = year + '-' + month + '-' + day + ' 12:00:00'
            end_date = datetime.datetime.strptime(string_date, "%Y-%m-%d %H:%M:%S")
            email = session.get('username')
            if not request.form.get('auth_did'):
                auth_did = "0"
            else:
                auth_did = request.form['auth_did']
            if not request.form.get('auth_gw'):
                auth_gw = "0"
            else:
                auth_gw = request.form['auth_gw']
            if not request.form.get('record'):
                record = "0"
            else:
                record = request.form['record']

            response = User(email).destination_new(user_id,did,number,record,auth_did,auth_gw,gateway,channel,own,end_date)
            if response == 0:
                
                error = "Destination " + str(number) + " created successfully"
                
            if response == 1:
                error = " Destination number already exist with origin " 
            db.session.commit() ####### Make a recent call to the database
            system = System()
            dids = system.available_dids()
            return render_template('destination-new.html', login_user=login_user, user=user, error=error, dids=dids, owns=owns)
        return render_template('destination-new.html', login_user=login_user, user=user, error=error, dids=dids, owns=owns)

    return redirect('/')
예제 #25
0
def Login():    

    if not 'username' in session:

        #db.session.commit() ####### commit to the database to refresh it
        
        if request.method == 'POST':

            error = None
            email = request.form['email']
            account = request.form['account']
            if len(email) < 5:
                abort(400,'The email address is too short')
            elif len(account) < 1:
                abort(400,'No account number specified')
            response = User(email).login(account)
            if response == 1:
                session['username'] = email
                db.session.commit() ####### commit to the database to refresh it 
                system = System()
                username = session.get('username')
                login_user = system.getUser(username)
                session.permanent = True
                
                return redirect('/home')
            elif response == 2:
                error = 'Database server is sleeping... Please try again to wake it up'
            elif response == 0:
                error = 'Invalid login credentials'
            else:
                abort(400,'Something unusual happened, please check Internet connectivity')
            return render_template('login.html', error=error)
        return render_template('login.html')
    db.session.commit() ####### commit to the database to refresh it
    system = System()
    username = session.get('username')
    login_user = system.getUser(username)
    return redirect('/home')
예제 #26
0
def Ipfilters():

    if 'username' in session:

        ip = request.environ.get(
            'HTTP_X_FORWARDED_FOR') or request.environ.get('REMOTE_ADDR')
        system = System()
        ipfilters = system.ipfilters()
        login_user = system.getUser(session.get('username'))
        return render_template('ipfilters.html',
                               login_user=login_user,
                               ip=ip,
                               ipfilters=ipfilters)
    return redirect(url_for("Index"))
예제 #27
0
def countries():
    if 'username' in session:

        system = System()
        countries = system.countries()
        login_user = system.getUser(session.get('username'))
        error = None
        if request.method == 'POST':

            country = request.form['country']
            region = request.form['region']

            if len(country) < 1:
                abort(400, 'No country entered')
            elif len(region) < 1:
                abort(400, 'No region selected')

            email = session.get('username')
            response = User(email).createCountry(region, country)
            if response == 0:
                error = country + ' added to region ' + region + ', refresh browser to see update'
                flash("Country added Successfully")
                countries = system.countries()
                return render_template('country.html',
                                       login_user=login_user,
                                       error=error,
                                       countries=countries)
            if response == 506:

                abort(
                    400,
                    'No data insertion was made, please check Internet connectivity'
                )
            if response == 1:
                error = country + ' already exist'
                return render_template('country.html',
                                       login_user=login_user,
                                       error=error,
                                       countries=countries)
        return render_template('country.html',
                               login_user=login_user,
                               error=error,
                               countries=countries)

    return redirect(url_for("Index"))
예제 #28
0
def user_create():

    
    if session.get('username'):
        system = System()
        login_user = system.getUser(session.get('username'))
        error = None

        if request.method == 'POST':

            firstname = request.form['firstname']
            lastname = request.form['lastname']
            email_cust = request.form['email_cust'] or None
            origin = request.form['number']

            if len(firstname) < 1:
                abort(400, 'Enter firstname')
            elif len(lastname) < 1:
                abort(400, 'Enter lastname')
            elif len(origin) < 1:
                abort(400, 'Enter phone number')

            email = session.get('username')
            response = User(email).createCustomer(firstname,lastname,email_cust,origin)
            if response == 0:

                error = firstname + ' ' + lastname + ' is added Successfully'
                flash("Customer added Successfully")
                if email_cust is not None:

                    msg = Message("Registration successfull, your registration details ",sender=app.config["DEFAULT_MAIL_SENDER"],recipients=[email_cust])
                    msg.html = render_template("reg-email.html",firstname=firstname,lastname=lastname,email=email_cust)
                    thr = Thread(target=send_async_email_test, args=[app, msg])
                    thr.start()
                return render_template('user-create.html', login_user=login_user, error=error)

            if response == 1:

                error = origin + ' already exist, so no record created'
                return render_template('user-create.html', login_user=login_user, error=error)

        return render_template('user-create.html', login_user=login_user)
    return redirect('/')
예제 #29
0
def Did():

    if session.get('username'):

        system = System()
        login_user = system.getUser(session.get('username'))
        pins = system.pins()
        countries = system.countries()
        dids = system.dids()
        error = None

        if request.method == 'POST':

            file = request.files['did_file']

            if not file:

                phone = request.form['phone']
                cost = request.form['cost']
                country = request.form['country']
                capacity = request.form['capacity']
                provider = request.form['provider']
                mode = request.form['mode']
                pin = request.form['pin']

                if len(phone) < 1:

                    abort(400, 'The phone number is invalid')
                elif len(cost) < 1:
                    abort(400, 'Invalid cost specified')
                elif len(country) < 1:
                    abort(400, 'Invalid country code')
                elif len(capacity) < 1:
                    abort(400, 'Please select capacity')
                elif len(provider) < 1:
                    abort(400, 'Please select provider')
                elif len(mode) < 1:
                    abort(400, 'Please select mode')
                elif len(pin) < 1:
                    abort(400, 'Please select pin')

                email = session.get('username')
                response = User(email).createDid(phone, provider, cost,
                                                 country, capacity, mode, pin)

                if response == 0:

                    flash('DID Successfully created')
                    error = 'DID Successfully created with pin ' + pin
                    return render_template('did.html',
                                           login_user=login_user,
                                           error=error,
                                           dids=dids,
                                           pins=pins,
                                           countries=countries)

                elif response == 1:

                    abort(400, 'DID %s already exist' % (phone))
                else:
                    abort(400, 'DID is not created')

            if System().allowed_file(file.filename):

                filename = secure_filename(file.filename)

                try:

                    file.save(
                        os.path.join(app.config['UPLOAD_FOLDER'], filename))
                    fileUrl = os.path.abspath(app.config['UPLOAD_FOLDER'] +
                                              filename)
                    #fileUrl = path(app.config['UPLOAD_FOLDER']+filename).abspath()

                    error = 'File uploaded : Path -> ' + fileUrl
                    data_list_dids = System().readCSV(fileUrl)
                    insert_dids = System().insertDids(data_list_dids)

                    error = str(
                        insert_dids) + ' DIDs has been uploaded and saved'

                except:

                    error = 'File not uploaded Successfully'

            else:

                error = 'File format is not allowed'

            return render_template('did.html',
                                   login_user=login_user,
                                   error=error,
                                   did_file=file,
                                   dids=dids,
                                   pins=pins,
                                   countries=countries)

        return render_template('did.html',
                               login_user=login_user,
                               error=error,
                               pins=pins,
                               dids=dids,
                               countries=countries)

    return redirect(url_for("Index"))
예제 #30
0
def Own():


    if session.get('username'):

        system = System()
        login_user = system.getUser(session.get('username'))
        dids = system.dids()
        owns = system.owns()
        error = None

        if request.method == 'POST':

            file = request.files['own_file']

            if not file:

                sim = request.form['sim']
                did = request.form['did']

                if len(sim) < 1:
                    abort(400, 'Please enter a SIM number')
                elif len(did) < 1:
                    abort(400,'Please select a did')

                email = session.get('username')
                response = User(email).createSim(sim,did)
                if response == 0:
                    flash('OWN Successfully created')
                    error = 'OWN Successfully created with did '+did
                    return render_template('own.html', login_user=login_user, error=error,owns=owns)

                elif response == 1:
                    abort(400, 'OWN %s already exist with SIM '%(sim))

                elif response == 506:
                    abort(400, 'Error:'+response+', Data insertion error')

            if System().allowed_file(file.filename):


                filename = secure_filename(file.filename)

                try:

                    file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
                    fileUrl = os.path.abspath(app.config['UPLOAD_FOLDER']+filename)
                    #fileUrl = path(app.config['UPLOAD_FOLDER']+filename).abspath()

                    error = 'File uploaded : Path -> ' + fileUrl
                    data_list_owns = system.readCSV(fileUrl)
                    insert_owns = system.insertOwns(data_list_owns)

                    error =  str(insert_owns) + ' OWN has been uploaded and saved'
                    #error =  data_list_owns

                except:


                    error = 'File not uploaded Successfully'
        
            else:

                error = 'File format is not allowed'

            return render_template('own.html', login_user=login_user, error=error, own_file=file, owns=owns)


        return render_template('own.html', login_user=login_user, error=error, dids=dids, owns=owns)


    return redirect(url_for("Index"))
예제 #31
0
def Did():

    if 'username' in session:

        db.session.commit()  ###### commit to the database
        system = System()
        login_user = system.getUser(session.get('username'))
        pins = system.available_pins()
        countries = system.countries()
        dids = system.dids()
        count_available_dids = system.count_available_dids()

        error = None

        if request.method == 'POST':

            file = request.files['did_file']

            if not file:

                phone = request.form['phone']
                cost = request.form['cost']
                country = request.form['country']
                capacity = request.form['capacity']
                provider = request.form['provider']
                mode = request.form['mode']
                pin = request.form['pin']

                if len(phone) < 1:

                    abort(400, 'The phone number is invalid')
                elif len(cost) < 1:
                    abort(400, 'Invalid cost specified')
                elif len(country) < 1:
                    abort(400, 'Invalid country code')
                elif len(capacity) < 1:
                    abort(400, 'Please select capacity')
                elif len(provider) < 1:
                    abort(400, 'Please select provider')
                elif len(mode) < 1:
                    abort(400, 'Please select mode')
                elif mode == 'PIN-DIALING' and len(pin) < 1:
                    abort(400, 'Please select pin')
                elif mode == 'DIRECT-DIALING':
                    pin = None

                email = session.get('username')
                response = User(email).createDid(phone, provider, cost,
                                                 country, capacity, mode, pin)

                if response == 0:

                    flash('DID Successfully created')
                    dids = system.dids()
                    pins = system.available_pins()
                    error = 'DID Successfully created  ' + phone
                    #return render_template('did.html', login_user=login_user, error=error, dids=dids, pins=pins, countries=countries)
                    return redirect('/did')
                elif response == 1:

                    abort(400, 'DID %s already exist' % (phone))

                elif response == 506:

                    abort(
                        400,
                        'A technical error occured, this has to do with the application program the mode for the pin in the (PIN) table'
                    )

                else:
                    abort(400, 'DID is not created')

            if System().allowed_file(file.filename):

                filename = secure_filename(file.filename)

                try:

                    file.save(
                        os.path.join(app.config['UPLOAD_FOLDER'], filename))
                    fileUrl = os.path.abspath(app.config['UPLOAD_FOLDER'] +
                                              filename)
                    #fileUrl = path(app.config['UPLOAD_FOLDER']+filename).abspath()

                    error = 'File uploaded : Path -> ' + fileUrl
                    data_list_dids = System().readCSV(fileUrl)
                    insert_dids = System().insertDids(data_list_dids)

                    error = str(
                        insert_dids['insertnum']
                    ) + ' DIDs has been uploaded in total of ' + str(
                        insert_dids['total'])

                except:

                    error = 'File not uploaded Successfully'

            else:

                error = 'File format is not allowed'
            ###### After the browsers refresh when uploading from a file
            dids = system.dids()
            pins = system.available_pins()
            count_available_dids = system.count_available_dids()
            return render_template('did.html',
                                   login_user=login_user,
                                   countdids=count_available_dids,
                                   error=error,
                                   did_file=file,
                                   dids=dids,
                                   pins=pins,
                                   countries=countries)
        ###### When the browser is using other method apart from GET
        db.session.rollback()
        dids = system.dids()
        pins = system.available_pins()
        count_available_dids = system.count_available_dids()
        return render_template('did.html',
                               login_user=login_user,
                               countdids=count_available_dids,
                               error=error,
                               pins=pins,
                               dids=dids,
                               countries=countries)

    return redirect(url_for("Index"))
예제 #32
0
def Did():


    if 'username' in session:


        db.session.commit() ###### commit to the database 
        system = System()
        login_user = system.getUser(session.get('username'))
        pins = system.available_pins()
        countries = system.countries()
        dids = system.dids()
        count_available_dids = system.count_available_dids()
        
        error = None

        if request.method == 'POST':

            file = request.files['did_file']

            if not file:

                phone = request.form['phone']
                cost = request.form['cost']
                country = request.form['country']
                capacity = request.form['capacity']
                provider = request.form['provider']
                mode = request.form['mode']
                pin = request.form['pin']
        
                if len(phone) < 1:

                    abort(400,'The phone number is invalid')
                elif len(cost) < 1:
                   abort(400,'Invalid cost specified')
                elif len(country) < 1:
                    abort(400,'Invalid country code')
                elif len(capacity) < 1:
                    abort(400,'Please select capacity')
                elif len(provider) < 1:
                    abort(400,'Please select provider')
                elif len(mode) < 1:
                    abort(400,'Please select mode')
                elif mode == 'PIN-DIALING' and len(pin) < 1:
                    abort(400,'Please select pin')
                elif mode == 'DIRECT-DIALING':
                    pin = None

                email = session.get('username')
                response = User(email).createDid(phone,provider,cost,country,capacity,mode,pin)
                
                if response == 0:


                    flash('DID Successfully created')
                    dids = system.dids()
                    pins = system.available_pins()
                    error = 'DID Successfully created  '+phone
                    #return render_template('did.html', login_user=login_user, error=error, dids=dids, pins=pins, countries=countries)
                    return redirect('/did')
                elif response == 1:

                    abort(400,'DID %s already exist'%(phone))

                elif response == 506:

                    abort(400,'A technical error occured, this has to do with the application program the mode for the pin in the (PIN) table')

                else:
                    abort(400,'DID is not created')
        
            if System().allowed_file(file.filename):


                filename = secure_filename(file.filename)

                try:

                    file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
                    fileUrl = os.path.abspath(app.config['UPLOAD_FOLDER']+filename)
                    #fileUrl = path(app.config['UPLOAD_FOLDER']+filename).abspath()

                    error = 'File uploaded : Path -> ' + fileUrl
                    data_list_dids = System().readCSV(fileUrl)
                    insert_dids = System().insertDids(data_list_dids)

                    error =  str(insert_dids['insertnum']) + ' DIDs has been uploaded in total of '+ str(insert_dids['total'])

                except:


                    error = 'File not uploaded Successfully' 
        
            else:

                error = 'File format is not allowed'
            ###### After the browsers refresh when uploading from a file
            dids = system.dids()
            pins = system.available_pins()
            count_available_dids = system.count_available_dids()
            return render_template('did.html', login_user=login_user, countdids=count_available_dids, error=error, did_file=file, dids=dids,pins=pins,countries=countries)
        ###### When the browser is using other method apart from GET
        db.session.rollback()
        dids = system.dids()
        pins = system.available_pins()
        count_available_dids = system.count_available_dids()
        return render_template('did.html', login_user=login_user, countdids=count_available_dids, error=error, pins=pins, dids=dids,countries=countries)

    return redirect(url_for("Index"))
예제 #33
0
def Did():


    if session.get('username'):



        system = System()
        login_user = system.getUser(session.get('username'))
        pins = system.pins()
        countries = system.countries()
        dids = system.dids()
        error = None

        if request.method == 'POST':

            file = request.files['did_file']

            if not file:

                phone = request.form['phone']
                cost = request.form['cost']
                country = request.form['country']
                capacity = request.form['capacity']
                provider = request.form['provider']
                mode = request.form['mode']
                pin = request.form['pin']
        
                if len(phone) < 1:

                    abort(400, 'The phone number is invalid')
                elif len(cost) < 1:
                    abort(400,'Invalid cost specified')
                elif len(country) < 1:
                    abort(400, 'Invalid country code')
                elif len(capacity) < 1:
                    abort(400, 'Please select capacity')
                elif len(provider) < 1:
                    abort(400, 'Please select provider')
                elif len(mode) < 1:
                    abort(400, 'Please select mode')
                elif len(pin) < 1:
                    abort(400, 'Please select pin')

                email = session.get('username')
                response = User(email).createDid(phone,provider,cost,country,capacity,mode,pin)

                if response == 0:


                    flash('DID Successfully created')
                    error = 'DID Successfully created with pin '+pin
                    return render_template('did.html', login_user=login_user, error=error, dids=dids, pins=pins, countries=countries)

                elif response == 1:


                    abort(400, 'DID %s already exist'%(phone))
                else:
                    abort(400, 'DID is not created')
        
            if System().allowed_file(file.filename):


                filename = secure_filename(file.filename)

                try:

                    file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
                    fileUrl = os.path.abspath(app.config['UPLOAD_FOLDER']+filename)
                    #fileUrl = path(app.config['UPLOAD_FOLDER']+filename).abspath()

                    error = 'File uploaded : Path -> ' + fileUrl
                    data_list_dids = System().readCSV(fileUrl)
                    insert_dids = System().insertDids(data_list_dids)

                    error =  str(insert_dids) + ' DIDs has been uploaded and saved'

                except:


                    error = 'File not uploaded Successfully'
        
            else:

                error = 'File format is not allowed'

            return render_template('did.html', login_user=login_user, error=error, did_file=file, dids=dids,pins=pins,countries=countries)

        return render_template('did.html', login_user=login_user, error=error, pins=pins, dids=dids,countries=countries)

    return redirect(url_for("Index"))
예제 #34
0
def Own():

    if 'username' in session:

        db.session.commit()  ###### commit to the database
        system = System()
        login_user = system.getUser(session.get('username'))
        dids = system.dids()
        owns = system.owns()
        error = None

        if request.method == 'POST':

            file = request.files['own_file']

            if not file:

                sim = request.form['sim']
                did = request.form['did']

                if len(sim) < 1:
                    abort(400, 'Please enter a SIM number')
                elif len(did) < 1:
                    abort(400, 'Please select a did')

                email = session.get('username')
                response = User(email).createSim(sim, did)
                if response == 0:
                    flash('OWN Successfully created')
                    error = 'OWN Successfully created with did ' + did
                    owns = system.owns()
                    return redirect('/own')

                elif response == 1:
                    abort(400, 'OWN %s already exist with SIM ' % (sim))

                elif response == 506:
                    abort(400, 'Error:' + response + ', Data insertion error')

            if System().allowed_file(file.filename):

                filename = secure_filename(file.filename)

                try:

                    file.save(
                        os.path.join(app.config['UPLOAD_FOLDER'], filename))
                    fileUrl = os.path.abspath(app.config['UPLOAD_FOLDER'] +
                                              filename)
                    #fileUrl = path(app.config['UPLOAD_FOLDER']+filename).abspath()

                    error = 'File uploaded : Path -> ' + fileUrl
                    data_list_owns = system.readCSV(fileUrl)
                    insert_owns = system.insertOwns(data_list_owns)

                    error = error = str(
                        insert_owns['insertnum']
                    ) + ' Owns has been uploaded in total of ' + str(
                        insert_owns['total'])
                    #error =  data_list_owns

                except:

                    error = 'File not uploaded Successfully'

            else:

                error = 'File format is not allowed'
            owns = system.owns()
            return render_template('own.html',
                                   login_user=login_user,
                                   error=error,
                                   own_file=file,
                                   owns=owns)

        db.session.commit()  ###### commit to the database
        dids = system.dids()
        owns = system.owns()
        return render_template('own.html',
                               login_user=login_user,
                               error=error,
                               dids=dids,
                               owns=owns)

    return redirect(url_for("Index"))