Exemple #1
0
    def __init__(self, dbPath, dbName):
        self.database = dbPath + dbName
        self.dataPath = dbPath
        self.visits = Visits()
        self.guests = Guests()
        self.reports = Reports(self)
        self.teams = Teams()
        self.accounts = Accounts()
        self.devices = Devices()
        self.unlocks = Unlocks()
        # needs path since it will open read only
        self.customReports = CustomReports(self.database)
        self.certifications = Certifications()
        self.members = Members()
        self.logEvents = LogEvents()

        if not os.path.exists(self.database):
            if not os.path.exists(dbPath):
                os.mkdir(dbPath)
            with self.dbConnect() as c:
                self.migrate(c, 0)
        else:
            with self.dbConnect() as c:
                data = c.execute('PRAGMA schema_version').fetchone()
                if data[0] != SCHEMA_VERSION:
                    self.migrate(c, data[0])
Exemple #2
0
def index():

    try:
        data = json.loads(request.data)
        check_fields(data, ["email", "password"], [])
        account = check_hash_no_exception(request.cookies)

        if account is not None:
            if account["email"] == data["email"]:
                return json.dumps({
                    "success": 0,
                    "message": "Already authenticated user"
                })
            else:
                # if the account is authenticated as another user,
                # log him out and then log in as the other user
                Accounts.logout(account['_id'], request.cookies['hash'])

        success, message = Accounts.login(data)
        if not success:
            return json.dumps({"success": 0, "message": message})
        else:
            body = json.dumps({
                "success": 1,
                "message": "Successfully logged in"
            })
            #print "almost done"
            resp = Response(body, status=200)
            resp.set_cookie('hash', value=message)
            return resp

    except FieldsException as e:
        return json.dumps({"success": 0, "message": str(e)})
    except Exception as e:
        return json.dumps({"success": 0, "message": str(e)})
    def get(self):
        Guser = users.get_current_user()
        
        if Guser:
            URL = self.request.url

            vstrURLlist = URL.split("/")
            vstrListID = vstrURLlist[len(vstrURLlist) - 1]

            findRequest = Accounts.query(Accounts.strUserID == Guser.user_id())
            thisAccountsList = findRequest.fetch()

            if len(thisAccountsList) > 0:
                thisAccounts = thisAccountsList[0]
            else:
                thisAccounts = Accounts()

            findRequest = MailingList.query(MailingList.strListID == vstrListID,MailingList.strOrganizationID == thisAccounts.strOrganizationID)
            thisMailingList = findRequest.fetch()

            if len(thisMailingList) > 0:
                thisNewsLetter = thisMailingList[0]
            else:
                thisNewsLetter = MailingList()

            template = template_env.get_template('templates/newsletter/thisNewsletter.html')
            context = {'thisNewsLetter':thisNewsLetter}
            self.response.write(template.render(context))
 def test_save_multiple_accounts(self):
     '''
     a test that checks whether both values appended to the array are actually present\ and returns the acount itself
     '''
     self.new_account.save_account()
     test_account = Accounts('abcd', 'efgh', 'ijkl', 'mnop')
     test_account.save_account()
     self.assertEqual(len(Accounts.user_accounts), 2)
 def test_del_account(self):
     '''
     test that check the delete function
     '''
     self.new_account.save_account()
     test_account = Accounts('abcd', 'efgh', 'ijkl', 'mnop')
     test_account.save_account()
     self.new_account.delete_account()
     self.assertEqual(len(Accounts.user_accounts), 1)
 def test_find_account_by_username(self):
     '''
     test to check whether the function used to find accounts really works
     '''
     self.new_account.save_account()
     test_account = Accounts('abcd', 'efgh', 'ijkl', 'mnop')
     test_account.save_account()
     found_account = Accounts.find_by_user_name('ijkl')
     self.assertEqual(found_account.user_name, test_account.user_name)
 def test_account_exists(self):
     '''
     unlike the previous test this test returns a true/false soort of answer depending on whether the account exists or not
     '''
     self.new_account.save_account()
     test_account = Accounts('abcd', 'efgh', 'ijkl', 'mnop')
     test_account.save_account()
     account_exists = Accounts.account_exists('ijkl')
     self.assertTrue(account_exists)
