Beispiel #1
0
 def confirm_emails(self):
     emails = request.POST.getall('email')
     for email in emails:
         email_confirmation_request(c.user, email)
     h.flash(_('Confirmation message sent. Please check your email.'))
     dest = request.POST.get('came_from', None)
     if dest is not None:
         redirect(dest.encode('utf-8'))
     else:
         redirect(url(controller='profile', action='edit_contacts'))
Beispiel #2
0
    def update_contacts(self):
        # TODO: this should be refactored into separate actions
        if hasattr(self, 'form_result'):
            # site url
            c.user.site_url = self.form_result['site_url']

            # address and email visibility (teachers only)
            if c.user.is_teacher:
                c.user.work_address = self.form_result['work_address']
                c.user.email_is_public = 'email_is_public' in self.form_result

            if self.form_result['confirm_email']:
                h.flash(_('Confirmation message sent. Please check your email.'))
                email_confirmation_request(c.user, c.user.email.email)
                redirect(url(controller='profile', action='edit_contacts'))

            # handle email
            email = self.form_result['email']
            confirmed = False
            if email != c.user.email.email:
                # XXX Allow user to set default email if it already added as second.
                if len(c.user.emails) > 1:
                    if c.user.emails[1].email == email:
                        del c.user.emails[1]
                        meta.Session.commit()
                        confirmed = True

                c.user.email.email = email
                c.user.email.confirmed = confirmed
                email_confirmation_request(c.user, email)
                sign_in_user(c.user)

            # new way to handle user email
            email = self.form_result['email']
            confirmed = False
            if email != c.user.email.email:
                email_objs = filter(lambda e: e.email == email, c.user.emails)
                if email_objs:
                    new_main_email = email_objs[0]
                    meta.Session.delete(new_main_email)
                    meta.Session.commit()
                    confirmed = True
                c.user.email.email = email
                c.user.email.confirmed = confirmed
                email_confirmation_request(c.user, email)
                sign_in_user(c.user)

            # handle phone number
            phone_number = self.form_result['phone_number']
            phone_confirmation_key = self.form_result['phone_confirmation_key']

            if self.form_result['resend_phone_code']:
                sms.confirmation_request(c.user)
            elif phone_number != c.user.phone_number:
                c.user.phone_number = phone_number
                c.user.phone_confirmed = False
                if phone_number:
                    # new number
                    if c.user.is_teacher:
                        # don't asks confirmations from teachers
                        c.user.phone_confirmed = True
                    else:
                        sms.confirmation_request(c.user)
            elif phone_confirmation_key:
                c.user.confirm_phone_number()

        meta.Session.commit()
        h.flash(_('Your contact information was updated.'))
        redirect(url(controller='profile', action='edit_contacts'))