Esempio n. 1
0
def register():
    if request.method == "POST":
        sqlSession = AppSession()

        username = request.form.get("username")
        password = request.form.get("password")
        confirmation = request.form.get("confirmation")

        if not username or not password or not username:
            return apology("Field Check", 400)

        if password != confirmation:
            return apology("Passwords don't match", 400)

        if sqlSession.query(User).filter(User.username == username).first():
            return apology("username exists")

        user = User(username=username,
                    hash=generate_password_hash(password, "pbkdf2:sha256"))

        sqlSession.add(user)
        sqlSession.commit()

        sqlSession.close()
        return redirect("/login")
    else:
        return render_template("register.html")
Esempio n. 2
0
def save_user(username, userid, realname, email, amount):
    engine = create_engine('sqlite:///sqlalchemy_database.db')
    DBSession = sessionmaker(bind=engine)
    session = DBSession()
    ed_user = User(uusername, userid, realname, email, amount)
    session.add(ed_user)
    session.commit()
Esempio n. 3
0
def update_database(amount_recv, nfc_user_recv, num_keg_recv):
    try:
        engine = create_engine('sqlite:///sqlalchemy_database.db')
        DBSession = sessionmaker(bind = engine)
        session = DBSession()
        ed_user = session.query(User).filter_by(userid = nfc_user_recv)
        try:
            ed_user = ed_user.one()
        except:
            create_user = User(username = '******', userid = nfc_user_recv, realname = 'No Name', email = 'No Email', amount = amount_recv)
            session.add(create_user)
            session.commit()
    
        total_amount_user = float(ed_user.amount) + amount_recv
        ed_user.amount = total_amount_user
        session.commit()
        
        #The Keg id must be create before        
        ed_keg = session.query(Keg).filter_by(kegid = num_keg_recv).one()
        total_amount_keg = float(ed_keg.amount) + amount_recv
        ed_keg.amount = total_amount_keg
        session.commit()
        return True 
    
    except:
        return False   
Esempio n. 4
0
def save_keg(kegid, amount):
    engine = create_engine('sqlite:///sqlalchemy_database.db')
    DBSession = sessionmaker(bind=engine)
    session = DBSession()
    ed_keg = User(kegid, amount)
    session.add(ed_keg)
    session.commit()
Esempio n. 5
0
 def put(self, email, password):
     if email and password:
         if session.query(User).filter(User.email == email).first() is not None:
             return "Error: email already in use", 400
         new_user = User(email=email, password=psswdhash.hash_password(password), token=generateToken())
         session.add(new_user)
         session.commit()
         return session.query(User).filter(User.email == email).first().token
Esempio n. 6
0
def addUser(user):
	image = user.getImage()
	new_image = Image(x_coord=image.getX(), y_coord=image.getY(), path=image.getPath())
	session.add(new_image)

	new_user = User(new_image)
	session.add(new_user)
	return user
Esempio n. 7
0
def insert_data_User(username, fullname, email, password, nfc_id):
    new_user = User(username=username,
                    fullname=fullname,
                    email=email,
                    password=password,
                    nfc_id=nfc_id)
    session.add(new_user)
    session.commit()
def insert_user():
    session = connection()
    try:
        new_user = User(username=request.json['username'], fullname=request.json['fullname'],
                        email=request.json['email'], password=request.json['password'], nfc_id=request.json['nfc_id'],
                        user_flow=request.json['user_flow'])
        session.add(new_user)
        session.commit()
        return jsonify({'post': request.json}), 201
    except:
        return False
Esempio n. 9
0
    def put(self, email, sn, id):
        """
        This function is used to register a user via email, facebook or google
        :param email: The user's email address
        :param sn: The method used for authentifying. Currently supports "email", "fb" and "google"
        :param id: In case of facebook and google method, the fb or google ID. Else, the user password
        :return: on success, the user's token
        """
        if not email:
            return {"error_type": "AuthenticationError(ERROR: User not found)", "status_code": 404}
        if not sn:
            return {"error_type": "AuthenticationError(ERROR: No auth method defined)", "status_code": 404}
        if not id:
            return {"error_type": "AuthenticationError(ERROR: No password/id given)", "status_code": 404}

        print("Got args : email = " + email + " sn = " + sn + " id = " + id)
        if session.query(User).filter(User.email == email).first() is not None:
            return {"error_type": "AuthenticationError(ERROR: Email already in use)",
                    "status_code": 400}

        if sn == "email":
            new_user = User(email=email, password=psswdhash.hash_password(id), token=generateToken())
            session.add(new_user)
            session.commit()

        elif sn == "fb":
            new_user = User(email=email, password=None, token=generateToken(), fb=True, fb_id=id)
            session.add(new_user)
            session.commit()

        elif sn == "google":
            new_user = User(email=email, password=None, token=generateToken(), google=True, google_id=id)
            session.add(new_user)
            session.commit()
        else:
            return {"error_type": "AuthenticationError(ERROR: Invalid query)",
                    "status_code": 400}

        TOKENS.append(session.query(User).filter(User.email == email).first().token)
        return {"user_token": session.query(User).filter(User.email == email).first().token,
                "status_code": 200}