Exemple #8
0
def monitorNewAccounts():
    #time when emails will be sent
    start = datetime.time(16, 59)
    end = datetime.time(17, 00)
    while (datetime.datetime.now().time() < start
           or datetime.datetime.now().time() > end):

        #takes input through keyboard on 20 second timer (so it doesnt get tied up when reports get emailed)
        stringer = timed_Input()

        #if there was an email
        if (stringer != None):
            #parses the input message
            message = stringer.split(",")

            #if the message is saying to create a new account with signal "0000"
            if (message[0] == "0000"):
                if (len(message) >= 10):
                    # creates new user with an email
                    new_account = Accounts(float(message[1]), float(
                        message[2]), float(message[3]), float(message[4]),
                                           float(message[5]),
                                           float(message[6]),
                                           float(message[7]),
                                           float(message[8]), message[9])
            # email not included
                else:
                    new_account = Accounts(float(message[1]), float(
                        message[2]), float(message[3]), float(message[4]),
                                           float(message[5]),
                                           float(message[6]),
                                           float(message[7]),
                                           float(message[8]))

                #creates new user id, if it already exists increments until finds number that doesnt exist
                new_id = random.randrange(1, 999)
                while (new_id in created_accounts):
                    new_id = new_id + 1

                #adds new account with new id to the existing accounts
                created_accounts[str(new_id)] = new_account

                #generate report
                reply = generate_report(str(new_id), created_accounts, True)

            #else the user already exists OR you need to create new account
            else:
                reply = generate_report(str(message[0]), created_accounts,
                                        False)

            #returns the report generated
            print(reply)
            print('\nEnter something.')

    #in time range to send reports so calls send reports and then loops back in
    sendReports()
Exemple #9
0
def index(account_id=-1):
    #TODO check if the user has permissions to do these operations
    #these are used for testing right now
    if request.method == "GET":
        try:
            success, message = Accounts.get(account_id)
            if not success:
                return json.dumps({"success": 0, "message": message})
            else:
                return json.dumps({"success": 1, "message": message})

        except FieldsException as e:
            return json.dumps({"success": 0, "message": str(e)})
        except Exception as e:
            logging.error(str(e))
            return json.dumps({
                "success": 0,
                "message": "Something went wrong"
            })

    if request.method == "PUT":
        try:
            data = json.loads(request.data)
            check_fields(data, [],
                         ["name", "email", "password", "permissions", "orgs"])
            success, message = Accounts.update(account_id, data)
            if not success:
                return json.dumps({"success": 0, "message": message})
            else:
                return json.dumps({"success": 1, "message": message})

        except FieldsException as e:
            return json.dumps({"success": 0, "message": str(e)})
        except Exception as e:
            logging.error(str(e))
            return json.dumps({
                "success": 0,
                "message": "Something went wrong"
            })

    if request.method == "DELETE":
        try:
            success, message = Accounts.delete(account_id)
            if not success:
                return json.dumps({"success": 0, "message": message})
            else:
                return json.dumps({"success": 1, "message": message})

        except FieldsException as e:
            return json.dumps({"success": 0, "message": str(e)})
        except Exception as e:
            logging.error(str(e))
            return json.dumps({
                "success": 0,
                "message": "Something went wrong"
            })
def main_menu(session, base_url):
    """
    Provides the different options for the sample application: Market Quotes, Account List

    :param session: authenticated session
    """

    market = Market(session, base_url)
    accounts = Accounts(session, base_url)
    order = Order(session, {}, base_url)

    # ret = market.quoteCommon("vsat")
    # print ("MARKET FOR VST", ret)

    accountsObj = accounts.printPorfolio(PERCENT)
    accountsList = accountsObj['acct']
    accountsPort = accountsObj['port']
    ordersAcct = {}
    for account in accountsList:
        ordersAcct[account['accountId']] = order.viewOpenOrder(account, False)
    checkAccountOrder(accountsPort, ordersAcct)
    menu_items = {"1": "Market Quotes",
                  "2": "Account List",
                  "3": "Place File order", 
                  "4": "Cancel all open orders",
                  "5": "Cancel ALL orders and redo on current price",
                  "6": "redo diff orders",
                  "7": "Exit"}

    while True:
        print("")
        options = menu_items.keys()
        for entry in options:
            print(entry + ")\t" + menu_items[entry])
        selection = input("Please select an option: ")
        if selection == "1":
            market.quotes()
        elif selection == "2":
            accounts.account_list()
        elif selection == "3":
            order.readCSV(False)
        elif selection == "4":
            for account in accountsList:
                order.viewOpenOrder(account, True)
        elif selection == "5":
            for account in accountsList:
                order.viewOpenOrder(account, True)
            order.readCSV(True)
        elif selection == "6":
            order.dodiff()
        elif selection == "7":
            break
        else:
            print("Unknown Option Selected!")
