Пример #1
0
def login():
    post_body = json.loads(request.data)
    email = post_body.get('email')
    password = post_body.get('password')

    if email is None or password is None:
        return json.dumps({'success': False, 'error': 'Invalid email or password'}), 400

    check= users_dao.get_user_by_email(email)
    if check is None :
        if not(isValidEmail(email)) :
            return json.dumps({'success': False, 'error': 'Wrong email format'}), 400
        
        created, user = users_dao.create_user(email, password)

        if not created:
            return json.dumps({'success': False, 'error': 'User already exists'}), 409

        return json.dumps({
            'success': True,
            'user': [user.serialize()],
        }), 201

    else: 
        success, user = users_dao.verify_credentials(email, password)

        if not success:
            return json.dumps({'success': False, 'error': 'Incorrect email or password'}), 400
        
        return json.dumps({
            'success': True,
            'user': [user.serialize()],
        }), 200
Пример #2
0
def register_account():
    try:
        post_body = json.loads(request.data)
        token = post_body['id_token']

        idinfo = id_token.verify_oauth2_token(
            token, requests.Request(),
            "828234084029-ci87jss5vnr5a8t9nnsaqvv5evurfegf.apps.googleusercontent.com"
        )
        if idinfo['iss'] not in [
                'accounts.google.com', 'https://accounts.google.com'
        ]:
            raise ValueError('Wrong issuer.')

        # return json.dumps(idinfo)
        userid = idinfo['sub']
        email = idinfo['email']

        created, user = users_dao.create_user(email, userid)

        if email is None or userid is None:
            return json.dumps({'error': 'Invalid email or password'})

        if not created:
            return json.dumps({'error': 'User already exists.'})

        return json.dumps({
            'session_token': user.session_token,
            'session_expiration': str(user.session_expiration),
            'update_token': user.update_token
        })

    except ValueError:
        # return json.dumps({'error': 'Invalid user id'})
        raise ValueError('Invalid Token')
Пример #3
0
def register_account():
    post_body = json.loads(request.data)
    email = post_body.get('email')
    password = post_body.get('password')

    if email is None or password is None:
        return json.dumps({'error': 'Invalid email or password'})

    created, user = users_dao.create_user(email, password)
    if not created:
        return json.dumps({'error': 'User already exists'})
    return json.dumps({
        'session_token': user.session_token,
        'session_expiration': str(user.session_expiration),
        'update_token': user.update_token
    })
Пример #4
0
def sign_in():
    body = json.loads(request.data)
    id_token = body.get('id_token')
    try:
        id_info = id_token.verify_oauth2_token(id_token, requests.Request(),
                                               client_id)
        username = id_info['sub']
        user = users_dao.create_user(username)
        data = json.dumps({
            "session_token": user.session_token,
            "session_expiration": str(user.session_expiration),
            "update_token": user.update_token
        })
        return success_response(data, 201)
    except Exception:
        return failure_response("User invalid")
Пример #5
0
def signup():
    body = json.loads(request.data)
    username = body.get("username")
    password = body.get("password")

    if username is None or password is None:
        return failure_response("Invalid username or password")

    was_created, user = users_dao.create_user(username, password)
    if not was_created:
        return failure_response("User already exists")

    return success_response({
        "id": user.id,
        "session_token": user.session_token,
        "session_expiration": str(user.session_expiration),
        "update_token": user.update_token,
    })
Пример #6
0
def register_account():
    body = json.loads(request.data)
    name = body.get("name")
    username = body.get("username")
    email = body.get("email")
    password = body.get("password")

    if name is None or username is None or email is None or password is None:
        return json.dumps({"error": "Invalid name, username, email or password."})
    
    created, user = users_dao.create_user(name, username, email, password)
    if not created:
        return json.dumps({"error": "User already exists."})

    return json.dumps({
        "session_token": user.session_token,
        "session_expiration": str(user.session_expiration),
        "update_token": user.update_token,
    })