Esempio n. 10
0
def save_user(username,fullname,email,userid):
    if user_exists(username):
        return (False, "exists")
    else:
        try:
            session = db_session()
            new_user = User(username=username, realname=fullname, email=email, userid=userid, amount=0)
            session.add(new_user)
            session.commit()
            return (True, "No error")
        except:
            return (False, "Error saving")
Esempio n. 11
0
def create_user_service():
    if not request.json or not 'userid' in request.json or not 'username' in request.json or not 'realname' in request.json or not 'email' in request.json:
        abort(400)
    if user_exists(request.json['username']):
        abort(400)
    session = db_session()
    try:
        user = User(userid=request.json['userid'], username=request.json['username'], realname=request.json['realname'], email=request.json['email'], amount=0)
        session.add(user)
        session.commit()
    except:
        abort(404)
    return jsonify(id=user.id,userid=user.userid,username=user.username,realname=user.realname,email=user.email,amount=user.amount)
Esempio n. 12
0
def save(table, info):
    session = connection()
    try:
        if table == User:
            new_user = User(username=info[0], fullname=info[1], email=info[2], password=info[3], nfc_id=info[4],
                            user_flow=info[5])
            session.add(new_user)
        elif table == Keg:
            new_keg = Keg(keg_id=info[0], keg_flow=info[1])
            session.add(new_keg)
        session.commit()
        return True
    except:
        return False
Esempio n. 13
0
 def put(self, name, password):
     """
     This function registers a team
     :param name: The team's name/nickname
     :param password: the team's plain password
     :return: the team's token
     """
     usr = session.query(Team).filter(Team.name == name).first()
     if usr is not None:
         return {"error_type": "AuthenticationError(ERROR: Team name taken",
                 "status_code": 400}
     new_team = User(name=name, password=psswdhash.hash_password(password), token=generateToken())
     session.add(new_team)
     session.commit()
     return session.query(Team).filter(Team.name == name).first().token
Esempio n. 14
0
def crear_users():

    try:
        #load session
        session = db_session()
        #saving user
        new_user = User(username=username,
                        userid=userid,
                        realname=realname,
                        email=email,
                        amount=amount)
        session.add(new_user)
        session.commit()
        print "User, Perfecte"
    except:
        print "User, Malament"
Esempio n. 15
0
 def put(self, email, password):
     """
     Endpoint for registering a new user
     :param email: The user's email address
     :param password: The user's unciphered password
     :return: User token from database, which can be subsequently sent to auth/token for next authentications
     """
     if email and password:
         if session.query(User).filter(User.email == email).first() is not None:
             return {"error_type": "AuthenticationError(ERROR: Email already in use)",
                     "status_code": 400}
         new_user = User(email=email, password=psswdhash.hash_password(password), token=generateToken())
         session.add(new_user)
         session.commit()
         return {"user_token": session.query(User).filter(User.email == email).first().token,
                 "status_code": 200}
Esempio n. 16
0
def new_user(username, name, password, email):

    session = Session()
    session = Session()
    registered_user = session.query(User).filter_by(username=username,
                                                    password=password,
                                                    email=email,
                                                    name=name).first()
    try:
        if registered_user is None:
            new_user = User(username=username,
                            name=name,
                            password=password,
                            email=email)
            session.add(new_user)
            session.commit()
            return True
    except:
        return False
Esempio n. 17
0
def save_data(username, fullname, email, password):
    #Check if user_exists() for register
    if user_exists(username):
        return False
    else:
        #Adding user
        try:
            #load session
            session = db_session()
            #saving user
            new_user = User(username=username,
                            fullname=fullname,
                            email=email,
                            password=password)
            session.add(new_user)
            session.commit()
            return True
        except:
            return False
