示例#1
0
def _deprovision_hook(request):
    # Process the deprovisiong from the AA.
    if request.method == "POST":
        hook_json = json.loads(request.body)
        # Check for a hook key for authentication
        if 'key' in hook_json.keys(
        ) and hook_json['key'] == settings.SHIBBOLETH_HOOK_KEY:
            # If the action was attribute_change update the user in keystone
            # based on the data received
            if hook_json['action'] == 'attribute_change':
                for eppn in hook_json['data']:
                    entitlement = None
                    for attribute in hook_json['data'][eppn]:
                        if attribute == settings.SHIBBOLETH_ENTITLEMENT_ID:
                            for attr_value in hook_json['data'][eppn][
                                    attribute]:
                                if entitlement is None:
                                    entitlement = attr_value
                                else:
                                    entitlement += ';' + attr_value
                    username = utils.update_user(username=eppn,
                                                 entitlement=entitlement)
                return HttpResponse(username)
            # If the action was user_removed delete the user from all project
            # in keystone, but keep the user.
            if hook_json['action'] == 'user_removed':
                for eppn in hook_json['data']:
                    username = utils.update_user(username=eppn,
                                                 entitlement=None)
                return HttpResponse(username)
示例#2
0
def _deprovision_hook(request):

    if request.method == "POST":
        hook_json = json.loads(request.body)
        if 'key' in hook_json.keys(
        ) and hook_json['key'] == settings.SHIBBOLETH_HOOK_KEY:
            if hook_json['action'] == 'attribute_change':
                for eppn in hook_json['data']:
                    entitlement = None
                    for attribute in hook_json['data'][eppn]:
                        if attribute == settings.SHIBBOLETH_ENTITLEMENT_ID:
                            for attr_value in hook_json['data'][eppn][
                                    attribute]:
                                if entitlement is None:
                                    entitlement = attr_value
                                else:
                                    entitlement += ';' + attr_value
                    username = utils.update_user(username=eppn,
                                                 entitlement=entitlement)
                return HttpResponse(username)
            if hook_json['action'] == 'user_removed':
                for eppn in hook_json['data']:
                    username = utils.update_user(username=eppn,
                                                 entitlement=None)
                return HttpResponse(username)
示例#3
0
def pay_handler():
    if request.method =='POST':
        data = request_form_to_dict()
        pid = int(data.get("pid"))
        count = int(data.get("amount"))
        period=Period.get(id=pid)
        time_now=datetime.now()
        left=period.total_count-period.join_count
        if left >= count:
            num = get_num(pid, count)
            # 创建或更新夺宝订单明细记录
            create_or_update_order_detail(current_user.id, pid, {
                "count": count,
                "created_datetime": time_now,
                "num": num
            })
            # 更新用户余额
            update_user(current_user.id, current_user.balance - count)
            if left == count:
                kj_time = get_kj_time(time_now)
                update_period(pid, {
                     "join_count": period.join_count + count,
                     "status": 1,
                     "end_time": time_now,
                     "kj_count": create_kj_count(time_now),
                     "kj_time": kj_time,
                })
                create_period(period.product.id, period.total_count,  period.number+ 1)
            else:
                update_period(pid,{
                    "join_count": period.join_count + count,
                    })
            return redirect(url_for('period_detail',pid=pid))
示例#4
0
文件: app.py 项目: cwbjr/DandD
def editaccount():
    if request.method == 'GET':
        if 'user' in session and session['user']:
            return render_template("editaccount.html")
        else:
            return redirect("/login/redirect")
    else:
        form = request.form.copy().to_dict()
        username = session['user']
        newusername = form['newUsername'] or ""
        newpassword = form['newPassword'] or ""
        oldpassword = form['oldPassword']

        if form['newUsername'] and form['newPassword']:
            if utils.update_user(username,newusername,oldpassword):
                if utils.update_pw(newusername,oldpassword,newpassword):
                    return 'bothSuccess'
            return 'fail'

        if form['newUsername']:
            if utils.update_user(username,newusername,oldpassword):
                return 'userSucess'
            return 'fail'

        if form['newPassword']:
            if utils.update_pw(username,oldpassword,newpassword):
                return 'pwSuccess'
            return 'fail'
        return 'fail'