Exemple #11
0
    def post(self):

        vstrChoice = self.request.get('vstrChoice')

        if vstrChoice == "0":
            #'&vstrUserID=' + struid + '&vstrEmail=' + email + '&vstrAccessToken=' + accessToken
            vstrUserID = self.request.get("vstrUserID")
            vstrEmail = self.request.get("vstrEmail")
            vstrAccessToken = self.request.get("vstrAccessToken")


            vstrListName = self.request.get('vstrListName')
            vstrListDescription = self.request.get('vstrListDescription')
            vstrStartSendingDate = self.request.get('vstrStartSendingDate')
            DateList = vstrStartSendingDate.split("-")
            strYear = int(DateList[0])
            strMonth = int(DateList[1])
            strDay = int(DateList[2])

            vstrDate = datetime.date(year=strYear,month=strMonth,day=strDay)


            vstrStartSendingTime = self.request.get('vstrStartSendingTime')
            TimeList = vstrStartSendingTime.split(":")
            strHour = int(TimeList[0])
            strMinute = int(TimeList[1])
            vstrTime = datetime.time(hour=strHour,minute=strMinute,second=0)



            findRequest = Accounts.query(Accounts.strUserID == vstrUserID)
            thisAccountsList = findRequest.fetch()

            if len(thisAccountsList) > 0:
                thisAccounts = thisAccountsList[0]
            else:
                thisAccounts = Accounts()

            findRequest = MailingList.query(MailingList.strOrganizationID == thisAccounts.strOrganizationID,MailingList.strListName == vstrListName,MailingList.strListDescription == vstrListDescription)
            thisMailingList = findRequest.fetch()

            if len(thisMailingList) > 0:
                thisMailing = thisMailingList[0]
            else:
                thisMailing = MailingList()
                thisMailing.writeListID(strinput=thisMailing.CreateListID())

            thisMailing.writeOrganizationID(strinput=thisAccounts.strOrganizationID)
            thisMailing.writeListName(strinput=vstrListName)
            thisMailing.writeListDescription(strinput=vstrListDescription)
            thisMailing.writeStartSendingDate(strinput=vstrDate)
            thisMailing.writeStartSendingTime(strinput=vstrTime)
            thisMailing.put()
            self.response.write("Mailing List successfully update")
Exemple #12
0
    def post(self):

        from mysms import SMSAccount
        from accounts import Accounts, Organization

        #'&vstrUserID=' + struid + '&vstrEmail=' + email + '&vstrAccessToken=' + accessToken;
        vstrUserID = self.request.get('vstrUserID')
        vstrEmail = self.request.get('vstrEmail')
        vstrAccessToken = self.request.get('vstrAccessToken')

        findRequest = Accounts.query(Accounts.strUserID == vstrUserID)
        thisAccountList = findRequest.fetch()

        if len(thisAccountList) > 0:
            thisAccount = thisAccountList[0]
        else:
            findRequest = Accounts.query(Accounts.strEmail == vstrEmail)
            thisAccountList = findRequest.fetch()

            if len(thisAccountList) > 0:
                thisAccount = thisAccountList[0]
            else:
                thisAccount = Accounts()

        findRequest = SMSAccount.query(
            SMSAccount.strOrganizationID == thisAccount.strOrganizationID)
        thisSMSAccountList = findRequest.fetch()

        if len(thisSMSAccountList) > 0:
            thisSMSAccount = thisSMSAccountList[0]
        else:
            thisSMSAccount = SMSAccount()

        findRequest = Organization.query(
            Organization.strOrganizationID == thisAccount.strOrganizationID)
        thisOrgList = findRequest.fetch()

        if len(thisOrgList) > 0:
            thisOrg = thisOrgList[0]
        else:
            thisOrg = Organization()

        template = template_env.get_template(
            'templates/account/accountinfo.html')
        context = {
            'thisSMSAccount': thisSMSAccount,
            'thisAccount': thisAccount,
            'thisOrg': thisOrg
        }
        self.response.write(template.render(context))
    def post(self):
        Guser = users.get_current_user()
        if Guser:
            vstrPaymentMethod = self.request.get('vstrPaymentMethod').value

            if vstrPaymentMethod == "Cash":
                findRequest = Accounts.query(
                    Accounts.strReference == Guser.user_id())
                thisAccountsList = findRequest.fetch()

                if len(thisAccountsList) > 0:
                    thisAccount = thisAccountsList[0]
                else:
                    thisAccount = Accounts()