Esempio n. 18
0
def save_data(message):
    #Aqui guardarem el messsage rebut(que constara del NFC's id i la quantitat de birra)
    try:
        #desglosem en variables
        message1 = message.split(" ")
        userid = message1[0]
        amount = float(message1[1])
        keg = int(message1[2])
        print '\n rebut', userid, " ", amount, " ", keg
        #load session
        session = db_session()
        #primer de tot, buscar a la taula la quantitat de birra que ha vegut un id,
        #actualitzar aquest valor sumant lo que hi havia i lo nou
        user = session.query(User).filter_by(userid=userid)
        try:
            user = user.one()
        except:
            new_user = User(username='******',
                            userid=userid,
                            realname='fantasma',
                            email='no email',
                            amount=amount)
            session.add(new_user)
            session.commit()

        amount_total = float(user.amount) + amount
        user.amount = amount_total
        print 'user.amount = ', user.amount
        session.commit()

        #guardem a la taula keg, la nova etrada
        keg1 = session.query(Keg).filter_by(kegid=keg).one()
        amount_total1 = float(keg1.amount) + amount
        keg1.amount = amount_total1
        print 'keg1.amount2= ', keg1.amount

        session.commit()
        return True
    except:
        return False
Esempio n. 19
0
def create_user_ws():
    if not request.json or not 'username' in request.json or not 'userid' in request.json or not 'realname' in request.json or not 'email' in request.json:
        abort(400)
    if exist_user(request.json['username']):
        abort(400)
    engine = create_engine('sqlite:///sqlalchemy_database.db')
    DBSession = sessionmaker(bind=engine)
    session = DBSession()
    try:
        ed_user = User(username=request.json['username'],
                       userid=request.json['userid'],
                       realname=request.json['realname'],
                       email=request.json['email'],
                       amount=0.0)
        session.add(ed_user)
        session.commit()
    except:
        abort(404)
    return jsonify(id=ed_user.id,
                   username=ed_user.username,
                   userid=ed_user.userid,
                   realname=ed_user.realname,
                   email=ed_user.email,
                   amount=ed_user.amount)
Esempio n. 20
0
from sqlalchemy_declarative import User, Base

path_to_db = "mydatabase.db"
engine = create_engine('sqlite:///' + path_to_db)
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Insert a User in the user table
new_user1 = User(username='******',
                 fullname="C3PO",
                 email="*****@*****.**",
                 password="******")
session.add(new_user1)
new_user2 = User(username='******',
                 fullname="R2D2",
                 email="*****@*****.**",
                 password="******")
session.add(new_user2)
session.commit()
Esempio n. 21
0
# session.rollback()
session = DBSession()

# urllib3.disable_warnings()
url = 'http://circleci.com/api/v1.1/recent-builds?circle-token=99de86208b9f8a6cd52e1a8e0534b7dc8c45862a'
payload = open("/home/user/apps/flask/request.json")
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
r = requests.get(url, data=payload, headers=headers)
data = r.json()

for build in data:
    # session.query(User).all()
    new_user = session.query(User).filter(
        User.name == build['username']).first()
    if not new_user:
        new_user = User(name=build['username'])
        session.commit()
        session.add(new_user)

    # if not build['status'] == 'running' or not build['status'] == 'queued':
    if build['status'] == 'failed' or build['status'] == 'no_tests' or build[
            'status'] == 'success' or build['status'] == 'fixed' or build[
                'status'] == 'timedout':
        metric = session.query(Metric).filter(
            Metric.build_url == build['build_url']).first()
        if not metric:
            merged_to_master = True if build['all_commit_details'] and len(
                build['all_commit_details']) > 1 else False
            related_branch = build['branch']
            if build['all_commit_details'] and len(
                    build['all_commit_details']) > 1:
Esempio n. 22
0
import sys, os
sys.path.append("/".join(os.path.abspath(__file__).split("/")[0:-2]))
from sqlalchemy_declarative import User, Base
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

engine = create_engine('sqlite:///sqlalchemy_example_auth.db')
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
DBSession.bind = engine
session = DBSession()

usr = User(email="test_user", password="******", token="test_token")
session.add(usr)
session.commit()

print(session.query(User).all())
#usr = session.query(User).first()
#print(usr.email)
#print(usr.password)
usr = session.query(User).filter(User.email == "*****@*****.**").first()
print(usr)
print(usr.email)
print(usr.password)
print(usr.token)

Esempio n. 23
0
import sys, os
sys.path.append("/".join(os.path.abspath(__file__).split("/")[0:-2]))
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy_declarative import Base, User

engine = create_engine('sqlite:///sqlalchemy_example_auth.db')
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Insert a User in the user table
new_user = User(email='*****@*****.**', password="******", token='test')
session.add(new_user)
session.commit()