Beispiel #1
0
def sign_up():
    if current_user.is_authenticated:
        return current_user.to_dict()
    form = SignUpForm(csrf_token=request.headers["x-Csrftoken"])
    if form.validate_on_submit():
        data = request.json
        user = User(
            firstname=data["firstname"],
            lastname=data["lastname"],
            username=data["username"],
            email=data["email"],
            password=data["password"],
        )
        watchlist = UserList(userId=user.id, listName="Watch List")
        db.session.add(user)
        db.session.commit()

        newUser = User.query.filter(
            User.email == user.to_dict()["email"]).first()
        login_user(newUser)

        watchlist = UserList(userId=newUser.id, listName="Watch List")
        db.session.add(watchlist)
        db.session.commit()
        return user.to_dict()
    return form.errors, 401
Beispiel #2
0
def index():
  if not request.is_json:
    return jsonify(msg="Missing JSON in request"), 400

  email = request.json.get("email")
  if not email:
    return jsonify(msg="Missing email"), 400
  
  password = request.json.get("password")
  if not password:
    return jsonify(msg="Missing password"), 400
  
  # LOGIN
  if request.method == 'PUT':
    user = User.query.filter(User.email == email).first()
    if not user or not user.check_password(password):
      return jsonify(msg="Bad email/password combination."), 401

  # SIGN UP
  elif request.method =="POST":
    username = request.json.get("username")
    if not username:
      return jsonify(msg="Missing username"), 400
    user = User(username=username, email=email, password=password)
    user.follow(user)

  # CREATE AND ASSIGN SESSION TOKEN IN DB
  access_token = create_access_token(identity=user.email)
  user.session_token = access_token
  db.session.add(user)
  db.session.commit()
  return jsonify(token=access_token, id=user.id, username=user.username, display_name=user.display_name), 200
Beispiel #3
0
def createUser():
    email, password, firstName, lastName = request.json.values()
    user = User(email=email,
                password=password,
                first_name=firstName,
                last_name=lastName)
    db.session.add(user)
    db.session.commit()
    login_user(user)
    return {"current_user_id": current_user.id}
Beispiel #4
0
def new_user():
    sign_up_form = SignUpForm()
    if sign_up_form.validate():
        data = request.get_json()
        new_user = User(username=data["username"],
                        email=data["email"],
                        password=data["password"])
        db.session.add(new_user)
        db.session.commit()
    else:
        return jsonify(success=False, errors=sign_up_form.errors), 400
    return jsonify('ok')
def signup():
    if not request.is_json:
        return jsonify({"msg": "Missing JSON in request"}), 400
    email = request.json.get("email", None)
    user = User.query.filter(User.email == email).first()
    if user:
        return jsonify(
            {"errors":
             "The email you've entered has been already registered"}), 400
    name = request.json.get("name", None)
    password = request.json.get("password", None)
    city = request.json.get("city", None)
    state = request.json.get("state", None)
    points = request.json.get("points", None)
    newUser = User(name=name,
                   email=email,
                   password=password,
                   city=city,
                   state=state,
                   points=points)
    db.session.add(newUser)
    db.session.commit()
    login_user(newUser)
    return {"user": newUser.to_dict()}
Beispiel #6
0
def login():
    if not request.is_json:
        return jsonify({"msg": "Missing JSON in request"}), 400

    username = request.json.get('username', None)
    password = request.json.get('password', None)

    if not username or not password:
        return {"errors": ["Missing required parameters"]}, 400

    access_token, user = User.authenticate(username, password)
    if access_token:
        return {"access_token": access_token}, 200

    return {"errors": ["Invalid username or password"]}, 401
def new_user():
    sign_up_form = SignUpForm()
    if sign_up_form.validate():
        print("aidhfakdsflksj")
        data = request.get_json()
        new_user = User(username=data["username"],
                        email=data["email"],
                        password=data["password"])
        db.session.add(new_user)
        db.session.commit()
    else:
        # errors = [value for (key, value) in sign_up_form.errors.items]
        print(sign_up_form.errors)
        return jsonify(success=False, errors=sign_up_form.errors), 400
    return jsonify('ok')
Beispiel #8
0
def login():
    if not request.is_json:
        return jsonify({"msg": "Missing JSON in request"}), 400

    email = request.json.get('email', None)
    password = request.json.get('password', None)

    if not email or not password:
        return {"errors": ["Missing required parameters"]}, 400

    authenticated, user = User.authenticate(email, password)
    # print(authenticated)
    # print(user)
    if authenticated:
        login_user(user)
        return {"current_user_id": current_user.id}

    return {"errors": ["Invalid email or password"]}, 401
