Esempio n. 1
0
def profile():
    """
    Function to edit and retrieve user profile information
    """
    current_user = get_jwt_identity()
    user = User.query.filter_by(email=current_user).first()
    if request.method == 'GET':
        return jsonify({"username": user.email, "bio": user.bio, "first_name": user.first_name,
                        "last_name": user.last_name, "email": user.email,
                        "image": user.image, "id": user.id}), 200
    elif request.method == "POST":
        data = request.get_json()
        # print(data['image'])
        user.update_bio(data['bio'])
        user.update_first_name(data['first_name'])
        user.update_last_name(data['last_name'])
        if data['email'] != user.email:
            print('email changed')
            timestamp = datetime.datetime.now()
            timestamp = timestamp.strftime("%d %H")
            md5_digest = hashlib.md5(timestamp.encode()).hexdigest()
            user.update_activation_code(md5_digest)
            confirmation_email(user.email, md5_digest)
            user.update_email(data['email'])

        db.session.merge(user)
        db.session.commit()
        return jsonify({"msg": "User information changed"}), 200
    else:
        return jsonify({"msg": "profile OK"}), 200
Esempio n. 2
0
def confirmation_token():
    """Sending confirmation token again"""
    jobj = request.get_json()
    timestamp = datetime.datetime.now()
    timestamp = timestamp.strftime("%d %H")
    md5_digest = hashlib.md5(timestamp.encode()).hexdigest()
    user = User.query.filter_by(email=jobj['email']).first()
    user.update_activation_code(md5_digest)
    confirmation_email(user.email, md5_digest)
    db.session.merge(user)
    db.session.commit()
    return jsonify({"msg": "User confirmation token sent"}), 200
Esempio n. 3
0
def confirmation_token():
    """Sending confirmation token again"""
    jobj = request.get_json()
    timestamp = datetime.datetime.now()
    timestamp = timestamp.strftime("%d %H:%M:%S")
    md5_digest = hashlib.md5(timestamp.encode()).hexdigest()
    user = User.query.filter_by(email=jobj["email"]).first()
    user.update_activation_code(md5_digest)
    confirmation_email(user.email, md5_digest)
    # updating user groups here
    user_ = UserGroups(user_id=user.id, group_id=2)
    db.session.merge(user)
    db.session.add(user_)
    db.session.commit()
    return jsonify({"msg": "User confirmation token sent"}), 200
Esempio n. 4
0
def signupfunc():
    """Registering user and checking for already existing user"""
    register_obj = request.get_json()
    check_user = User.query.filter_by(email=register_obj["email"]).first()
    if check_user is None:
        user = User(username=register_obj["email"], email=register_obj["email"])
        user.set_password(register_obj["password"])
        user.set_session_hash()
        user.ip_address = request.remote_addr
        user.activation_selector = None
        user.activation_code = "0000"
        user.forgotten_password_selector = None
        user.forgotten_password_code = "0000"
        user.forgotten_password_time = "0000"
        user.remember_selector = None
        user.remember_code = "0000"
        user.created_on = "0000"
        user.last_login = "******"
        user.active = "0"
        user.first_name = register_obj["first_name"]
        user.last_name = register_obj["last_name"]
        user.company = "0000"
        user.phone = "0000"
        user.country = "0000"
        user.image = "0000"
        user.bio = "No Bio"
        user.core = "0000"
        user.external_source = "0000"
        user.external_id = "0000"
        user.password_hash = "0000"
        timestamp = datetime.datetime.now()
        timestamp = timestamp.strftime("%d %H:%M:%S")
        md5_digest = hashlib.md5(timestamp.encode()).hexdigest()
        user.update_activation_code(md5_digest)
        confirmation_email(user.email, md5_digest)
        db.session.add(user)
        # db.session.commit()
        # user_ = User.query.filter_by(email=register_obj["email"]).first()
        db.session.commit()

        return jsonify({"msg": "User created"}), 200
    else:
        return jsonify({"msg": "User already exists"}), 200