Commits

alex bodnaru  committed e22e916

improve automatic login

  • Participants
  • Parent commits 0a62656

Comments (0)

Files changed (4)

File tgext.registration2.egg-info/PKG-INFO

 Metadata-Version: 1.0
 Name: tgext.registration2
-Version: 0.5.1dev-20090815
+Version: 0.5.1dev-20110401
 Summary: set of controller entries to handle users' (self)registration in turbogears 2
 Home-page: http://resheteva.org.il/packages
 Author: alex bodnaru
 Description: Introduction
         ============
         
-        provide ./new, ./edit_user, ./delete_user, ./lost_password functionality,
+        provide ./new, ./edit_user, ./delete_user, ./lost_password functionality, 
         to be imported in any project
         
         Changelog
         * Initial release
         
         
-        a self-registration module for turbogears2 meant to allow users to register
-        themselves, edit their information, request password reset when lost, and even
+        a self-registration module for turbogears2 meant to allow users to register 
+        themselves, edit their information, request password reset when lost, and even 
         delete their account.
-        this code is heavily based on the registration add-on for turbogears 1, made by
+        this code is heavily based on the registration add-on for turbogears 1, made by 
         patrick lewis.
         
-        this code changed the original add-on by supporting only sqlalchemy (and
-        elixir) models, but not sqlobject ones (which are currently not supported in
-        tg2 anyway), but also as the deployment model: this is an extension module,
-        that may and would better be used independently of any project, however adding
-        a few tables and a controller entry point to the main project.
-        it may also be heavily customized for one project, by copying the registration
+        this code changed the original add-on by supporting only sqlalchemy (and 
+        elixir) models, but not sqlobject ones (which are currently not supported in 
+        tg2 anyway), but also as the deployment model: this is an extension module, 
+        that may and would better be used independently of any project, however adding 
+        a few tables and a controller entry point to the main project. 
+        it may also be heavily customized for one project, by copying the registration 
         code to a special location for some specific project.
         
         copyright (c) 2006-2008 patrick lewis
         copyright (c) 2009 alex bodnaru, <alexbodn@012.net.il>
         
         this code is released under the mit license.
-        as an exception, to the license, i make clear that taking any piece of this
-        code in order to port the original add-on or improve it anyhow should require
+        as an exception, to the license, i make clear that taking any piece of this 
+        code in order to port the original add-on or improve it anyhow should require 
         no special permission and should not need to mention the code came from here.
         
         how to:
-        * usage of the registration module requires the presence of the auth model (say
+        * usage of the registration module requires the presence of the auth model (say 
         auth=yes in quickstarting your project).
         
-        * in <your_project>/model/__init__.py, append the following line right under
+        * in <your_project>/model/__init__.py, append the following line right under 
         the import of the auth objects (from auth import ...):
         from tgext.registration2.model import *
         
-        * in <your_project>/controllers/<any_controller>.py, import the
+        * in <your_project>/controllers/<any_controller>.py, import the 
         UserRegistration controller class:
         from tgext.registration2.controllers import UserRegistration
-        and, set the access point of the registration module under the access point of
+        and, set the access point of the registration module under the access point of 
         the controller of your choice (RootController in our example:
         class RootController(BaseController):
-        <registration access point> = UserRegistration()
+            <registration access point> = UserRegistration()
         
         * to customize any of the parameters set in the tgext/registration/registration.cfg
-        please copy this file anywhere you wish and change any of the given values and
-        set the location of the copied file in development/deployment.ini, in variable
+        please copy this file anywhere you wish and change any of the given values and 
+        set the location of the copied file in development/deployment.ini, in variable 
         registration_config, under [app:main].
         
-        * that's all: in <your site>, you may access any of the registration controller
+        * that's all: in <your site>, you may access any of the registration controller 
         entries at <your site>/<registration access point>
-        <registration access point>/ new, edit_user, lost_password and delete_user may
+        <registration access point>/ new, edit_user, lost_password and delete_user may 
         be invoked now from any point in your site you may wish.
         
         what next?
-        one of the advantages of maintaining the code independently of any site project
+        one of the advantages of maintaining the code independently of any site project 
         is the possibility to improve the code to the benefit of older projects too.
         for now, my intention is to add the following:
         * captcha support, including management of the picture-label pairs.
         * chalenging question support, to be used for lost_password and delete_user.
-        * the ability to generate x509 certificates to allow users to autologin (with
+        * the ability to generate x509 certificates to allow users to autologin (with 
         an appropriate repoze.who plugin).
         * make the tests work.
         

File tgext/__init__.pyc

Binary file modified.

File tgext/registration2/controllers.py

 from pkg_resources import resource_string
 import logging
 import datetime
-import sha
+import hashlib
 import smtplib
 import urllib
 import string
             user = self.promote_pending_user(pend)
             self.add_unverified_groups(user)
             # log them in
-            cookie = AuthTktCookiePlugin(config["repoze.secret"])
-            headers=cookie.remember(request.environ, {"repoze.who.userid" : user_name})
+            plugins = request.environ.get('repoze.who.plugins').values()
+            rememberers = [auth for auth in plugins if hasattr(auth, 'remember')]
+            res = rememberers and \
+                rememberers[0].remember(request.environ, dict(login=user_name, password=password1))
+            #cookie = AuthTktCookiePlugin(config["repoze.secret"])
+            #headers=cookie.remember(request.environ, {"repoze.who.userid" : user_name})
             
         return dict(name=display_name, email=email, error_msg=error_msg)
 
         "Returns a hash that can be used for validation."
         hash_str =  u" ".join((unique_input, request.remote_addr, 
                              self.hash_salt, datetime.datetime.now().isoformat()))
-        return sha.new(unicode(hash_str).encode('ascii', 'replace')).hexdigest()
+        return hashlib.new('sha1', unicode(hash_str).encode('ascii', 'replace')).hexdigest()
         
     def registration_base_url(self):
         """Returns the full http://... address of the registration controller.

File tgext/registration2/registration_config.pyc

Binary file modified.