We're Hiring!

Default logging a user in for certain pages

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Default logging a user in for certain pages

Postby Manz » Thu Jan 05, 2012 12:18 am

Hey Everyone,

I am looking to automate a 'guest' account for certain pages in omero, and am looking for the best way to do it. Currently we have a catalogue page that shows images and metadata associated with those pages, and I have worked out how to log that into our 'guest' account using the following in its views.py function:

conn = BlitzGateway("blah", "blahblah", host="blah.com")
conn.connect()
conn.changeActiveGroup(dbconnect.groupidfromds(datasetId))

Which works with the data but does not show the images in the catalogue. Which I assume means that the login isn't being saved or carried. So then I thought what if I altered the @isUserConnected to say
if user isn't logged in,
for certain urls
log in automatically as blah

Would this work? I tried the following but couldn't get it working

/opt/OmeroServer/lib/python/omeroweb/webclient/views.py

Code: Select all
def isUserConnected (f):
    def wrapped (request, *args, **kwargs):
        #this check the connection exist, if not it will redirect to login page
        server = string_to_dict(request.REQUEST.get('path')).get('server',request.REQUEST.get('server', None))
        url = request.REQUEST.get('url')
        #logger.info(" URL log- %s" % str(url))
        if url is None or len(url) == 0:
            if request.META.get('QUERY_STRING'):
                url = '%s?%s' % (request.META.get('PATH_INFO'), request.META.get('QUERY_STRING'))
            else:
                url = '%s' % (request.META.get('PATH_INFO'))
       
        conn = None
        #logger.info(" URL log- %s" % str(url))
        try:
            conn = getBlitzConnection(request, useragent="OMERO.web")
        except Exception, x:
            logger.error(traceback.format_exc())
       
        from omero.gateway import BlitzGateway
        from omeroweb.webgateway.views import _createConnection

#my addition
        if conn is None:
               # include a if statement to check url
                conn = _createConnection("", username="blah", passwd="blah", host="blah.com", useragent="OMERO.web")
        #       cc=conn.connect()
                conn = getBlitzConnection(request, useragent="OMERO.web")
        logger.info(" CONN create log- %s" % str(conn))
        logger.info(" URL log- %s" % str(url))
        logger.info(" CONN request - %s" % str(request))
#my addition end
        if conn is None:
            # TODO: Should be changed to use HttpRequest.is_ajax()


Manz
 
Posts: 72
Joined: Wed Jun 29, 2011 11:48 pm

Re: Default logging a user in for certain pages

Postby wmoore » Thu Jan 12, 2012 9:34 am

Hi,

Here's how I do it in the "emdb" app:

Instead of using the @isUserConnected decorator, I have a separate method getConnection() that is called from within each view method.

http://github.com/will-moore/openmicros ... s.py#L1088

There's no particular reason for this - I was just working on this before we adopted isUserConnected across the board. The logic should be the same anyway.

We now use settings.py to allow configuration of the username and password via the command line (see the code above and http://github.com/will-moore/openmicros ... gs.py#L172). This saves you from putting your username and password in your code which may be handy?

Hope that helps,

Will.
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 0 guests