Ejemplo n.º 1
0
 def signup(self):
     u = User()
     for fn in ['email','password','name']:
         setattr(u,fn,self.form_result.get(fn))
     u.fb_uid=None
     default_user_attrs(u,request)
     #override lang with the lang user signed up in
     u.lang = request.environ['pylons.routes_dict']['_lang']
     meta.Session.add(u); meta.Session.commit()
     return self.login()
Ejemplo n.º 2
0
def setup_app(command, conf, vars):
    """Place any commands to setup greencouriers here"""
    load_environment(conf.global_conf, conf.local_conf)
    # Load the models
    from greencouriers.model import meta,User
    meta.metadata.bind = meta.engine

    # Create the tables if they aren't there already
    meta.metadata.create_all(checkfirst=True)
    if False and not len(meta.Session.query(User).all()): #cancelled for now
	u = User()
	u.id=1
	meta.Session.add(u)
	meta.Session.commit()
Ejemplo n.º 3
0
def force_login(f,*args,**kws):
    auth = False
    if 'greenie_auth' in session and session['greenie_auth']:
        try:
            u = meta.Session.query(User).filter_by(login_hash=session['greenie_auth']).one()
            #FIXME: we don't handle a case here in which the user has a previous facebook account and he attempts to associate it to a second email account..
            if not u.fb_uid and facebook.check_session() and not len(meta.Session.query(User).filter_by(fb_uid=facebook.uid).all()):
                u.fb_uid=facebook.uid
                meta.Session.commit()
            c.user = u
            c.user_id = u.id
            auth=True
        except:
            #pass
            raise

            
    if config['use_facebook']!='true': 
        c.use_facebook=False
# we have an alternative auth system in place now.
#         u  = meta.Session.query(User).get(1)
#         if not u:
#             u = User()
#             u.id = 1
#             u.fb_uid='12341234'
#             u.name='Test user'
#             meta.Session.add(u); meta.Session.commit()
#         c.user = u
#         c.user_id = u.id
#        return f(*args,**kws)
    c.use_facebook=True
    action = request.environ['pylons.routes_dict']['action']
    login_action='fb_login'
    fbses = facebook.check_session()
    if fbses:
        if not facebook.uid: raise Exception('no fb uid!')
        #raise Exception('fb uid:%s'%facebook.uid)
        try:
            u = meta.Session.query(User).filter_by(fb_uid=facebook.uid).one()
        except NoResultFound:
            u = User()
            u.fb_uid = facebook.uid
            u.name = facebook.users.getInfo(facebook.uid)[0]['name']
            #facebook.users.setStatus("just registered on <a href='http://www.greenie.co.il'>Green Couriers</a> - the green way of delivering.",False)
            #facebook.feed.publishUserAction(51359366316)
            from greencouriers.controllers.auth import default_user_attrs
            default_user_attrs(u,request)
            meta.Session.add(u); meta.Session.commit()
        c.user_id=u.id
        c.user = u
        auth = True
    elif not auth:
        if action!=login_action:
            # we could not login. see if there are any last exceptions?
            if request.urlvars['controller']=='main' or \
                    (request.urlvars['action'] in ['login','signup','logout',_('reset')]\
                    and not re.compile(_('_signup$')).search(request.urlvars['controller'])):
                return f(*args,**kws)
            # redirect to login.
            return redirect(url.current(action=login_action,return_action=action))
    if auth==True:
        if c.user:
            from greencouriers.lib.base import freemap_url_from_country
            c.use_google_maps,c.freemap_url = freemap_url_from_country(c.user.country,c.user)
            #if c.use_google_maps: raise Exception('country of user %s is %s'%(c.user.id,c.user.country))
            #raise Exception('extracted %s,%s from %s'%(c.use_google_maps,c.freemap_url,c.user.country))
        return f(*args,**kws)