Пример #7
0
def register_account():
    post_body = json.loads(request.data)
    name = post_body.get('name')
    email = post_body.get('email')
    if email[-11:] != 'cornell.edu':
        return json.dumps({'success': False, 'error': 'Invalid email domain'})
    password = post_body.get('password')
    if not name or not email or not password:
        return json.dumps({
            'success': False,
            'error': 'Missing name, email, or password'
        })
    created, user = users_dao.create_user(name, email, password)
    if not created:
        return json.dumps({'success': False, 'error': 'User already exists'})
    return json.dumps({
        'session_token': user.session_token,
        'session_expiration': str(user.session_expiration),
        'update_token': user.update_token
    })
Пример #8
0
def register_account():
    body = json.loads(request.data)
    email = body.get("email")
    password = body.get("password")
    name = body.get("name")

    if email is None or password is None or name is None:
        return json.dumps({"error": "Invalid email or password"})

    was_created, user = users_dao.create_user(email, password, name)

    if not was_created:
        return json.dumps({"error": "User already exists"})

    return json.dumps({
        "session_token": user.session_token,
        "session_expiration": str(user.session_expiration),
        "update_token": user.update_token,
        "id": user.id
    })
Пример #9
0
def register_account():
    body = json.loads(request.data)
    first_name = body.get("first_name")
    last_name = body.get("last_name")
    username = body.get("username")
    phone_number = body.get("phone_number")
    email = body.get("email")
    password = body.get("password")

    if first_name is None or last_name is None or username is None or phone_number is None or email is None or password is None:
        return json.dumps({"error": "Invalid input."})
    created, user = users_dao.create_user(first_name, last_name, username,
                                          phone_number, email, password)
    if not created:
        return json.dumps({"error": "User already exists."})
    return json.dumps({
        "session_token": user.session_token,
        "session_expiration": str(user.session_expiration),
        "update_token": user.update_token,
    })
Пример #10
0
def register_account():
    post_body = json.loads(request.data)
    email = post_body.get('email')
    password = post_body.get('password')
    first_name = post_body.get('first_name')
    last_name = post_body.get('last_name')

    if not email or not password:
        return json.dumps({'error': 'missing email or password.'})

    created, user = users_dao.create_user(email, password, first_name,
                                          last_name)

    if not created:
        return json.dumps({'error': 'User already exists.'})

    return json.dumps({
        'session_token': user.session_token,
        'session_expiration': str(user.session_expiration),
        'update_token': user.update_token
    })
Пример #11
0
def register_account():
    body = json.loads(request.data)
    email = body.get("email")
    password = body.get("password")
    user_id = body.get("user_id")
    device_id = body.get("device_id")
    device_type = body.get("device_type")
    if email is None or password is None:
        return failure_response("Invalid email or password")
    if user_id is None or device_id is None or device_type is None:
        return json.dumps(
            {"error": "Need to supply user_id, device_id, and device_type."})
    created, user = users_dao.create_user(email, password, user_id, device_id,
                                          device_type)
    if not created:
        return failure_response("User already exists.")
    return json.dumps({
        "session_token": user.session_token,
        "session_expiration": str(user.session_expiration),
        "update_token": user.update_token,
    })
Пример #12
0
def create_user():
    """ Create a new user. """
    try:
        body = json.loads(request.data)
        email = body.get('email')
        password = body.get('password')
        name = body.get('name')
        phone_num = body.get('phone_num')
    except KeyError:
        return json.dumps({
            'success': False,
            'error': 'No json provided!'
        }), 400

    if email is None or password is None:
        return json.dumps({'error': 'Invalid email or password'})

    created, user = users_dao.create_user(name, phone_num, email, password)

    if not created:
        return json.dumps({'error': 'User already exists'})

    return json.dumps({'success': True, 'data': user.serialize()}), 201