Ignore:
Timestamp:
26 Sep 2019, 11:38:36 (5 years ago)
Author:
Henrik Bettermann
Message:

Finalize parents access.

File:
1 edited

Legend:

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

    r15546 r15609  
    5050    academic_sessions_vocab, IDataCenter, DOCLINK)
    5151from waeup.kofa.interfaces import MessageFactory as _
    52 from waeup.kofa.mandates.mandate import PasswordMandate
     52from waeup.kofa.mandates.mandate import PasswordMandate, ParentsPasswordMandate
    5353from waeup.kofa.university.interfaces import (
    5454    IDepartment, ICertificate, ICourse)
     
    392392    grok.template('loginasstep1')
    393393    pnav = 4
     394
     395    def update(self):
     396        super(LoginAsStudentStep1, self).update()
     397        kofa_utils = getUtility(IKofaUtils)
     398        self.temp_password_minutes = kofa_utils.TEMP_PASSWORD_MINUTES
     399        return
    394400
    395401    def label(self):
     
    25552561    grok.require('waeup.handleStudent')
    25562562    form_fields = grok.AutoFields(IStudentBase).select(
    2557         'email', 'phone')
     2563        'email', 'phone', 'parents_email')
    25582564    label = _('Edit base data')
    25592565    pnav = 4
     
    32163222        return
    32173223
     3224class ParentsUser:
     3225    pass
     3226
     3227class RequestParentsPasswordPage(StudentRequestPasswordPage):
     3228    """Captcha'd request password page for parents.
     3229    """
     3230    grok.name('requestppw')
     3231    grok.template('requestppw')
     3232    label = _('Request password for parents access')
     3233
     3234    def update(self):
     3235        super(RequestParentsPasswordPage, self).update()
     3236        kofa_utils = getUtility(IKofaUtils)
     3237        self.temp_password_minutes = kofa_utils.TEMP_PASSWORD_MINUTES
     3238        return
     3239
     3240    @action(_('Send temporary login credentials to email address'), style='primary')
     3241    def get_credentials(self, **data):
     3242        if not self.captcha_result.is_valid:
     3243            # Captcha will display error messages automatically.
     3244            # No need to flash something.
     3245            return
     3246        number = data.get('number','')
     3247        lastname = data.get('lastname','')
     3248        email = data['email']
     3249        cat = getUtility(ICatalog, name='students_catalog')
     3250        results = list(
     3251            cat.searchResults(reg_number=(number, number)))
     3252        if not results:
     3253            results = list(
     3254                cat.searchResults(matric_number=(number, number)))
     3255        if results:
     3256            student = results[0]
     3257            if getattr(student,'lastname',None) is None:
     3258                self.flash(_('An error occurred.'), type="danger")
     3259                return
     3260            elif student.lastname.lower() != lastname.lower():
     3261                # Don't tell the truth here. Anonymous must not
     3262                # know that a record was found and only the lastname
     3263                # verification failed.
     3264                self.flash(_('No student record found.'), type="warning")
     3265                return
     3266            elif email != student.parents_email:
     3267                self.flash(_('Wrong email address.'), type="warning")
     3268                return
     3269        else:
     3270            self._redirect_no_student()
     3271            return
     3272        kofa_utils = getUtility(IKofaUtils)
     3273        password = kofa_utils.genPassword()
     3274        mandate = ParentsPasswordMandate()
     3275        mandate.params['password'] = password
     3276        mandate.params['student'] = student
     3277        site = grok.getSite()
     3278        site['mandates'].addMandate(mandate)
     3279        # Send email with credentials
     3280        args = {'mandate_id':mandate.mandate_id}
     3281        mandate_url = self.url(site) + '/mandate?%s' % urlencode(args)
     3282        url_info = u'Confirmation link: %s' % mandate_url
     3283        msg = _('You have successfully requested a parents password for the')
     3284        # Create a fake user
     3285        user = ParentsUser()
     3286        user.name = student.student_id
     3287        user.title = "Parents of %s" % student.display_fullname
     3288        user.email = student.parents_email
     3289        if kofa_utils.sendCredentials(user, password, url_info, msg):
     3290            email_sent = user.email
     3291        else:
     3292            email_sent = None
     3293        self._redirect(email=email_sent, password=password,
     3294            student_id=student.student_id)
     3295        ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
     3296        self.context.logger.info(
     3297            '%s - %s (%s) - %s' % (ob_class, number, student.student_id, email_sent))
     3298        return
     3299
    32183300class StudentRequestPasswordEmailSent(KofaPage):
    32193301    """Landing page after successful password request.
Note: See TracChangeset for help on using the changeset viewer.