Exemple #14
0
    def post(self):

        from mysms import SMSAccount
        from accounts import Accounts, Organization
        vstrUserID = self.request.get("vstrUserID")
        vstrUserEmail = self.request.get('vstrUserEmail')
        vstraccessToken = self.request.get('vstraccessToken')

        findRequest = Accounts.query(Accounts.strUserID == vstrUserID)
        thisAccountList = findRequest.fetch()

        if len(thisAccountList) > 0:
            thisAccount = thisAccountList[0]
        else:
            findRequest = Accounts.query(Accounts.strEmail == vstrUserEmail,
                                         Accounts.strVerified == True)
            thisAccountList = findRequest.fetch()

            if len(thisAccountList) > 0:
                thisAccount = thisAccountList[0]
            else:
                thisAccount = Accounts()

        findRequest = SMSAccount.query(
            SMSAccount.strOrganizationID == thisAccount.strOrganizationID)
        thisSMSAccountList = findRequest.fetch()

        if len(thisSMSAccountList) > 0:
            thisSMSAccount = thisSMSAccountList[0]
        else:
            thisSMSAccount = SMSAccount()

        findRequest = Organization.query(
            Organization.strOrganizationID == thisAccount.strOrganizationID)
        thisOrgList = findRequest.fetch()

        if len(thisOrgList) > 0:
            thisOrg = thisOrgList[0]
        else:
            thisOrg = Organization()

        template = template_env.get_template('templates/sms/sub/admin.html')
        context = {
            'thisSMSAccount': thisSMSAccount,
            'thisAccount': thisAccount,
            'thisOrg': thisOrg,
            'vstrUserID': vstrUserID
        }
        self.response.write(template.render(context))
Exemple #15
0
    def get(self):
        Guser = users.get_current_user()
        if Guser:
            findRequest = Accounts.query(Accounts.strUserID == Guser.user_id())
            thisAccountsList = findRequest.fetch()

            if len(thisAccountsList) > 0:
                thisAccounts = thisAccountsList[0]
            else:
                thisAccounts = Accounts()

            findRequest = MailingList.query(MailingList.strOrganizationID == thisAccounts.strOrganizationID)
            thisMailingList = findRequest.fetch()

            template = template_env.get_template('templates/newsletter/newsletter.html')
            context = {'thisMailingList':thisMailingList}
            self.response.write(template.render(context))
def check_hash_no_exception(cookies):
    if "hash" not in cookies:
        logging.error("No cookie hash supplied, please login")
        return None
    account = Accounts.account_from_hash(cookies['hash'])
    if account is None:
        logging.error("Invalid hash")
        return None
    return account
Exemple #17
0
def processAccounts():
    accountsList = []
    accountsFile = open('static/file/acc', 'r')
    for alist in accountsFile:
        list = alist.split(',')
        s = Accounts(list[0], list[1], int(list[2]))

        accountsList.append(s)

    return accountsList
