Esempio n. 1
0
    def _login_user(self, u):
        s = Session(_DBCON)
        s.userid = u._id
        s.ip = bottle.request.get('REMOTE_ADDR')
        s.useragent = bottle.request.get('HTTP_USER_AGENT')
        s.save()

        return s
Esempio n. 2
0
    async def insertSession(self, userId: int) -> Session:
        sql = Query.into(sessions).columns(sessions.user_id, sessions.updated_at) \
            .insert(userId, datetime.now(timezone.utc)) \
            .returning(sessions.session_id, sessions.user_id, sessions.updated_at)

        result = await databaseClient.query(sql.get_sql())
        row = result[0]
        return Session(sessionId=row[0], userId=row[1], updatedAt=row[2])
Esempio n. 3
0
def getSession(db, sessionId=None):

    session = Session(db, sessionId)
    if (session.init()):
        ERROR("get session error %s" % sessionId)
        return {}

    session.update()

    return session.toObj()
Esempio n. 4
0
    async def refreshSession(self, session: Session) -> Optional[Session]:
        sql = Query.update(sessions).set(sessions.updated_at, datetime.now(timezone.utc)) \
            .where(Criterion.all([
                sessions.session_id == session.sessionId,
                sessions.user_id == session.userId,
                sessions.updated_at == session.updatedAt
            ])) \
            .returning(sessions.session_id, sessions.user_id, sessions.updated_at)

        result = await databaseClient.query(sql.get_sql())
        if len(result) == 0: return None
        row = result[0]
        return Session(sessionId=row[0], userId=row[1], updatedAt=row[2])
Esempio n. 5
0
def newSession(db, userObj):

    session = Session(db, getUuid())
    session.username = userObj["name"]
    session.cookie = {
        "id": userObj["id"],
        "name": userObj["name"],
        "role": userObj["role"]
    }
    session.role = userObj["role"]
    session.username = userObj["name"]
    session.userId = userObj["id"]

    session.add()

    return session.toObj()
Esempio n. 6
0
    def wrapper(*args, **kwargs):
        if bottle.request.get_cookie('token') or bottle.request.GET.get(
                'token'):
            token = bottle.request.get_cookie(
                'token') or bottle.request.GET.get('token')

            s = Session(_DBCON, publicid=token)
            if not s.valid or not s.check(
                    bottle.request.get('REMOTE_ADDR'),
                    bottle.request.get('HTTP_USER_AGENT')):
                return bottle.redirect('/login')
            else:
                bottle.request.session = s
                return callback(*args, **kwargs)
        else:
            return bottle.redirect('/login')
Esempio n. 7
0
def new_pot_registration(pot_id):
    try:
        # NOTE: Have to call datetime.utcnow() here instead of creating default values in class Session as it will stay as constant
        new_session = Session(newSessInput=NewSessionInput(potId=pot_id),
                              sessionStartTime=datetime.utcnow())
        # NOTE: Have to call datetime.utcnow() here instead of creating default values in class Pot as it will stay as constant
        # Another way of getting utc time is datetime.now(timezone.utc)
        new_pot = Pot(potId=pot_id,
                      potRegisteredTime=datetime.utcnow(),
                      session=new_session)
        quiz_dates = scheduled_quiz_dates(new_session.sessionStartTime,
                                          new_session.quiz.quizDayNumbers)
        new_session.quiz.quizDates = quiz_dates
        return new_pot
    except Exception as e:
        return e
Esempio n. 8
0
def removeSession(db, sessionId):
    session = Session(db, sessionId)
    return session.delete()
Esempio n. 9
0
    # a = np.array([[1], [2], [3]])
    # # b = np.array([[1,2 , 3, 3],
    # # 		[4, 5, 6, 6],
    # # 		[7, 8, 9, 9]])
    # b = np.array([[4], [5], [6]])
    # print(a.T.dot(b) - 1)

    mp = model_prototype()
    W = np.random.uniform(2, 1, 3)
    x1 = np.random.uniform(-10, 10, 10)
    x2 = np.random.uniform(-10, 10, 10)
    x3 = np.array([1] * 10)
    X = np.array([x1, x2, x3]).transpose()
    y = np.array([1 if val >= 0 else 0 for val in X.dot(W)])
    md = mp.recognize("Logistic")
    X = np.hstack((X[0:len(X), 0:-1], np.array([y]).T))
    # print(X)
    md.feed_data(X)
    # print(md.weights)
    sess = Session()
    for i in range(0, 100):
        md.next_step()
    vs = visualizer(md, (5, 5), (-5, 5), (-5, 5))
    image = vs.visualize()
    image.save("bla.png")
    image.show()

    # yy = np.array([1 if val >=0 else 0 for val in X.dot(md.weights)])
    # print("yy = ", yy)
    # print("y = ", y)
    # print(md.weights)
Esempio n. 10
0
 def get_session(node):
     return Session(name=CalendarScrapper.get_name(node),
                    begin=CalendarScrapper.get_begin(node),
                    location=CalendarScrapper.get_location(node),
                    duration=CalendarScrapper.get_duration(node))