[web2py] Re: Auth with Wordpress
Hello Kenneth, > But how do I handle that WP takes care of authentication and somehow gives > the customer rights to view the manual. > > I had a similar problem. I added an XMLRPC method to my wordpress instance to check if a given username/password combination is valid and added an auth method to my web2py instance which calls that XMLRPC method. Wordpress Code: # custom remote auth add_filter( 'xmlrpc_methods', 'my_add_xml_rpc_methods' ); function my_add_xml_rpc_methods( $methods ) { $methods['mh.testCredentials'] = 'test_credentials'; return $methods; } function test_credentials( $params ) { global $wp_xmlrpc_server; $blog_id = (int) $params[0]; // not used, but follow in the form of the wordpress built in XML-RPC actions $username = $params[1]; $password = $params[2]; $args = $params[3]; // verify credentials if ( ! $wp_xmlrpc_server->login( $username, $password ) ) { return False; } do_action( 'xmlrpc_call', 'mh.testCredentials' ); // patterned on the core XML-RPC actions // return success return True; } This is one of the tutorials I used when coming up with this: http://www.foxrunsoftware.net/articles/wordpress/extending-the-wordpress-xml-rpc-api/ Now the web2py part - copy to ./gluon/contrib/login_methods/my_auth.py from wordpress_xmlrpc import Client from wordpress_xmlrpc import AuthenticatedMethod from wordpress_xmlrpc import InvalidCredentialsError class GetUserInfo(AuthenticatedMethod): method_name = "mh.testCredentials" def my_auth(server): """ to use basic login with a different server from gluon.contrib.login_methods.basic_auth import basic_auth auth.settings.login_methods.append(basic_auth('http://server')) """ def basic_login_aux(username, password,server=server): wp = Client(server, username, password) retVal = None try: retVal = wp.call(GetUserInfo()) except InvalidCredentialsError: return False return retVal return basic_login_aux Now, where you configure your auth module, add this: from gluon.contrib.login_methods.my_auth import my_auth auth.settings.login_methods=[my_auth("http://mywordpress/xmlrpc.php";)] # smart people use https auth.settings.actions_disabled.append('register') -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] One database field, two form fields? From seconds to min:sec
Hello all, I'm writing a web app where people can log their exercise sessions. Basically, sessions are timed, and the faster the better. To this end, I store seconds in my model: Field('f_record_taken', type='date',notnull=True,default=datetime.date. today(), label=T('Record Taken')), Field('f_user', type='reference auth_user',notnull=True, label=T('User')), Field('f_exercise', type='reference t_exercise_description',notnull=True , label=T('Exercise')), ### either repetitions, time or weight Field('f_measure', type='double',notnull=True, label=T('Measurement')), Field('f_comment', type='string',label=T("Comment")), I use SQLForm to let users insert new entries: form = SQLFORM(db.t_exercise_log, fields = ["f_record_taken", "f_measure", "f_comment"] Obviously, this will render the f_measure field as a single form entry - but users do not want to enter seconds because it requires them to do the math from minutes to seconds. I could theoretically use a time field instead, but I use the f_measure field for other types of exercise as well (think "weight lifted in kilos"). How would you go about doing this? I assume I could use SQLForm.Factory, but then I might have to validate the form by hand (?). So I'm wondering what would be the best, most web2py-ish solution here, e.g. by modifying some kind of representation logic in the model. Kind regards, Michael -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [web2py] Re: Auth with Wordpress
Am Donnerstag, 7. Februar 2013 19:13:41 UTC+1 schrieb Kenneth: > > Am I understanding you solution completly wrong but isn't it so that > web2py asks WP if a username and password compination is OK. In my case > customer first logs into a WP site, he gets a list of manuals he has paid > for. When selecting a manual he wants to read he is sent to a web2py site. > Somehow WP has to tell web2py that it is OK to show the site for the user. > > > Kenneth > > > Hi Kenneth, you are right, my solution won't do that. I was basically facing a similar problem and decided to just make the user log in again. Some kind of single log-in scheme or session sharing would be nice, but that's out of my depth. -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: One database field, two form fields? From seconds to min:sec
Hello all, I decided to tackle this with the first implementation I saw in the documentation. I insert two custom fields, remove the f_measure field from the form and use the "SQLForm without Database IO" code from the book to process the form. Here's my (somewhat ugly) code, hopefully it will be useful to someone. form = SQLFORM(db.t_exercise_log, fields = ["f_record_taken", "f_comment", "f_scaled"], labels = {'f_measure' : EXERCISE_UNIT[exercise.f_unit[0]]}) time_element = TR(LABEL('Time:'), DIV(INPUT(_name='minutes',_type='text',_size='2', _maxlength ='3', requires=IS_INT_IN_RANGE(0,181, error_message=T('Minutes must be between 0 and 180')), _id="t_exercise_log_f_min", _style="width: 2em; margin: 2px 2px 2px 5px;"), T("m"), INPUT(_name='seconds',_type='text',_size='2', # 0 < x < 60 requires=IS_INT_IN_RANGE(0,60, error_message=T('Seconds must be between 0 and 59.')), _id="t_exercise_log_f_sec", _style="width: 2em; margin: 2px 2px 2px 5px;"), T("s"))) form[0].insert(-3,time_element) form.vars.f_measure = 0 Form processing: if form.validate(): sec = form.vars.minutes * 60 + form.vars.seconds form.vars.f_measure = sec # delete fields or DB insertion will fail del form.vars.minutes del form.vars.seconds form.vars.id = db.t_exercise_log.insert(**dict(form.vars)) _updateCurrentExerciseLog(auth.user_id, form.vars.id) session.flash = T('your record has been logged') redirect(URL("list")) Am Donnerstag, 7. Februar 2013 14:07:46 UTC+1 schrieb Michael Haas: > > Hello all, > > I'm writing a web app where people can log their exercise sessions. > Basically, sessions are timed, and the faster the better. To this end, I > store seconds in my model: > > Field('f_record_taken', type='date',notnull=True,default=datetime.date > .today(), > label=T('Record Taken')), > Field('f_user', type='reference auth_user',notnull=True, > label=T('User')), > Field('f_exercise', type='reference t_exercise_description',notnull= > True, > label=T('Exercise')), > ### either repetitions, time or weight > Field('f_measure', type='double',notnull=True, > label=T('Measurement')), > Field('f_comment', type='string',label=T("Comment")), > > > > I use SQLForm to let users insert new entries: > > form = SQLFORM(db.t_exercise_log, fields = ["f_record_taken", "f_measure" > , "f_comment"] > > Obviously, this will render the f_measure field as a single form entry - > but users do not want to enter seconds because it requires them to do the > math from minutes to seconds. I could theoretically use a time field > instead, but I use the f_measure field for other types of exercise as well > (think "weight lifted in kilos"). > > How would you go about doing this? I assume I could use SQLForm.Factory, > but then I might have to validate the form by hand (?). So I'm wondering > what would be the best, most web2py-ish solution here, e.g. by modifying > some kind of representation logic in the model. > > > Kind regards, > > Michael > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: One database field, two form fields? From seconds to min:sec
I accidentally hit sent while still editing the code formatting. Oh well, it should be obvious how it works. I still feel a custom widget with a validator doing the value calculation would be nicer, but I'm not sure if that's possible. Kind regards, Michael -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Pretty URLs with cgihandler.py
Hello all, my webhost only offers Python in CGI mode, so I'm currently using cgihandler.py which works reasonably well. My current URL is http:/host/cgihandler.py/ which shows the main page of my application just fine. However, I'd like the URL to be just http://host/ without the cgihandler.py/ part. Things I have tried in .htaccess: * ScriptAlias / /cgihandler.py/ - Just results in HTTP 500 * RewriteRule ^/(.*) /cgihandler.py/$1 - Just results in HTTP 404 for http://host/ and "invalid function default/cgihandler" for http://host/cgihandler.py/ * AliasMatch ^/(.*) /cgihandler.py/$1 - HTTP 500 again So, I have a feeling I'm missing something fundamental here - any clues? My routes.py: routers = dict( # base router BASE = dict( default_application = "Sarge", #path_prefix = "cgihandler.py", ), ) Of course, path_prefix is enabled for regular operation where I use the cgihandler.py suffix in the URL. Kind regards, Michael -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: Pretty URLs with cgihandler.py
Hi there, got it figured out. Here's my .htaccess: RewriteEngine On RewriteBase / # break after this rule to avoid firing the second rule for static files RewriteRule ^([^/]+)/static/(.*)$ /applications/$1/static/$2 [L] RewriteCond %{REQUEST_URI} !^/cgihandler\.py/ RewriteCond %{REQUEST_URI} !^/applications/([^/]+)/static/ RewriteRule ^(.*)$ /cgihandler.py/$1 ScriptAlias and AliasMatch only work in httpd.conf, so putting these in .htaccess would not work. The real magic - i.e. the difference from my earlier attempts - probably is "RewriteBase /" and not starting the RewriteRule patterns with /. The first rewrite rule has the benefit of not routing static file requests through cgihandler.py. Instead, these requests are served by Apache which makes a huge difference in load times for me. It's also easier to add far-future expires headers this way, as web2py only does that for files with version strings in their name (?). Hope that helps someone. Kind regards, Michael Am Samstag, 16. Februar 2013 23:22:48 UTC+1 schrieb Michael Haas: > > Hello all, > > my webhost only offers Python in CGI mode, so I'm currently using > cgihandler.py which works reasonably well. > > My current URL is http:/host/cgihandler.py/ which shows the main page of > my application just fine. However, I'd like the URL to be just > http://host/ without the cgihandler.py/ part. > > Things I have tried in .htaccess: > > * ScriptAlias / /cgihandler.py/ - Just results in HTTP 500 > * RewriteRule ^/(.*) /cgihandler.py/$1 - Just results in HTTP 404 for > http://host/ and "invalid function default/cgihandler" for > http://host/cgihandler.py/ > * AliasMatch ^/(.*) /cgihandler.py/$1 - HTTP 500 again > > So, I have a feeling I'm missing something fundamental here - any clues? > > My routes.py: > > routers = dict( > # base router > BASE = dict( > default_application = "Sarge", > #path_prefix = "cgihandler.py", > ), > ) > > Of course, path_prefix is enabled for regular operation where I use the > cgihandler.py suffix in the URL. > > Kind regards, > > Michael > > > > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.