Exemplo n.º 1
0
def user_signup():
    input_data = request.get_json()

    first_name = input_data.get('first_name')
    last_name = input_data.get('last_name')
    admin = User(
        user_name = first_name + " " + last_name,
        email=input_data.get('email'),
        password=input_data.get('password'),
        role=input_data.get('role'),
        initial_balance = input_data.get('initial_balance')
    )
    admin.add()

    return "Signed Up"
Exemplo n.º 2
0
def verify_token(token):
    user = User.verify_auth_token(token)
    print(token)
    if user is None:
        return False
    g.user = user
    return True
Exemplo n.º 3
0
def init_db():
    db.create_all()
    Role.insert_roles()
    admin = User.query.get(1) or User()
    admin.username = Config.FLASKY_ADMIN
    admin.password = '******'
    db.session.add(admin)
    db.session.commit()
    admin.role_id = 3
    db.session.commit()
Exemplo n.º 4
0
def newUser():

    try:
        db.session.user
    except:
        return redirect(url_for('login'))

    if request.method == 'POST':
        import logging
        logging.warn(request.form['creation_user'])
        if request.form['creation_user'] == 'True':
            new = User(name=request.form['name'], title=request.form['title'], user_name=request.form['user_name'], password=request.form['password'], user_creator=True)
        else:
            new = User(name=request.form['name'], title=request.form['title'], user_name=request.form['user_name'], password=request.form['password'],)
        db.session.add(new)
        db.session.commit()
        flash("User was created")
        return redirect(url_for('printUsers'))
    else:
        return render_template('user_templates/new_user.html')
Exemplo n.º 5
0
def insertUser(openid, userIdentity, avatarUrl, nickName, ownedProjects,
               participatedProjects):
    """
    :return: user id
    """
    u = User(openid=openid,
             userIdentity=userIdentity,
             avatarUrl=avatarUrl,
             nickName=nickName,
             ownedProjects=ownedProjects,
             participatedProjects=participatedProjects)
    db.session.add(u)
    db.session.flush()
    db.session.commit()
    return openid
Exemplo n.º 6
0
    def post(self):
        parsed_args = self.parser.parse_args()
        username = parsed_args['username']
        password = parsed_args['password']
        description = parsed_args['description']
        if username is None or password is None:
            abort(400, message="Missing arguments")
        if session.query(User).filter(User.username == username).first() is not None:
            abort(400, message="User {} already exists".format(username))
        user = User(username=username)
        user.hash_password(password)
        if description is not None:
            user.description = description

        if 'image' in request.files:
            image = request.files['image']
            if image.filename != '':
                cloudinary_struct = uploader.upload(image, public_id='{0}_{1}'.format(username, image.filename))
                user.pic_url = cloudinary_struct['url']
        session.add(user)
        session.commit()

        return user, 201
Exemplo n.º 7
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# *************************************************************
# Filename @ sql_test.py
# Author @ Likex
# Create date @ 2016-02-27 20:04:46
# Description @ 
# *************************************************************



# Script starts from here

from manage import User
from manage import db
b=User(username='******')
c=User(username='******')
d=User(username='******')
db.session.add_all([b,c,d])
db.session.commit()
Exemplo n.º 8
0
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from manage import User, Channel

app = Flask(__name__)
app.config.from_pyfile('dbconf.cfg')
db = SQLAlchemy(app)

u1 = User(id=1, name='Louis')
u2 = User(id=2, name='John')

c1 = Channel(id=1, name='LTT')
c2 = Channel(id=2, name='EMT')

c1.subscribers.append(u1)
c1.subscribers.append(u2)
c2.subscribers.append(u2)

db.session.add(u1)
db.session.add(u2)
db.session.add(c1)
db.session.add(c2)
db.session.commit()

db.session.close()