コード例 #1
0
def signup():
    if current_user.is_authenticated:
        # Already Logged In
        return redirect(url_for('index'))

    form = SignupForm()
    if form.validate_on_submit():
        # Get all data from html
        username = request.form.get("username")
        address = request.form.get("address")
        email = request.form.get("email")
        password = request.form.get("password")

        user = User.query.filter_by(email=email).first()
        if user:
            flash("User Already Exist")
        else:
            new_user = User(username, address, password, email)
            # Assign role
            role = Role.query.filter_by(name="User").first()
            if not role:
                role = Role(name='User')
            new_user.role = [
                role,
            ]

            db.session.add(new_user)
            db.session.commit()
            return redirect(url_for('login'))
    return render_template("signup.html", form=form)
コード例 #2
0
    def testUserTable(self):
        assert 0 == len(User.query.all())

        user1 = User("user1", "*****@*****.**")
        db.add(user1)
        db.commit()
        assert 1 == len(User.query.all())

        user2 = User("user2", "*****@*****.**")
        db.add(user2)
        db.commit()
        assert 2 == len(User.query.all())
コード例 #3
0
ファイル: app.py プロジェクト: nickchow2020/Flask-Feedback
def login():
    form = Login()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data

        user = User.authenticate(username, password)
        if user:
            session['username'] = user.username
            return redirect(f"/user/{user.username}")
        else:
            form.username.errors = [
                "Please Provide a valid Username or Password"
            ]

    return render_template("login.html", form=form)
コード例 #4
0
def signup():
    print request.get_json()
    params = request.get_json()['creds']
    try:
        data = User.objects.get(username=params['username'])
        return jsonify({'status': False})
    except DoesNotExist:

        hashed_pass = bcrypt.hashpw(str(params['password']), bcrypt.gensalt())
        user_obj = User(username=params['username'])
        user_obj.set_password(params['password'])
        user_obj.save()
        return jsonify({'status': True})
コード例 #5
0
ファイル: app.py プロジェクト: nickchow2020/Flask-Feedback
def register():
    form = Register()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        email = form.email.data
        first_name = form.first_name.data
        last_name = form.last_name.data

        new_user = User.register(username=username,
                                 password=password,
                                 email=email,
                                 first=first_name,
                                 last=last_name)

        db.session.add(new_user)
        db.session.commit()
        session['username'] = new_user.username
        return redirect('/secret')

    return render_template("register.html", form=form)
コード例 #6
0
ファイル: app.py プロジェクト: Remedious-RUHacks/remedious
def signup():
    if current_user.is_authenticated:
        # Already Logged In
        return {"Error": "Already LoggedIn"}

    # Get all data from html
    firstname = request.form.get("firstname")
    lastname = request.form.get("lastname")
    email = request.form.get("email")
    password = request.form.get("password")

    user = User.query.filter_by(email=email).first()

    if user:
        return {"Error": "User Already Exist"}
    else:
        new_user = User(firstname, lastname, password, email)

        db.session.add(new_user)
        db.session.commit()
        return {
            "Success": f"Account Succesfull Created for {new_user.firstname}"
        }
    return {"Error": "Error Occured!"}
コード例 #7
0
ファイル: seed.py プロジェクト: nickchow2020/Flask-Feedback
from modals import Feedbacks,db,User
from app import app

db.drop_all()
db.create_all()


user1 = User.register(
    username="******",
    password="******",
    email="*****@*****.**",
    first="Nick",
    last="Zhou")

user2 = User.register(
    username="******",
    password="******",
    email="*****@*****.**",
    first="Stephen",
    last="Zhou")


db.session.add(user1)
db.session.add(user2)
db.session.commit()


tweet1 = Feedbacks(title="Hello,World",content="I Love You",username="******")
tweet2 = Feedbacks(title="Thank Your,World",content="I Love You",username="******")
tweet3 = Feedbacks(title="Okay,World",content="I Love You",username="******")
tweet4 = Feedbacks(title="Lucky,World",content="I Love You",username="******")
コード例 #8
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from modals import Category, db, User, ItemField, MobileItem

engine = create_engine('sqlite:///app.db', echo=True)
db.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
sess = DBSession()

db.metadata.drop_all()
db.metadata.create_all(engine)

# adding users
user1 = User("user1", "*****@*****.**")
sess.add(user1)
sess.commit()
user2 = User("user2", "*****@*****.**")
sess.add(user2)
sess.commit()

# adding categories
nokia = Category("Nokia")
sess.add(nokia)
mx = Category("Micromax")
sess.add(mx)
sony = Category("Sony")
sess.add(sony)
krbm = Category("Karbonn")
sess.add(krbm)
sess.commit()