Exemplo n.º 1
0
def page():
    db.create_all()
    user_sc = Credentialschema(many=False)
    data = request.get_json()

    check_email = data.get('email_address')
    check_pass = data.get('password')

    def check(emailid):
        regexp = '^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$'
        if re.search(regexp, emailid):
            return True

        else:
            return False

    #
    flagging = check(check_email)

    #
    def checkpass(passwd):
        """

        """
        if len(passwd) <= 7:
            return False
        elif not re.search("[A-Z]", passwd):
            return False
        elif not re.search("[0-9]", passwd):
            return False
        return True

    flagging1 = checkpass(check_pass)

    if Credential.select_user_by_email(check_email):
        return custom_http_code('Bad resquest', 400)

    if flagging == False or flagging1 == False:
        return custom_http_code('Bad request', 400)
    else:
        load_data = user_sc.load(data)
        new_user = Credential(load_data)
        # Credential.execute_query()
        db.session.add(new_user)
        db.session.commit()

        #   result=Credential.query.filter_by(first_name='Jane').first()
        result = Credential.select_user_by_email(check_email)
        print(result)
        data = user_sc.dump(result)
        print(data)
        # output=Credential.select_user_by_email(check_email)
        print("done")
        return jsonify(data)
Exemplo n.º 2
0
def updateinfo():
    start = time.time()
    username = request.authorization.username
    passwordinfo = request.authorization.password
    user_sc = Credentialschema(many=False)
    #auth=Credential.select_user_by_emailandpass(username,passwordinfo)
    dbtime = time.time()
    flag = checkauthentication(username, passwordinfo)
    dur = (time.time() - dbtime) * 1000
    c.timing("dbconnect", dur)

    if flag == True:
        user_sc = Credentialschema(many=False)
        data = request.get_json()
        # id=data.get('email_address')
        accountupdated_date = datetime.datetime.now().isoformat()
        password_new = data.get('password')

        pwd = bcrypt.hashpw(password_new.encode('utf8'), bcrypt.gensalt())
        pwd = str(pwd, 'utf-8')
        # self.password=pwd

        firstname = data.get('first_name')
        lastname = data.get('last_name')
        date1 = data.get('account_created')
        date2 = data.get('account_modified')

        def checkpass(passwd):

            if len(passwd) <= 7:
                return False
            elif not re.search("[A-Z]", passwd):
                return False
            elif not re.search("[0-9]", passwd):
                return False
            return True

        flagging1 = checkpass(password_new)

        fetch_keys = list(data.keys())
        if ("account_updated" in fetch_keys
                or "account_created" in fetch_keys):
            return custom_http_code({'Bad request'}, 400)

        elif flagging1 == True:

            schema_of_partial = user_sc.load(data, partial=True)

            #stmt=db.session.update().where(Credential.c.email_address==id).values(password=password_new, first_name= firstname, last_name=last_name,account_updated=account_updated_date,)

            # Credential.first_name=firstname
            # Credential.
            # Credential.last_name

            # Credential.updating(data)
            # db.session.commit()

            dbtime = time.time()
            state = Credential.query.filter_by(email_address=username).update(
                dict(password=pwd, first_name=firstname, last_name=lastname))

            #    db.session.update(first_name=firstname)
            db.session.commit()
            dur = (time.time() - dbtime) * 1000
            c.timing("dbconnect", dur)

            dur = (time.time() - start) * 1000
            c.timing("putusertime", dur)
            c.incr("putuserapi")
            return custom_http_code('done update', 204)

        else:

            c.incr("putuserapi")
            dur = (time.time() - start) * 1000
            c.timing("putusertime", dur)
            return custom_http_code('bad request', 400)

    else:
        return custom_http_code("not authorized", 401)