Exemplo n.º 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
Exemplo n.º 2
0
def anc_do_process_12weeks(request):
    if "logged" not in request.session:
        return {"ok": 0, "msg": "Please login."}
    else:
        if request.is_xhr:
            csrf_token = request.params["csrf_token"]
            is_token = csrf_token == unicode(request.session.get_csrf_token())

            if is_token:
                anc = AncModel(request)
                rs = anc.do_process_12weeks(request.session["hospcode"])

                return {"ok": 1} if rs else {"ok": 0, "msg": "ไม่สามารถประมวลผลได้"}
            else:
                return {"ok": 0, "msg": "Not authorized "}
        else:
            return {"ok": 0, "msg": "Not ajax request"}
Exemplo n.º 3
0
def anc_do_process_12weeks(request):
    if 'logged' not in request.session:
        return {'ok': 0, 'msg': 'Please login.'}
    else:
        if request.is_xhr:
            csrf_token = request.params['csrf_token']
            is_token = (csrf_token == unicode(
                request.session.get_csrf_token()))

            if is_token:
                anc = AncModel(request)
                rs = anc.do_process_12weeks(request.session['hospcode'])

                return {
                    'ok': 1
                } if rs else {
                    'ok': 0,
                    'msg': 'ไม่สามารถประมวลผลได้'
                }
            else:
                return {'ok': 0, 'msg': 'Not authorized '}
        else:
            return {'ok': 0, 'msg': 'Not ajax request'}