Example #1
0
def change_password(request):
    if 'logged' not in request.session:
        return HTTPFound(location='/signin')

    if request.is_xhr:

        csrf_token = request.params['csrf_token']
        is_token = (csrf_token == unicode(request.session.get_csrf_token()))

        if is_token:

            admin = AdminModel(request)

            id = ObjectId(request.params['id'])
            password = request.params['password']

            try:
                admin.change_password(id, password)
                return {'ok': 1}
            except Exception as e:
                return {'ok': 0, 'msg': e.message}
        else:
            return {'ok': 0, 'msg': 'Not authorized.'}
    else:
        return {'ok': 0, 'msg': 'Not ajax request'}
Example #2
0
def change_password(request):
    if 'logged' not in request.session:
        return HTTPFound(location='/signin')

    if request.is_xhr:

        csrf_token = request.params['csrf_token']
        is_token = (csrf_token == unicode(request.session.get_csrf_token()))

        if is_token:

            admin = AdminModel(request)

            id = ObjectId(request.params['id'])
            password = request.params['password']

            try:
                admin.change_password(id, password)
                return {'ok': 1}
            except Exception as e:
                return {'ok': 0, 'msg': e.message}
        else:
            return {'ok': 0, 'msg': 'Not authorized.'}
    else:
        return {'ok': 0, 'msg': 'Not ajax request'}
Example #3
0
def app_change_password(request):
    admin = AdminModel(request)

    id = request.session['id']
    password = request.params['password']

    try:
        admin.change_password(ObjectId(id), password)
        return {'ok': 1}
    except Exception as e:
        return {'ok': 0, 'msg': e.message}
Example #4
0
def app_change_password(request):
    admin = AdminModel(request)

    id = request.session['id']
    password = request.params['password']

    try:
        admin.change_password(ObjectId(id), password)
        return {'ok': 1}
    except Exception as e:
        return {'ok': 0, 'msg': e.message}
Example #5
0
def save_view(request):
    if 'logged' not in request.session:
        return HTTPFound(location='/signin')

    if request.session['user_type'] != '1':
        return {'ok': 0, 'msg': 'Not admin.'}
    else:

        data = {
            'fullname': request.params['fullname'],
            'cid': request.params['cid'],
            'hospcode': request.params['department'],
            'username': request.params['username'],
            'password': request.params['password'],
            'user_type': request.params['user_type'],
            'user_status': request.params['user_status'],
            'position': request.params['position']
        }

        admin = AdminModel(request)

        id = request.params["id"] if 'id' in request.params else False

        if not id:

            is_duplicate = admin.check_duplicate(request.params['username'])

            if is_duplicate:
                return {'ok': 0, 'msg': 'ชื่อผู้ใช้งานนี้ถูกใช้แล้ว กรุณาเลือกใหม่'}
            else:
                rs = admin.save(data)

                if rs:
                    return {'ok': 1}
                else:
                    return {'ok': 0, 'msg': 'ไม่สามารถบันทึกรายการได้'}

        else:
            data['id'] = ObjectId(request.params['id'])
            admin.update(data)

            return {'ok': 1}
Example #6
0
def get_user_list(request):
    if 'logged' not in request.session:
        return HTTPFound(location='/signin')
    else:
        if request.is_xhr:  # is ajax request
            start = request.params['start'] if 'start' in request.params else 0
            stop = request.params['stop'] if 'stop' in request.params else 25

            limit = int(stop) - int(start)

            admin = AdminModel(request)

            rs = admin.get_user_list(int(start), int(limit))

            rows = []
            if rs:
                for r in rs:

                    obj = {
                        'id': str(r['_id']),
                        'username': r['username'],
                        'cid': r['cid'] if 'cid' in r else '-',
                        'hospcode': r['hospcode'] if 'hospcode' in r else '-',
                        'hospname':
                        h.get_hospital_name(request, r['hospcode']),
                        'fullname': r['fullname'] if 'fullname' in r else '-',
                        'user_type':
                        r['user_type'] if 'user_type' in r else '-',
                        'user_status':
                        r['user_status'] if 'user_status' in r else '0',
                        'position': r['position'] if 'position' in r else '-'
                    }

                    rows.append(obj)

                return {'ok': 1, 'rows': rows}
            else:
                return {'ok': 0, 'msg': u'ไม่พบข้อมูล'}
        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