Exemple #18
0
def VerifyAndReturnAccount(strUserID, strAccessToken):
    """
        Myoptions = {"type": "service_account",
                         "project_id": "sa-sms-b",
                         "private_key_id": "b5a2df76c2222b83893b111c41e49bdf3fb2298a",
                         "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDogYEyuGH8Dxd2\nOt11WSlWxPL7bxKZd6F26NOmVQ+vWDqlthmGPWM1zAFW4l/+600VUMKqqcjAC39W\nm2kCQp+S95WyovzyZ7u4PVEBoYrQJq1oSI1zjxCtRC/u0kqI5iYLyN7ofpJRqjnu\nUCQyu/8AstoW1M88/xwwgRUbJqZxPpbrkBHQGakm+M8Q5ZvJwQPLpPeQLRD7Xjyt\nmgbHLqDaJy1iwEo1V8ypAyS0il0rfNx7TtxTgrBUEpjt9/rPrVSdkSwExyZeFTYS\nPZo2ls24irlHQC+MKVanbSyNFeT20Z9KM/Fl2v6XpwQZFqd4tf2k3U3U7CjJ2K4A\nhi8ABWLtAgMBAAECggEADIHANr+UWxVfaGIM552+4NwB9g8o1k3ecaG0ljidJLbU\n8MpgNR24PdHrgIZM2PmZ++Y259dE5TpjxH+M9oIpnfjozzh/7XTcXtzC2W5HI/Xw\nqLC+ayjsTLsOQ6/W3TuuxZODP3O6Nd+3ngom6FO/M9prFi9RtoZCje64+UJAUcxh\n2A9ZcpQNzjUScqhmJiy+HvKYnmRx7gRuxTLi7drKgFQJUY4qptMindVuTudBVTxZ\n8/gOuUv3cCg+WBgZrWIt9BFE6g0KbZYIJWC892cI22qwPlday+h99134J75fTG03\nAXKFfdvOYO4wv7xAhgwMIn/ewGQhHANw1G0Ah0qmQQKBgQD9u5C93GxnokSCoHSr\nEWm2VDRNQXJuMhrp8QCU2xFZbswOzzjE4IUZS01ac90upRhzuuaIv/mwCLJh9hfH\nRbaPj7Z/0Oy/Vf251oqsGKcZwjaQlLWGA+wFg/7x0D2N9xjNiao4uMx42zohCLG3\nT3U3a05J7rzs99IbYw0NSsu/qwKBgQDqlWGXM1/FCI/YdwMVncuQx/HbzyLLReVx\ny5VegQADOR06DiUJbDilvY+6cjuwIqOYwKYY/zNbM8YubF63mDUTOINEXGB3sCSf\nz2L6TnHQcZ4PQUm1TSHgcliTZmRqWpn5WmAqH/z672jkYGTrWMBsF2E5U5Q1OeB1\nxYWNc1kvxwKBgFl0BA57pJhQw/iNmzQoWm2WeC34ceBZt9VcSwkvxokSH8zkz63R\nPftx6d6G1Ka6O8mpTddOXzfpiQIyYaW2dStdzkh3ns/CAEbBVXhg5KCXMOd+FhUe\nUtqK85nLAbiIMe1cqG+A7014dKDq0MTAtaGJKju0eFTO9fsDy7kw8m4rAoGBAJNl\nd2OFEUkBnzi5VwPPGWiIaaze0xL8gTXmYJ132uUrjvS6jIUGLfXeTSAuxNhge4Dw\nk60jNUa6Gm1zBHTBu5+vI7Phg2/RCsIrkhqLDbKWoWUedczogT/BOWysqq207gii\nw8fUP6YAplzRQLgsFQQWEK3vmTF0g1gc21TMxJ5jAoGBALXq/qhnQOUHUnuPs5M3\n+waHg7mJgzQt1jbClB1AVc722Lp9KSFCIhzbr3AQmHDo/eSAm9OwTTd1I4NW4vY9\nieSp/Md16NCqMXqBP6uINKuEMURAW2gGbLHDxu55EopOly+2NdgYHZbcnaeadAix\nLZoX/XlMSSgtyei0GxS9dZai\n-----END PRIVATE KEY-----\n",
                         "client_email": "*****@*****.**",
                         "client_id": "114948598379533240849",
                         "auth_uri": "https://accounts.google.com/o/oauth2/auth",
                         "token_uri": "https://accounts.google.com/o/oauth2/token",
                         "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
                         "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-ov6wg%40sa-sms-b.iam.gserviceaccount.com"}
            try:

                import firebase_admin

                cred = firebase_admin.credentials.Certificate(Myoptions)

                default_app = firebase_admin.initialize_app(cred)

                from firebase_admin.auth import verify_id_token
            except:
                logging.error("Credentials error")


            findRequest = Accounts.query(Accounts.strUserID == strUserID)
            thisAccountList = findRequest.fetch()
            if len(thisAccountList) > 0:
                thisAccount = thisAccountList[0]

                try:
                    decode_token = verify_id_token(id_token=strAccessToken,app=default_app)
                    uid = decode_token['uid']
                except:
                    uid = None

                if (uid != None) and (uid == strUserID):
                    return thisAccount
                else:
                    return None  # Once firebase credentials is working properly then we should return none here
            else:
                return None

    """

    from accounts import Accounts

    findRequest = Accounts.query(Accounts.strUserID == strUserID)
    thisAccountList = findRequest.fetch()
    if len(thisAccountList) > 0:
        thisAccount = thisAccountList[0]
        return thisAccount
    else:
        return None