示例#5
0
def logout():
    session.pop('logged_in', None)

    user = db.users.find_one({'email': session['email']}, {"_id": False})

    update_user(user['email'], {'logged_in': False}, db)

    flash("You have been logged out")
    return redirect('home')
示例#6
0
def logout():
    session.pop('logged_in', None)

    user = db.users.find_one( { 'email' : session['email'] } , { "_id" : False } )

    update_user(user['email'], {'logged_in': False}, db)

    flash("You have been logged out")
    return redirect('home')
示例#7
0
def _update_user(request):
    pw = None
    eppn, entitlement, email = _get_attrs(request)
    next_page = request.GET.get('return', '/')
    if request.method == "POST":
        pw = request.POST.get('password')
    utils.update_user(username=eppn,
                      entitlement=entitlement,
                      mail=email,
                      password=pw)
    # redirect to the Shibboleth HOOK return url.
    return redirect(next_page)
def _update_user(request):
    next_page = request.GET.get('return', '/')
    eppn = request.META.get(settings.SHIBBOLETH_NAME_ATTRIBUTE, None)
    if not eppn:
        logger.error("Name attribute is missing!")
        raise Exception("Missing name attribute.")

    entitlement = request.META.get(settings.SHIBBOLETH_ENTITLEMENT_ATTRIBUTE, None)
    if entitlement is not None:
        username = utils.update_user(request)

    #redirect to the Shibboleth HOOK return url.
    return redirect(next_page)
示例#9
0
def user_detail(request, pk):
    """

    **Get or change the user profile data- Ignore**

    > GET

    Returns the User Profile data.

    * Requires `user id` which is an integer and taken as primary key
    to identify user.

    * Possible HTTP status codes and JSON response:

        * `HTTP_200_OK` - Returns the User Profile data:

                {
                  "email": String,
                  "id": Integer,
                  "first_name": String,
                  "last_name": String,
                  "created": String,
                  "contact_no": Integer
                }

        * `HTTP_500_INTERNAL_SERVER_ERROR` - Internal server error



    > PUT

    ### Update User Profile Data

    * Requires data that needs to be changed. Any and all of the below fields
    could be modified in a single PUT request.

        1. `first_name`: String
        2. `last_name`: String
        3. `contact_no`: Integer
        4. `email` : String


    * Requires only the changed data of the user and `email` along the changed
    parameters.

    * Possible HTTP status codes and JSON response:

        * `HTTP_200_OK` - User profile data in JSON format:

                {
                  "email": String,
                  "id": Integer,
                  "first_name": String,
                  "last_name": String,
                  "created": String,
                  "contact_no": Integer
                }

        * `HTTP_500_INTERNAL_SERVER_ERROR`

        :param pk:
        :param request:
    """
    data = request.data
    try:
        user = validations_utils.user_validation(
            pk)  # Validates if user exists or not.
        # validations_utils.user_token_validation(request.auth.user_id, pk)  # Validates user's Token authentication.
    except ValidationException as e:  # Generic exception
        return Response(e.errors, status=e.status)
    if request.method == 'GET':
        fire_base = firebase.FirebaseApplication(
            'https://userfirebase-1e188.firebaseio.com/', None)
        result = fire_base.get('/users', None)

        user_profile_serializer = UserProfileSerializer(user)
        return Response(user_profile_serializer.data,
                        status=status.HTTP_200_OK)
    elif request.method == 'PUT':
        try:
            data = validations_utils.email_validation(
                data
            )  # Validates email id, it returns lower-cased email in data.
            updated_data = utils.update_user(data, user)  # Updates user data.
            return Response(updated_data, status=status.HTTP_200_OK)
        except ValidationException as e:  # Generic exception
            return Response(e.errors, status=e.status)