Beispiel #9
0
def login():
    if not request.is_json:
        return jsonify({"msg": "Missing JSON in request"}), 400

    username = request.json.get('username', None)
    password = request.json.get('password', None)

    if not username or not password:
        return {"errors": ["Missing required parameters"]}, 400

    authenticated, user = User.authenticate(username, password)
    print(authenticated)
    print(user)
    if authenticated:
        login_user(user)
        return {
            "current_user_id": current_user.id,
            "current_username": username
        }, 200

    return {"errors": ["Invalid username or password"]}, 401
Beispiel #10
0
from dotenv import load_dotenv
# from starter_app.models import User, Restaurant, Reservation, Review ,favorites
from starter_app.models import User, Restaurant, Reservation, Review, Favorite
from starter_app import app, db
from datetime import date

load_dotenv()

with app.app_context():
    db.drop_all()
    db.create_all()
    ian = User(name='Ian',
               email='*****@*****.**',
               city='Philadelphia',
               state="PA",
               password='******',
               points=300)
    javier = User(name='Javier',
                  email='*****@*****.**',
                  city='Las Vegas',
                  state="NV",
                  password='******',
                  points=400)
    dean = User(name='Dean',
                email='*****@*****.**',
                city='Boise',
                state="ID",
                password='******',
                points=500)
    angela = User(name='Angela',
                  email='*****@*****.**',
Beispiel #11
0
from dotenv import load_dotenv
load_dotenv()

from starter_app import app, db
from starter_app.models import User, City, Landlord, Review

with app.app_context():
    db.drop_all()
    db.create_all()

    #Users
    ian = User(username='******',
               email='*****@*****.**',
               password='******',
               city_id=1)
    javier = User(username='******',
                  email='*****@*****.**',
                  password='******',
                  city_id=2)
    dean = User(username='******',
                email='*****@*****.**',
                password='******',
                city_id=3)
    angela = User(username='******',
                  email='*****@*****.**',
                  password='******',
                  city_id=1)
    soonmi = User(username='******',
                  email='*****@*****.**',
                  password='******',
                  city_id=2)
Beispiel #12
0
import datetime
from starter_app.models import User, Post, Comment, Social
from starter_app import app, db
from dotenv import load_dotenv
load_dotenv()


with app.app_context():
    db.drop_all()
    db.create_all()

    ian = User(username='******', email='*****@*****.**', password='******')
    javier = User(username='******', email='*****@*****.**', password='******')
    dean = User(username='******', email='*****@*****.**', password='******')
    angela = User(username='******', email='*****@*****.**', password='******')
    soonmi = User(username='******', email='*****@*****.**',
                  password='******')
    alissa = User(username='******', email='*****@*****.**', password='******')
    demo = User(username='******', email='*****@*****.**', password='******')

    post1 = Post(
        image_url='https://i.pinimg.com/originals/58/44/28/5844285eddc375e333bc5e02227e893f.jpg',
        user_id=1, date=datetime.datetime.now(), desc='this is a test bud')


    comment1 = Comment(
        content="This must be a joke, totally repulsive.",
        user_id=3, post_id=1)

    social1 = Social(user=1, following=5)
    social2 = Social(user=1, following=4)
Beispiel #13
0
SEED_USERS_PASSWORD = os.environ.get('SEED_USERS_PASSWORD')

with app.app_context():
    db.drop_all()
    db.create_all()

    tags = [
        'Animation', 'Art', 'Comics', 'Drawing & Painting', 'Food & Drink',
        'Gaming', 'Music', 'Other', 'Photography', 'Podcast', 'Science & Tech',
        'Social', 'Software', 'Streaming', 'Video & Film', 'Writing'
    ]
    for tag in tags:
        db.session.add(Tag(tag_name=tag))

    captain = User(username='******',
                   email='*****@*****.**',
                   password='******',
                   bio="a loud cat that gallops around the house at 3am")
    luna = User(username='******',
                email='*****@*****.**',
                password=SEED_USERS_PASSWORD,
                bio="I'm a small cat!!!",
                accept_payments=True,
                display_name="mewna")
    cath = User(display_name="Cath",
                username='******',
                email='*****@*****.**',
                bio=':-D',
                password=SEED_USERS_PASSWORD)
    bobo = User(username='******',
                display_name="Bobo",
                bio="fighting gamer",
Beispiel #14
0
    Recommendation,
)
from starter_app import app, db
from dotenv import load_dotenv

load_dotenv()

with app.app_context():
    db.drop_all()
    db.create_all()

    seeder = [
        User(
            username="******",
            firstname="demo",
            lastname="user",
            email="*****@*****.**",
            password="******",
            cash=1000,
        ),
        User(
            username="******",
            firstname="second",
            lastname="person",
            email="*****@*****.**",
            password="******",
        ),
        User(
            username="******",
            firstname="money",
            lastname="user",
            password="******",