Exemple #19
0
    def get(self):
        Guser = users.get_current_user()
        if Guser:

            findRequest = Accounts.query()
            thisAccountsList = findRequest.fetch()

            template = template_env.get_template(
                'templates/dashboard/dashfiles/payments.html')
            context = {'thisAccountsList': thisAccountsList}
            self.response.write(template.render(context))
Exemple #20
0
def load_all_projects(wf):
    log.debug('start updating the cache')
    wf = Workflow3()

    all_accounts = None
    try:
        all_accounts = Accounts(get_accounts(wf))
    except PasswordNotFound:  # API key has not yet been set
        notify("WARNING", "No API key saved")

        log.error('No API key saved')

    log.debug('loading accounts...')

    if not all_accounts:
        # just paste gitlab url to the variables page and token to the keychain and start using the workflow
        url = get_wf_variable(wf, "gitlab_url")
        token = get_wf_variable(wf, "gitlab_token")
        all_accounts = Account({
            "simple_account": {
                "url": url,
                "token": token,
                "project_membership": "true",
                "project_visibility": "internal",
            }
        })

    log.info('Removing cache: {}'.format(DATA_FILE))
    # if os.path.exists(DATA_FILE):
    #     return
    try:
        os.remove(DATA_FILE)
    except:
        pass

    result = []
    for acc_name, acc_settings in all_accounts.dict.items():
        log.info('base api url is: {url}; api token is: {token_name}'.format(
            url=acc_settings.url, token_name=acc_settings.token))
        result.extend(get_all_pages(wf, account=acc_settings))

    with open(DATA_FILE, 'w+') as fp:
        json.dump(result, fp)

    notify(
        "Cache was updated",
        "Was loaded {projects} projects from all gitlab instances".format(
            projects=len(result)))
Exemple #21
0
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Budget ver. 1.0", size=(1100, 650))
        self.Centre(wx.BOTH)
        panel = wx.Panel(self, -1)

        notebook = wx.Notebook(panel)
        notebook.AddPage(Expenses(notebook), "Expenses")
        notebook.AddPage(Income(notebook), "Income")
        notebook.AddPage(Transfer(notebook), "Transfer")
        notebook.AddPage(Accounts(notebook), "Accounts")
        notebook.AddPage(Analysis(notebook), "Analysis")
        notebook.AddPage(Manage(notebook), "Manage")

        sizer = wx.BoxSizer()
        sizer.Add(notebook, 1, wx.EXPAND)
        panel.SetSizer(sizer)
Exemple #22
0
 def inter(self):
     sql = """
         SELECT follow_uk,is_follow_crawler
         FROM yunpan.accounts
         WHERE is_follow_crawler is FALSE AND follow_count>0
         LIMIT 1
     """
     time.sleep(0.5)
     cursor = self.mysql_conn.cursor()
     cursor.execute(sql)
     result = cursor.fetchall()
     if result is not None and len(result) > 0:
         account = result[0][0]
     else:
         account = None
     while (account is not None):
         account = Accounts(account).execute()
Exemple #23
0
def index():

    try:
        account = check_hash(request.cookies)
        success, message = Accounts.logout(account['_id'],
                                           request.cookies['hash'])
        if not success:
            return json.dumps({"success": 0, "message": message})
        else:
            body = json.dumps({"success": 1, "message": message})
            #print "almost done"
            resp = Response(body, status=200)
            #set a cookie that will expire in unixtime 0, which should be the past
            resp.set_cookie('hash', '', expires=0)
            return resp

    except Exception as e:
        return json.dumps({"success": 0, "message": str(e)})
def create_account(fullname, username, password, phone_number, email):
    '''
        Function to create a new account
        '''
    new_account = Accounts("Ane kofi", "akofi", "12a", "22550", "*****@*****.**")
    return new_account
def login_account(number):
    '''
        Function that finds a account by username and password then returns the account .
        '''
    return Accounts.login_by_user("username", "password")
Exemple #26
0
def create_account(first_name, last_name, user_name, password):
    accounts = Accounts(first_name, last_name, user_name, password)
    return accounts
Exemple #27
0
def display_accounts():
    return Accounts.display_accounts()
Exemple #28
0
def isexist_accounts(user_name):
    return Accounts.account_exists(user_name)
Exemple #29
0
def find_accounts(user_name):
    return Accounts.find_by_user_name(user_name)
