Esempio n. 1
0
def index():
    vd = {
        #'date':datetime.datetime.now().strftime('%Y'),
        'baseurl':settings.BASEURL,
    }

    e = bottle.request.POST.get('email')
    p = bottle.request.POST.get('password')
        
    if e and p:
        u = User(_DBCON, email=e, password=p)
        
        if u._id:
            s = Session(_DBCON)
            s.userid = u._id
            s.ip = bottle.request.get('REMOTE_ADDR')
            s.useragent = bottle.request.get('HTTP_USER_AGENT')
            s.save()
            
            s.set_cookie()
            
            bottle.redirect('/')
        else:
            return bottle.template('login', error='Incorrect email/password combination', email=e, password=p, vd=vd)
    else:
        return bottle.template('login', error='Please complete the form', email=e or '', password=p or '', vd=vd)
Esempio n. 2
0
def index():
    user = FacebookClient().process(bottle.request.GET['code'])
    
    if user:
        users = EntityManager(_DBCON).getAll(User, filterCriteria={'facebookUserId':user['id']})
        if users:
            _id = users[0]._id
        else:
            _id = None

        
        u = User(_DBCON, _id=_id)
        u.username = user['name']
        u.password = user['id']
        u.valid = False
        u.facebookUserId = user['id']
        u.save()
        
        s = Session(_DBCON)
        s.userid = u._id
        s.ip = bottle.request.get('REMOTE_ADDR')
        s.useragent = bottle.request.get('HTTP_USER_AGENT')
        s.save()
        
        s.set_cookie()
    
        bottle.redirect('/')
        
    else:
        bottle.redirect('/login')