Example #7
0
def get_user_total(request):
    if 'logged' not in request.session:
        return HTTPFound(location='/signin')

    if request.is_xhr:

        csrf_token = request.params['csrf_token']
        is_token = (csrf_token == unicode(request.session.get_csrf_token()))

        if is_token:

            admin = AdminModel(request)

            try:
                total = admin.get_user_total()
                return {'ok': 1, 'total': total}
            except Exception as e:
                return {'ok': 0, 'msg': e.message}
        else:
            return {'ok': 0, 'msg': 'Not authorized.'}
    else:
        return {'ok': 0, 'msg': 'Not ajax request'}
Example #8
0
def get_user_total(request):
    if 'logged' not in request.session:
        return HTTPFound(location='/signin')

    if request.is_xhr:

        csrf_token = request.params['csrf_token']
        is_token = (csrf_token == unicode(request.session.get_csrf_token()))

        if is_token:

            admin = AdminModel(request)

            try:
                total = admin.get_user_total()
                return {'ok': 1, 'total': total}
            except Exception as e:
                return {'ok': 0, 'msg': e.message}
        else:
            return {'ok': 0, 'msg': 'Not authorized.'}
    else:
        return {'ok': 0, 'msg': 'Not ajax request'}
Example #9
0
def get_user_list(request):
    if 'logged' not in request.session:
        return HTTPFound(location='/signin')
    else:
        if request.is_xhr:  # is ajax request
            start = request.params['start'] if 'start' in request.params else 0
            stop = request.params['stop'] if 'stop' in request.params else 25

            limit = int(stop) - int(start)

            admin = AdminModel(request)

            rs = admin.get_user_list(int(start), int(limit))

            rows = []
            if rs:
                for r in rs:

                    obj = {
                        'id': str(r['_id']),
                        'username': r['username'],
                        'cid': r['cid'] if 'cid' in r else '-',
                        'hospcode': r['hospcode'] if 'hospcode' in r else '-',
                        'hospname': h.get_hospital_name(request, r['hospcode']),
                        'fullname': r['fullname'] if 'fullname' in r else '-',
                        'user_type': r['user_type'] if 'user_type' in r else '-',
                        'user_status': r['user_status'] if 'user_status' in r else '0',
                        'position': r['position'] if 'position' in r else '-'
                    }

                    rows.append(obj)

                return {'ok': 1, 'rows': rows}
            else:
                return {'ok': 0, 'msg': u'ไม่พบข้อมูล'}
        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
Example #10
0
def save_view(request):
    if 'logged' not in request.session:
        return HTTPFound(location='/signin')

    if request.session['user_type'] != '1':
        return {'ok': 0, 'msg': 'Not admin.'}
    else:

        data = {
            'fullname': request.params['fullname'],
            'cid': request.params['cid'],
            'hospcode': request.params['department'],
            'username': request.params['username'],
            'password': request.params['password'],
            'user_type': request.params['user_type'],
            'user_status': request.params['user_status'],
            'position': request.params['position']
        }

        admin = AdminModel(request)

        id = request.params["id"] if 'id' in request.params else False

        if not id:

            is_duplicate = admin.check_duplicate(request.params['username'])

            if is_duplicate:
                return {
                    'ok': 0,
                    'msg': 'ชื่อผู้ใช้งานนี้ถูกใช้แล้ว กรุณาเลือกใหม่'
                }
            else:
                rs = admin.save(data)

                if rs:
                    return {'ok': 1}
                else:
                    return {'ok': 0, 'msg': 'ไม่สามารถบันทึกรายการได้'}

        else:
            data['id'] = ObjectId(request.params['id'])
            admin.update(data)

            return {'ok': 1}