Beispiel #1
0
def login_user():
    '''
    Request new password
    :return:
    '''
    info=""
    user_id = validat_session(request.cookies.get("samma_uid"))
    if user_id != False:
        pass
    if request.method == 'POST':
        email = str(request.form['email'])
        password = str(request.form['password'])
        user_id = login(email,password)
        if user_id !=False:
            #Uer has given correct user and password
            #Creating session and login session cookie
            session_id = session(user_id)
            redirect_to_mypage = redirect('/home' , _scheme='https')
            #resp = make_response(render_template('pro.html',info=info))
            resp = make_response(redirect_to_mypage)
            resp.set_cookie('samma_uid',value=session_id)
            return resp
        else:
            info ="Not a valid email ore password"
    return render_template('pro.html',info=info)
Beispiel #2
0
def mypage():
    info=""
    user_id = validat_session(request.cookies.get("samma_uid"))
    if user_id != False:
        session_id = session(user_id)
        user_id_mongo=user_id.decode("utf-8")
        user_data = get_user_data(user_id_mongo)
        user_r = settings.db.domain.find({"UID":user_id_mongo})
        user_domain=[]
        baseline = settings.db.baseline.find({'UID':user_id_mongo})
        for d in user_r:
            user_domain.append(d)

        if request.method == 'POST':
            domain = str(request.form['domain'])
            add_to_que(domain,user_id_mongo)
            info="Scan started"
        if request.method=='GET':
            if request.args.get('bs'):
                if user_data['baslinestatus'] =="Full":
                    '''
                    full baseline cant add more
                    '''
                    info="Cant add more baseline it's full"
                else:
                    add_baselinecount(user_id_mongo)
                    bs_id = request.args.get('bs')
                    domain = request.args.get('domain')
                    settings.db.baseline.insert( { 'bs':bs_id, 'domain':domain, 'UID':user_id_mongo,'Date':format(datetime.datetime.utcnow()),'Status':'Not matced'} )


                #resp = make_response(render_template('mypage.html',info=info,domain=user_domain,baseline=baseline,user_data=user_data))
                #resp.set_cookie('northamlin_uid',value=session_id)
                #return resp
                return redirect('home')

            elif request.args.get('del'):
                remove_baselinecount(user_id_mongo)
                bs_id = request.args.get('del')
                settings.db.baseline.remove({'_id':ObjectId(bs_id), 'UID':user_id_mongo})
                #resp = make_response(render_template('mypage.html',info=info,domain=user_domain,baseline=baseline,user_data=user_data))
                #resp.set_cookie('northamlin_uid',value=session_id)
                #return resp
                return redirect('home')
            elif request.args.get('show'):
                domain=request.args.get('show')
                scan = settings.db.domain.find_one({"_id": ObjectId(domain),"UID":user_id_mongo})
                resp = make_response(render_template('mypage.html',info=info,domain=user_domain,scan=scan,baseline=baseline,user_data=user_data))
                resp.set_cookie('northamlin_uid',value=session_id)
                return resp


        resp = make_response(render_template('mypage.html',info=info,domain=user_domain,baseline=baseline,user_data=user_data))
        resp.set_cookie('samma_uid',value=session_id)
        return resp

    else:
        redirect_to_index = redirect('/' ,_scheme='https')
        response = make_response(redirect_to_index )
        response.set_cookie('samma_uid',value='nope')
        return response