Beispiel #1
0
def do_signup():
    data = json.loads(request.data)
    integration = data['integration']
    tel = "+1" + data['tel']
    if integration == "messenger":
        print(data)
        email = data['email']
        password = data['password']
        sch.User(tel,
                 active="messenger",
                 messenger_login=sch.MessengerAccount(
                     email=email, password=password)).save()
        try:
            newMessengerInstance(tel, email, password)
        except Exception:
            log.info("whoops")
            pass
    elif integration == "twitter":
        print(data)
        access_token = data['access_token']
        access_token_secret = data['access_secret_token']
        api_key = data['api_key']
        api_secret_key = data['api_secret_key']
        client = None
        try:
            client = newTwitterInstance(
                tel,
                consumer_key=api_key,
                consumer_secret=api_secret_key,
                access_token_key=access_token,
                access_token_secret=access_secret_token)
            lastmsgid = client.GetDirectMessages(return_json=True,
                                                 count=1).events[0].id
        except Exception:
            pass
        lastmsgid = 100
        sch.User(tel,
                 active="twitter",
                 twitter_login=sch.TwitterAccount(
                     access_token=access_token,
                     access_token_secret=access_token_secret,
                     api_key=api_key,
                     api_secret_key=api_secret_key,
                     last_msg=lastmsgid)).save()

    return json.dumps({"status": 200})
Beispiel #2
0
 def registerUser(self, **values):
     values['password'] = self.app.bcrypt.generate_password_hash(values['password'])
     user = schema.User(**values)
     try:
         return user.save()
     except schema.NotUniqueError:
         return False
     except schema.ValidationError:
         return None
def get_user_by_token(session: Session, token: str) -> Optional[schema.User]:
    users = session.query(User).filter(User.token == token).all()
    if len(users) != 1:
        return None
    user = users[0]
    db_user = schema.DBUser.from_orm(user)
    if datetime.now() > db_user.token_expires_at:
        return None
    return schema.User(**db_user.dict())
Beispiel #4
0
    def save_user(self, user: tweepy.User) -> schema.User:
        user_node = schema.User.nodes.get_or_none(screen_name=user.screen_name)

        if user_node is None:
            user_node = schema.User()

        user_node.user_id = user.id
        user_node.name = user.name
        user_node.screen_name = user.screen_name
        user_node.location = user.location
        user_node.description = user.description
        user_node.url = user.url
        user_node.protected = user.protected
        user_node.followers_count = user.followers_count
        user_node.friends_count = user.friends_count
        user_node.listed_count = user.listed_count
        user_node.created_at = user.created_at
        user_node.favourites_count = user.favourites_count
        user_node.utc_offset = user.utc_offset
        user_node.time_zone = user.time_zone
        user_node.geo_enabled = user.geo_enabled
        user_node.verified = user.verified
        user_node.statuses_count = user.statuses_count
        user_node.contributors_enabled = user.contributors_enabled
        user_node.is_translator = user.is_translator
        user_node.is_translation_enabled = user.is_translation_enabled
        user_node.profile_background_color = user.profile_background_color
        user_node.profile_background_image_url = user.profile_use_background_image
        user_node.profile_background_image_url_https = user.profile_background_image_url_https
        user_node.profile_background_tile = user.profile_background_tile
        user_node.profile_image_url = user.profile_image_url
        user_node.profile_image_url_https = user.profile_image_url_https
        user_node.profile_link_color = user.profile_link_color
        user_node.profile_sidebar_border_color = user.profile_sidebar_border_color
        user_node.profile_sidebar_fill_color = user.profile_sidebar_fill_color
        user_node.profile_text_color = user.profile_text_color
        user_node.profile_use_background_image = user.profile_use_background_image
        user_node.has_extended_profile = user.has_extended_profile
        user_node.default_profile = user.default_profile
        user_node.default_profile_image = user.default_profile_image
        user_node.notifications = user.notifications
        user_node.translator_type = user.translator_type

        user_node.save()

        print('save {}'.format(user_node.screen_name))

        return user_node
