Exemple #1
0
def do_login(request):

    from icare.helpers.icare_helper import ICHelper

    h = ICHelper()

    csrf_token = request.params['csrf_token']
    username = request.params['username']
    password = h.get_hash(request.params['password'])
    is_process = True if 'isProcess' in request.params else False

    auth = Auth()

    is_token = (csrf_token == unicode(request.session.get_csrf_token()))
    if is_token:
        #do login
        users = auth.do_login(username, password, request)
        if users:
            session = request.session
            session['logged'] = True
            session['hospcode'] = users['hospcode']
            session['owner'] = users['owner']
            session['fullname'] = users['fullname']
            session['user_type'] = users['user_type']
            session['id'] = str(users['_id'])

            if is_process:
                #process data
                anc = AncModel(request)
                mch = MchModel(request)
                babies = BabiesModel(request)

                anc.do_process_list(users['hospcode'])
                anc.do_process_12weeks(users['hospcode'])

                mch.do_process_forecast(users['hospcode'])
                babies.process_milk(users['hospcode'])

            if users['user_type'] == '1':
                return HTTPFound(location='/admins/users')
            else:
                return HTTPFound(location='/')
        else:
            return HTTPFound(location='/signin')
    else:
        raise HTTPUnauthorized
Exemple #2
0
def reports_milk_process(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        if request.is_xhr:  # is ajax request
            csrf_token = request.params['csrf_token']
            is_token = (csrf_token == unicode(request.session.get_csrf_token()))

            if is_token:
                babies = BabiesModel(request)
                babies.process_milk(request.session['hospcode'])

                return {'ok': 1}
            else:
                return {'ok': 0, 'msg': 'Invalid token key'}
        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}
Exemple #3
0
def reports_milk_process(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        if request.is_xhr:  # is ajax request
            csrf_token = request.params['csrf_token']
            is_token = (csrf_token == unicode(
                request.session.get_csrf_token()))

            if is_token:
                babies = BabiesModel(request)
                babies.process_milk(request.session['hospcode'])

                return {'ok': 1}
            else:
                return {'ok': 0, 'msg': 'Invalid token key'}
        else:
            return {'ok': 0, 'msg': 'Not ajax request.'}