Changeset 8858


Ignore:
Timestamp:
30 Jun 2012, 07:39:07 (12 years ago)
Author:
Henrik Bettermann
Message:

Store user in mandate. This makes everything much easier.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py

    r8857 r8858  
    2626import time
    2727import re
     28from urllib import urlencode
    2829from zope import schema
    2930from zope.authentication.interfaces import (
     
    6768from waeup.kofa.authentication import get_principal_role_manager
    6869from waeup.kofa.utils.helpers import get_user_account, msave
     70from waeup.kofa.mandates.mandate import PasswordMandate
    6971
    7072grok.context(IKofaObject)
     
    21242126        # Change password
    21252127        kofa_utils = getUtility(IKofaUtils)
    2126         pwd = kofa_utils.genPassword()
    2127 
    2128         ###: To be changed
    2129         IUserAccount(user).setPassword(pwd)
    2130 
    2131 
    2132         # Send email with new credentials
    2133         msg = _('You have successfully changed your password for the')
    2134         login_url = self.url(grok.getSite(), 'login')
    2135         url_info = u'Login: %s' % login_url
     2128        password = kofa_utils.genPassword()
     2129        mandate = PasswordMandate()
     2130        mandate.params['password'] = password
     2131        mandate.params['user'] = user
     2132        site = grok.getSite()
     2133        site['mandates'].addMandate(mandate)
     2134        # Send email with credentials
     2135        args = {'mandate_id':mandate.mandate_id}
     2136        mandate_url = self.url(site) + '/mandate?%s' % urlencode(args)
     2137        url_info = u'Confirmation link: %s' % mandate_url
     2138        msg = _('You have successfully requested a password for the')
    21362139        success = kofa_utils.sendCredentials(
    2137             IUserAccount(user),pwd,url_info,msg)
     2140            IUserAccount(user),password,url_info,msg)
    21382141        if success:
    21392142            self.flash(_('An email with your user name and password ' +
  • main/waeup.kofa/trunk/src/waeup/kofa/mandates/mandate.py

    r8857 r8858  
    5555
    5656    def _setPassword(self):
    57         user_id = self.params.get('user_id', None)
     57        user = self.params.get('user', None)
    5858        pwd = self.params.get('password', None)
    59         user_type = self.params.get('user_type', None)
    60         user = None
    61         if user_type == 'student':
    62             user = grok.getSite()['students'].get(user_id, None)
    63         elif user_type == 'officer':
    64             user = grok.getSite()['users'].get(user_id, None)
    6559        if user and pwd:
    66             IUserAccount(user).setPassword(pwd)
    67             return True
     60            try:
     61                IUserAccount(user).setPassword(pwd)
     62                return True
     63            except:
     64                return False
    6865        return False
    6966
  • main/waeup.kofa/trunk/src/waeup/kofa/mandates/tests.py

    r8857 r8858  
    9999        # Add and execute a perfect mandate
    100100        mandate = PasswordMandate()
    101         mandate.params['user_id'] = student.student_id
     101        mandate.params['user'] = student
    102102        mandate.params['password'] = 'mypwd1'
    103         mandate.params['user_type'] = 'student'
    104103        self.app['mandates'].addMandate(mandate)
    105104        msg = mandate.execute()
     
    115114        officer = self.app['users']['bob']
    116115        mandate = PasswordMandate()
    117         mandate.params['user_id'] = 'bob'
     116        mandate.params['user'] = officer
    118117        mandate.params['password'] = 'mypwd1'
    119         mandate.params['user_type'] = 'officer'
    120118        self.app['mandates'].addMandate(mandate)
    121119        msg = mandate.execute()
     
    142140        self.app['students'].addStudent(student)
    143141        mandate = PasswordMandate()
    144         mandate.params['user_id'] = student.student_id
    145         mandate.params['user_type'] = 'student'
     142        mandate.params['user'] = student
    146143        mandate.params['password'] = 'mypwd1'
    147144        self.app['mandates'].addMandate(mandate)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r8857 r8858  
    19891989        mandate = PasswordMandate()
    19901990        mandate.params['password'] = password
    1991         mandate.params['student_id'] = student.student_id
    1992         mandate.params['user_type'] = 'student'
     1991        mandate.params['user'] = student
    19931992        site = grok.getSite()
    19941993        site['mandates'].addMandate(mandate)
Note: See TracChangeset for help on using the changeset viewer.