Beispiel #5
0
def add():

    #adds the new user to the User database by taking the form information and creating a User out of it.

    db = database.get_session()

    # Using http request method we can get information from html elements by using the request library in python. Give any html element a name and an action associated with that
    # name for example <form action='\newdriver method=post> and if the form has an element called Name: <input type="text" name="name" we can get the form to send the value of
    # name entered using the post method and we can get it on the python end by doing request.form['name'] and since the form has an action called '\newdriver the server will know
    # and run whichever function is below the @app.route('/newdriver) line
    firstname = request.form['firstname']
    lastname = request.form['lastname']
    username = request.form['username']
    email = request.form['email']
    role = request.form['role']

    # Using the schema we created above we can enter the data we got into the database. Also another copy from http-demo and can be found in line 82 of the http-demo
    new_driver = schema.User(firstname=firstname,
                             lastname=lastname,
                             username=username,
                             email=email,
                             role=role)

    # Add the new driver we defined above to the database using the built in method 'add' and once again using the built in method 'commit' make sure the record is permanently
    # entered into the databse.
    db.add(new_driver)
    db.commit()
    db.close()

    # Let's not forget to do a db.close() for all our sessions with the database. It won't make a difference right now but once we deploy the app or start testing it on Heroku
    # it will be a mess.

    msg = Message('Set Your Password',
                  sender=('Reed College Nightbus', '*****@*****.**'),
                  recipients=[email])
    # salt separates tokens of the same input values
    token = s.dumps(email, salt='set-password')
    link = url_for('set_password', token=token, _external=True)
    msg.html = '<p>Confirm your email.</p><p> Please follow this link to activate your account: {}</p>'.format(
        link)
    mail.send(msg)

    # To check if a user has been successfully added to the database open a new tab in terminal, use the command psql nightbus to go to the nightbus database and do
    # SELECT * FROM "Users"; and it should be the last entry in that table.
    # Most of the stuff related to the databases I found at https://realpython.com/blog/python/flask-by-example-part-2-postgres-sqlalchemy-and-alembic/ and http-demo

    return redirect(url_for('admin'))
Beispiel #6
0
def register():

    db = database.get_session()
    # this function should allow anyone to register and be able to log in right now. Once we have that we can work on different views for different types of users and stuff like that.
    # it works in similar fashion like the add driver and remove driver functions it connects to the databases using the get session function and gets the data from the form using the
    # flask request module then it creates a User and an Auth entry. The user entry is just for keeping track of users while the auth entry will contain the username and the password
    # the person signed up with. We don't actually store the password we encrypt it using the passlib library that we imported above. We then add both entries to their respective
    # tables and we commit and then we are done.

    db = database.get_session()

    firstname = request.form['firstname']
    lastname = request.form['lastname']
    email = request.form['email']
    username = request.form['username']
    password = request.form['password']
    role = (request.form['role']).lower()

    user = schema.User(firstname=firstname,
                       lastname=lastname,
                       email=email,
                       username=username,
                       role=role)
    user_auth = schema.Auth(username=username)
    user_auth.encrypt_password(password)

    db.add(user)
    db.add(user_auth)
    db.commit()

    # The next few lines automatically send an email to the email address the user entered when registering asking them to confirm their email. We use the generate_confirmation_token
    # we defined in our email_confimation module to generate a random token. The url they will get will be of the format localhost/confirm_email + token and when they click it they
    # should be redirected to the function immediately below.

    #        subject = 'Confirm Your Email'
    #        token = generate_confirmation_token(email, serializer)
    #        confirm_url = url_for('confirm_email', token = token, _external=True)
    #        html = render_template('activate.html', confirm_url = confirm_url)
    #        send_mail(user.email, subject, html, mail)

    db.close()
    return redirect(url_for('login'))
Beispiel #7
0
def load_user(sessionID):
    try:
        (userName, userID) = db.getUserNameBySessionID(sessionID)
        return db.User(userID, userName, sessionID=sessionID)
    except:
        return None
Beispiel #8
0
 def get_user(self):
     return schema.User(username="******")
def test_repr():
    assert repr(schema.Team())
    assert repr(schema.User())
    assert repr(schema.Challenge())