Exemple #30
0
def index():
    #TODO refactor these methods because some of them already have the account
    #  they do not need to retrieve it from an id.
    if request.method == "GET":
        try:
            account = check_hash(request.cookies)
            success, message = Accounts.get(account['_id'])
            if not success:
                return json.dumps({"success": 0, "message": message})
            else:
                return json.dumps({"success": 1, "message": message})

        except AuthException as e:
            return json.dumps({"success": 0, "message": str(e)})
        except FieldsException as e:
            return json.dumps({"success": 0, "message": str(e)})
        except Exception as e:
            logging.error(str(e))
            return json.dumps({
                "success": 0,
                "message": "Something went wrong"
            })

    if request.method == "POST":
        try:
            data = json.loads(request.data)
            check_fields(data,
                         ["name", "email", "password", "permissions", "orgs"],
                         [])
            success, message = Accounts.create(data)
            if not success:
                return json.dumps({"success": 0, "message": message})
            else:
                return json.dumps({"success": 1, "message": message})

        except FieldsException as e:
            return json.dumps({"success": 0, "message": str(e)})
        except Exception as e:
            logging.error(str(e))
            return json.dumps({
                "success": 0,
                "message": "Something went wrong"
            })

    if request.method == "PUT":
        try:
            account = check_hash(request.cookies)
            data = json.loads(request.data)
            check_fields(data, [],
                         ["name", "email", "password", "permissions", "orgs"])
            success, message = Accounts.update(account, data)
            if not success:
                return json.dumps({"success": 0, "message": message})
            else:
                return json.dumps({"success": 1, "message": message})

        except AuthException as e:
            return json.dumps({"success": 0, "message": str(e)})
        except FieldsException as e:
            return json.dumps({"success": 0, "message": str(e)})
        except Exception as e:
            logging.error(str(e))
            return json.dumps({
                "success": 0,
                "message": "Something went wrong"
            })

    if request.method == "DELETE":
        try:
            account = check_hash(request.cookies)
            success, message = Accounts.delete(account['_id'])
            if not success:
                return json.dumps({"success": 0, "message": message})
            else:
                return json.dumps({"success": 1, "message": message})

        except AuthException as e:
            return json.dumps({"success": 0, "message": str(e)})
        except FieldsException as e:
            return json.dumps({"success": 0, "message": str(e)})
        except Exception as e:
            logging.error(str(e))
            return json.dumps({
                "success": 0,
                "message": "Something went wrong"
            })
Exemple #31
0
    claimErr = os.path.join(errDir, "claim_errlog.txt")
    
    
    (r,c) = commands.getstatusoutput("rm -f %s"%accErr)
    (r,c) = commands.getstatusoutput("rm -f %s"%propErr)
    (r,c) = commands.getstatusoutput("rm -f %s"%copeErr)
    (r,c) = commands.getstatusoutput("rm -f %s"%polErr)
    (r,c) = commands.getstatusoutput("rm -f %s"%claimErr)

    
    pr = Properties(datadir, dumpdir)
    

    
    ## accounts must be loaded
    ac = Accounts(datadir, dumpdir)
    if ac.run():
        ac.showErrors(open(accErr, "w"))
        print "Correct errors in Accounts first"
        
#        sys.exit(1)
    pr.setAccount(ac.mloaded)
    if pr.run():
        print "errors in property"
        pr.showErrors(open(propErr, "w"))


    
    hasErrs = False

Exemple #32
0
        return len(self.iderrs)
def usage():
    print "usage property.py dir dumpdur"
if __name__ == "__main__":
    import sys
    if len(sys.argv) != 3:
        usage()
        sys.exit(1)

    pr = Properties(sys.argv[1], sys.argv[2])
    

        
    ## accounts must be loaded
    ac = Accounts(sys.argv[1], sys.argv[2])
    if ac.run():
        ac.showErrors(open("errs/acc_errlog.txt", "w"))
        print "Correct errors in Accounts first"
#        sys.exit(1)
    pr.setAccount(ac.mloaded)
    if pr.run():
        print "errors in property"
        pr.showErrors(open("errs/prop_errlog.txt", "w"))
#        sys.exit(1)
        
    if pr.loadChangedIDs():
        pr.showChangeIDErrors(open("errs/pr_changeIDErrs.txt", "w"))
        print "Correct errors in changed ids first"
        sys.exit(1)