def post(self):
     pre = pre_or_part( self, True, False )
     c   = config()
     l   = False
     e   = False
     s   = ''
     t   = ''
     
     
     sess    = get_current_session()
     
     if sess.is_active():
         sess.terminate()
     
     if pre:
         if self.request.get( 'username' ) == c.pre.username and self.request.get( 'password' ) == c.pre.password:
             l   = True
             
         else:
             e   = True
         
         if l:
             sess[ 'logged_in' ] = True
         
     else:
         em  = self.request.get( 'email' )
         
         if len( em ) > 0:
             part    = participant_model.get_participant_by_email( em )
             
             if part is not None:
                 l   = True
                 
             else:
                 e   = True
                 
             
         else:
             e   = True
             
         
     
     if l:
         sdk = opentok_helper.OpenTokSDK( c.tokbox.api_key, c.tokbox.secret )
         
         # s   = sdk.create_session( self.request.url ).session_id
         t   = sdk.generate_token( c.tokbox.session_id, c.role.presenter if pre else c.role.participant )
     
     d   = { 'error': e, 'logged_in': l, 'token': t, 'session_id': c.tokbox.session_id, 'config': c.tokbox, 'email': '', 'time': '' }
     
     if pre is False and l and part:
         d[ 'email' ]    = em
         d[ 'time']      = part.time
     
     load( self, d )
def add_stream(s, a=False, p=False, e=''):
    m   = StreamModel()
    
    m.stream    = s
    m.active    = a
    m.presenter = p
    
    if len( e ) > 0:
        q   = participant_model.get_participant_by_email( e )
        
        if q is not None:
            m.participant   = q
        
        q2  = StreamModel().gql( 'WHERE participant = :1', q ).get()
        
        if q2 is not None:
            q2.delete()
    
    if p:
        delete_current_presenter()
    
    m.put()