Example #1
0
def refresh():
    user = get_jwt_identity()
    access_token = create_access_token(identity=user,
                                       fresh=False,
                                       expires_delta=timedelta(seconds=900))
    access_jti = get_jti(encoded_token=access_token)
    jwt_revoked_store.set(access_jti, 'false', ACCESS_EXPIRES * 1.2)
    return jsonify(access_token=access_token), 201
Example #2
0
def login():
    data = request.get_json()
    email = data['email']
    password = data['password']
    user = User.authenticate(email, password)
    if user:
        access_token = create_access_token(
            user.id, fresh=True, expires_delta=timedelta(seconds=900))
        refresh_token = create_refresh_token(user.id)
        access_jti = get_jti(encoded_token=access_token)
        refresh_jti = get_jti(encoded_token=refresh_token)
        jwt_revoked_store.set(access_jti, 'false', ACCESS_EXPIRES * 1.2)
        jwt_revoked_store.set(refresh_jti, 'false', REFRESH_EXPIRES * 1.2)
        return jsonify(error=False,
                       access_token=access_token,
                       refresh_token=refresh_token), 201
    else:
        return jsonify(error=True, message="Invalid Details."), 401
Example #3
0
def register():
    data = request.get_json()
    f_name = data['f_name']
    s_name = data['s_name']
    email = data['email'].lower()
    password = data['password']
    domain = data['domain'].lower()

    if not re.fullmatch(r'[^@]+@[^@]+\.[^@]+', email) or \
      len(password) < 8 or \
      len(password) > 25 or \
      not f_name.isalnum() or \
      not s_name.isalnum() or \
      not re.search(r'\d+', password) or \
      not re.search(r'[A-Z]+', password):
        return jsonify(error=True,
                       message='Invalid Details. Please Try again'), 400
    if not domain.isalnum():
        return jsonify(
            error=True,
            message='Your domain can only contain letters and numbers!'), 400

    user = User.query.filter_by(domain=domain).first()
    if user is None:
        users = User.query.all()
        if len(users) < 25:
            user = User(domain=domain,
                        email=email,
                        f_name=f_name,
                        s_name=s_name,
                        password=generate_password_hash(password),
                        account_type=4)
            user.add()

            user = User.query.filter_by(domain=domain).first()
            mailer = MailService(
                current_app,
                ('Fareed From Kreoh', current_app.config['MAIL_USERNAME']),
                user.id)
            mailer.send_welcome_message()

            access_token = create_access_token(
                user.id, fresh=True, expires_delta=timedelta(seconds=900))
            refresh_token = create_refresh_token(user.id)

            access_jti = get_jti(encoded_token=access_token)
            refresh_jti = get_jti(encoded_token=refresh_token)
            jwt_revoked_store.set(access_jti, 'false', ACCESS_EXPIRES * 1.2)
            jwt_revoked_store.set(refresh_jti, 'false', REFRESH_EXPIRES * 1.2)

            return jsonify(error=False,
                           access_token=access_token,
                           refresh_token=refresh_token), 201
        else:
            return jsonify(
                error=True,
                message=
                "You've just missed out! The early access is currently full!"
            ), 400
    else:
        return jsonify(error=True, message="unable to create user"), 400
Example #4
0
def logout_refresh():
    jti = get_raw_jwt()['jti']
    jwt_revoked_store.set(jti, 'true', REFRESH_EXPIRES * 1.2)
    return jsonify(error=False, message='Refresh JWT revoked'), 200
Example #5
0
def logout():
    jti = get_raw_jwt()['jti']
    jwt_revoked_store.set(jti, 'true', ACCESS_EXPIRES * 1.2)
    return jsonify(error=False, message='Access JWT revoked'), 200