Beispiel #10
0
    def __init__(self):
        import schema

        self.CURRENT_CASE_ANNOTATION = schema.CaseAnnotation(
        )  # not currently used

        self.CURRENT_USER = schema.User(
            username="******")  # no users are currently being used

        self.CURRENT_FILE_SIZE = schema.FileSize(
            65000000000
        )  # this is the total amount of files in repo table shown

        self.CURRENT_PROGRAMS = [schema.Program(name="NHSII")]

        self.DATA_CATEGORIES = [
            schema.DataCategories(case_count=2, data_category="Raw Reads"),
            schema.DataCategories(case_count=2, data_category="Gene Families"),
            schema.DataCategories(case_count=2,
                                  data_category="Taxonomic Profiles")
        ]

        self.DATA_CATEGORIES_SINGLE_CASE = [
            schema.DataCategories(file_count=1, data_category="Raw Reads"),
            schema.DataCategories(file_count=1, data_category="Gene Families"),
            schema.DataCategories(file_count=1,
                                  data_category="Taxonomic Profiles")
        ]

        self.EXPERIMENTAL_STRATEGIES = [
            schema.ExperimentalStrategies(file_count=6,
                                          experimental_strategy="WMGX"),
            schema.ExperimentalStrategies(file_count=6,
                                          experimental_strategy="16S")
        ]

        self.CURRENT_PROJECTS = {
            "1":
            schema.Project(
                id="1",
                project_id="NHSII-DemoA",
                name="NHSII-DemoA",
                program=self.CURRENT_PROGRAMS[0],
                summary=schema.Summary(
                    case_count=2,
                    file_count=6,
                    data_categories=self.DATA_CATEGORIES,
                    experimental_strategies=[self.EXPERIMENTAL_STRATEGIES[0]],
                    file_size=15),
                primary_site=["Stool"]),
            "2":
            schema.Project(
                id="2",
                project_id="NHSII-DemoB",
                name="NHSII-DemoB",
                program=self.CURRENT_PROGRAMS[0],
                summary=schema.Summary(
                    case_count=2,
                    file_count=6,
                    data_categories=self.DATA_CATEGORIES,
                    experimental_strategies=[self.EXPERIMENTAL_STRATEGIES[1]],
                    file_size=15),
                primary_site=["Stool"]),
        }

        self.CURRENT_FILE_CASES = {
            "1":
            schema.FileCase(
                1, "Case1", self.CURRENT_PROJECTS["1"],
                schema.Demographic("not hispanic or latino", "male", "white"),
                "Stool"),
            "2":
            schema.FileCase(
                2, "Case2", self.CURRENT_PROJECTS["1"],
                schema.Demographic("not hispanic or latino", "male", "white"),
                "Stool"),
            "3":
            schema.FileCase(
                3, "Case3", self.CURRENT_PROJECTS["2"],
                schema.Demographic("not hispanic or latino", "female",
                                   "white"), "Stool"),
            "4":
            schema.FileCase(
                4, "Case4", self.CURRENT_PROJECTS["2"],
                schema.Demographic("hispanic or latino", "female", "white"),
                "Stool")
        }

        self.CASE_FILES = {
            "1":
            schema.CaseFile(1,
                            experimental_strategy="WMGX",
                            data_category="Raw Reads",
                            data_format="Fastq",
                            platform="Illumina MiSeq",
                            access="controlled"),
            "2":
            schema.CaseFile(2,
                            experimental_strategy="WMGX",
                            data_category="Taxonomic Profile",
                            data_format="TSV",
                            platform="Illumina MiSeq",
                            access="open"),
            "3":
            schema.CaseFile(3,
                            experimental_strategy="WMGX",
                            data_category="Gene Families",
                            data_format="TSV",
                            platform="Illumina MiSeq",
                            access="open"),
            "4":
            schema.CaseFile(4,
                            experimental_strategy="WMGX",
                            data_category="Raw Reads",
                            data_format="Fastq",
                            platform="Illumina MiSeq",
                            access="controlled"),
            "5":
            schema.CaseFile(5,
                            experimental_strategy="WMGX",
                            data_category="Taxonomic Profile",
                            data_format="TSV",
                            platform="Illumina MiSeq",
                            access="open"),
            "6":
            schema.CaseFile(6,
                            experimental_strategy="WMGX",
                            data_category="Gene Families",
                            data_format="TSV",
                            platform="Illumina MiSeq",
                            access="open"),
            "7":
            schema.CaseFile(7,
                            experimental_strategy="16S",
                            data_category="Raw Reads",
                            data_format="Fastq",
                            platform="Illumina HiSeq",
                            access="controlled"),
            "8":
            schema.CaseFile(8,
                            experimental_strategy="16S",
                            data_category="Taxonomic Profile",
                            data_format="TSV",
                            platform="Illumina HiSeq",
                            access="open"),
            "9":
            schema.CaseFile(9,
                            experimental_strategy="16S",
                            data_category="Gene Families",
                            data_format="TSV",
                            platform="Illumina HiSeq",
                            access="open"),
            "10":
            schema.CaseFile(10,
                            experimental_strategy="16S",
                            data_category="Raw Reads",
                            data_format="Fastq",
                            platform="Illumina HiSeq",
                            access="controlled"),
            "11":
            schema.CaseFile(11,
                            experimental_strategy="16S",
                            data_category="Taxonomic Profile",
                            data_format="TSV",
                            platform="Illumina HiSeq",
                            access="open"),
            "12":
            schema.CaseFile(12,
                            experimental_strategy="16S",
                            data_category="Gene Families",
                            data_format="TSV",
                            platform="Illumina HiSeq",
                            access="open"),
        }

        self.FILE_SIZES = {
            "gene": 300000000,
            "raw": 5000000000,
            "taxa": 200000000
        }

        self.TEST_FILES = {
            "1":
            schema.File(1, "demoA_sample1_raw_reads.fastq", "case1", "sample1",
                        "controlled", self.FILE_SIZES["raw"], "Raw Reads",
                        "Fastq", "Illumina MiSeq", "WMGX",
                        "demoA_sample1_raw_reads.fastq",
                        schema.FileCases(hits=[self.CURRENT_FILE_CASES["1"]])),
            "2":
            schema.File(2, "demoA_sample1_taxonomic_profile.tsv", "case1",
                        "sample1", "open", self.FILE_SIZES["taxa"],
                        "Taxonomic Profile", "TSV", "Illumina MiSeq", "WMGX",
                        "demoA_sample1_taxonomic_profile.tsv",
                        schema.FileCases(hits=[self.CURRENT_FILE_CASES["1"]])),
            "3":
            schema.File(3, "demoA_sample1_gene_families.tsv", "case1",
                        "sample1", "open", self.FILE_SIZES["gene"],
                        "Gene Families", "TSV", "Illumina MiSeq", "WMGX",
                        "demoA_sample1_gene_families.tsv",
                        schema.FileCases(hits=[self.CURRENT_FILE_CASES["1"]])),
            "4":
            schema.File(4, "demoA_sample2_raw_reads.fastq", "case2", "sample2",
                        "controlled", self.FILE_SIZES["raw"], "Raw Reads",
                        "Fastq", "Illumina MiSeq", "WMGX",
                        "demoA_sample2_raw_reads.fastq",
                        schema.FileCases(hits=[self.CURRENT_FILE_CASES["2"]])),
            "5":
            schema.File(5, "demoA_sample2_taxonomic_profile.tsv", "case2",
                        "sample2", "open", self.FILE_SIZES["taxa"],
                        "Taxonomic Profile", "TSV", "Illumina MiSeq", "WMGX",
                        "demoA_sample2_taxonomic_profile.tsv",
                        schema.FileCases(hits=[self.CURRENT_FILE_CASES["2"]])),
            "6":
            schema.File(6, "demoA_sample2_gene_families.tsv", "case2",
                        "sample2", "open", self.FILE_SIZES["gene"],
                        "Gene Families", "TSV", "Illumina MiSeq", "WMGX",
                        "demoA_sample2_gene_families.tsv",
                        schema.FileCases(hits=[self.CURRENT_FILE_CASES["2"]])),
            "7":
            schema.File(7, "demoB_sample3_raw_reads.fastq", "case3", "sample3",
                        "controlled", self.FILE_SIZES["raw"], "Raw Reads",
                        "Fastq", "Illumina HiSeq", "16S",
                        "demoB_sample3_raw_reads.fastq",
                        schema.FileCases(hits=[self.CURRENT_FILE_CASES["3"]])),
            "8":
            schema.File(8, "demoB_sample3_taxonomic_profile.tsv", "case3",
                        "sample3", "open", self.FILE_SIZES["taxa"],
                        "Taxonomic Profile", "TSV", "Illumina HiSeq", "16S",
                        "demoB_sample3_taxonomic_profile.tsv",
                        schema.FileCases(hits=[self.CURRENT_FILE_CASES["3"]])),
            "9":
            schema.File(9, "demoB_sample3_gene_families.tsv", "case3",
                        "sample3", "open", self.FILE_SIZES["gene"],
                        "Gene Families", "TSV", "Illumina HiSeq", "16S",
                        "demoB_sample3_gene_families.tsv",
                        schema.FileCases(hits=[self.CURRENT_FILE_CASES["3"]])),
            "10":
            schema.File(10, "demoB_sample4_raw_reads.fastq", "case4",
                        "sample4", "controlled", self.FILE_SIZES["raw"],
                        "Raw Reads", "Fastq", "Illumina HiSeq", "16S",
                        "demoB_sample4_raw_reads.fastq",
                        schema.FileCases(hits=[self.CURRENT_FILE_CASES["4"]])),
            "11":
            schema.File(11, "demoB_sample4_taxonomic_profile.tsv", "case4",
                        "sample4", "open", self.FILE_SIZES["taxa"],
                        "Taxonomic Profile", "TSV", "Illumina HiSeq", "16S",
                        "demoB_sample4_taxonomic_profile.tsv",
                        schema.FileCases(hits=[self.CURRENT_FILE_CASES["4"]])),
            "12":
            schema.File(12, "demoB_sample4_gene_families.tsv", "case4",
                        "sample4", "open", self.FILE_SIZES["gene"],
                        "Gene Families", "TSV", "Illumina HiSeq", "16S",
                        "demoB_sample4_gene_families.tsv",
                        schema.FileCases(hits=[self.CURRENT_FILE_CASES["4"]])),
        }

        self.CURRENT_COUNTS = schema.Count(projects="2",
                                           participants="4",
                                           samples="4",
                                           dataFormats="3",
                                           rawFiles="4",
                                           processedFiles="8")

        self.TEST_CASES = {
            "1":
            schema.Case(1,
                        case_id="Case1",
                        primary_site="Stool",
                        demographic=schema.Demographic(
                            "not hispanic or latino", "male", "white"),
                        project=self.CURRENT_PROJECTS["1"],
                        summary=schema.Summary(
                            case_count=1,
                            file_count=1,
                            file_size=1,
                            data_categories=self.DATA_CATEGORIES_SINGLE_CASE),
                        files=schema.CaseFiles(hits=[
                            self.CASE_FILES["1"], self.CASE_FILES["2"],
                            self.CASE_FILES["3"]
                        ])),
            "2":
            schema.Case(2,
                        case_id="Case2",
                        primary_site="Stool",
                        demographic=schema.Demographic(
                            "not hispanic or latino", "male", "white"),
                        project=self.CURRENT_PROJECTS["1"],
                        summary=schema.Summary(
                            case_count=1,
                            file_count=1,
                            file_size=1,
                            data_categories=self.DATA_CATEGORIES_SINGLE_CASE),
                        files=schema.CaseFiles(hits=[
                            self.CASE_FILES["4"], self.CASE_FILES["5"],
                            self.CASE_FILES["6"]
                        ])),
            "3":
            schema.Case(3,
                        case_id="Case3",
                        primary_site="Stool",
                        demographic=schema.Demographic(
                            "not hispanic or latino", "female", "white"),
                        project=self.CURRENT_PROJECTS["2"],
                        summary=schema.Summary(
                            case_count=1,
                            file_count=1,
                            file_size=1,
                            data_categories=self.DATA_CATEGORIES_SINGLE_CASE),
                        files=schema.CaseFiles(hits=[
                            self.CASE_FILES["7"], self.CASE_FILES["8"],
                            self.CASE_FILES["9"]
                        ])),
            "4":
            schema.Case(4,
                        case_id="Case4",
                        primary_site="Stool",
                        demographic=schema.Demographic("hispanic or latino",
                                                       "female", "white"),
                        project=self.CURRENT_PROJECTS["2"],
                        summary=schema.Summary(
                            case_count=1,
                            file_count=1,
                            file_size=1,
                            data_categories=self.DATA_CATEGORIES_SINGLE_CASE),
                        files=schema.CaseFiles(hits=[
                            self.CASE_FILES["10"], self.CASE_FILES["11"],
                            self.CASE_FILES["12"]
                        ]))
        }

        self.CURRENT_FILES = schema.Files(hits=self.TEST_FILES.keys())
        self.CURRENT_CASES = schema.RepositoryCases(
            hits=self.TEST_CASES.keys())
Beispiel #11
0
 def _login(self, sess, username, eventID, creator, uid):
     sess.add(
         schema.User(id=uid,
                     username=username,
                     event_id=eventID,
                     creator=creator))