Changeset 11977 for main/waeup.ikoba/trunk/src
- Timestamp:
- 17 Nov 2014, 06:29:21 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba
- Files:
-
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/browser/pages.py
r11975 r11977 262 262 login_button = label 263 263 264 def _comment(self, customer): 265 return getattr(customer, 'suspended_comment', None) 266 264 267 def update(self, SUBMIT=None, camefrom=None): 265 268 self.camefrom = camefrom … … 1613 1616 def _searchUser(self, identifier, email): 1614 1617 # Search customer 1615 #cat = queryUtility(ICatalog, name='customers_catalog') 1616 #results = cat.searchResults( 1617 #reg_number=(identifier, identifier), 1618 # email=(email,email)) 1619 #for result in results: 1620 # if result.customer_id == identifier or \ 1621 # result.reg_number == identifier or \ 1622 # result.matric_number == identifier: 1623 # return result 1618 cat = queryUtility(ICatalog, name='customers_catalog') 1619 results = cat.searchResults( 1620 reg_number=(identifier, identifier), 1621 email=(email,email)) 1622 for result in results: 1623 if result.customer_id == identifier \ 1624 or result.reg_number == identifier: 1625 return result 1624 1626 # Search portal user 1625 1627 user = grok.getSite()['users'].get(identifier, None) -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py
r11971 r11977 42 42 from waeup.ikoba.browser.breadcrumbs import Breadcrumb 43 43 from waeup.ikoba.browser.interfaces import ICaptchaManager 44 from waeup.ikoba.mandates.mandate import PasswordMandate 44 45 from waeup.ikoba.utils.helpers import get_current_principal, to_timezone, now 45 46 from waeup.ikoba.customers.interfaces import ( 46 ICustomer, ICustomersContainer, ICustomerRequestPW 47 ICustomer, ICustomersContainer, ICustomerRequestPW, ICustomersUtils 47 48 ) 48 49 from waeup.ikoba.customers.catalog import search … … 507 508 self._redirect(email=email_sent, password=password, 508 509 customer_id=customer.customer_id) 509 ob_class = self.__implemented__.__name__.replace('waeup. kofa.','')510 ob_class = self.__implemented__.__name__.replace('waeup.ikoba.','') 510 511 self.context.logger.info( 511 512 '%s - %s (%s) - %s' % (ob_class, number, customer.customer_id, email_sent)) … … 567 568 """ 568 569 grok.context(ICustomer) 569 grok.name('change _password')570 grok.name('changepassword') 570 571 grok.require('waeup.handleCustomer') 571 grok.template('change _password')572 grok.template('changepassword') 572 573 label = _('Change password') 573 574 pnav = 4 -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser_templates/changepassword.pt
r11971 r11977 2 2 i18n:domain="waeup.kofa" enctype="multipart/form-data"> 3 3 4 <input type="hidden" name=" student_id" value=""5 tal:attributes="value context/ student_id" />4 <input type="hidden" name="customer_id" value="" 5 tal:attributes="value context/customer_id" /> 6 6 7 7 <table class="form-table"> -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_authentication.py
r11972 r11977 237 237 self.assertRaises( 238 238 Unauthorized, 239 self.browser.open, self.customer_path + '/change _password')240 return 239 self.browser.open, self.customer_path + '/changepassword') 240 return -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py
r11975 r11977 498 498 'mrofficer - customers.browser.LoginAsCustomerStep1 - K1000000 - ' 499 499 'temp_password generated: %s' % temp_password in logcontent) 500 501 class CustomerUITests(CustomersFullSetup): 502 # Tests for Customer class views and pages 503 504 def test_customer_change_password(self): 505 # Customers can change the password 506 self.customer.personal_updated = datetime.utcnow() 507 self.browser.open(self.login_path) 508 self.browser.getControl(name="form.login").value = self.customer_id 509 self.browser.getControl(name="form.password").value = 'spwd' 510 self.browser.getControl("Login").click() 511 self.assertEqual(self.browser.url, self.customer_path) 512 self.assertTrue('You logged in' in self.browser.contents) 513 # Change password 514 self.browser.getLink("Change password").click() 515 self.browser.getControl(name="change_password").value = 'pw' 516 self.browser.getControl( 517 name="change_password_repeat").value = 'pw' 518 self.browser.getControl("Save").click() 519 self.assertTrue('Password must have at least' in self.browser.contents) 520 self.browser.getControl(name="change_password").value = 'new_password' 521 self.browser.getControl( 522 name="change_password_repeat").value = 'new_passssword' 523 self.browser.getControl("Save").click() 524 self.assertTrue('Passwords do not match' in self.browser.contents) 525 self.browser.getControl(name="change_password").value = 'new_password' 526 self.browser.getControl( 527 name="change_password_repeat").value = 'new_password' 528 self.browser.getControl("Save").click() 529 self.assertTrue('Password changed' in self.browser.contents) 530 # We are still logged in. Changing the password hasn't thrown us out. 531 self.browser.getLink("Base Data").click() 532 self.assertEqual(self.browser.url, self.customer_path) 533 # We can logout 534 self.browser.getLink("Logout").click() 535 self.assertTrue('You have been logged out' in self.browser.contents) 536 self.assertEqual(self.browser.url, 'http://localhost/app/index') 537 # We can login again with the new password 538 self.browser.getLink("Login").click() 539 self.browser.open(self.login_path) 540 self.browser.getControl(name="form.login").value = self.customer_id 541 self.browser.getControl(name="form.password").value = 'new_password' 542 self.browser.getControl("Login").click() 543 self.assertEqual(self.browser.url, self.customer_path) 544 self.assertTrue('You logged in' in self.browser.contents) 545 return 546 547 def test_customer_upload_passport(self): 548 # Customer cant login if their password is not set 549 IWorkflowInfo(self.customer).fireTransition('start') 550 self.browser.open(self.login_path) 551 self.browser.getControl(name="form.login").value = self.customer_id 552 self.browser.getControl(name="form.password").value = 'spwd' 553 self.browser.getControl("Login").click() 554 self.assertMatches( 555 '...You logged in...', self.browser.contents) 556 # Admitted customer can upload a passport picture 557 self.browser.open(self.customer_path + '/change_portrait') 558 ctrl = self.browser.getControl(name='passportuploadedit') 559 file_obj = open(SAMPLE_IMAGE, 'rb') 560 file_ctrl = ctrl.mech_control 561 file_ctrl.add_file(file_obj, filename='my_photo.jpg') 562 self.browser.getControl( 563 name='upload_passportuploadedit').click() 564 self.assertTrue( 565 'src="http://localhost/app/customers/K1000000/passport.jpg"' 566 in self.browser.contents) 567 568 def test_customer_login(self): 569 # Customer cant login if their password is not set 570 self.customer.password = None 571 self.browser.open(self.login_path) 572 self.browser.getControl(name="form.login").value = self.customer_id 573 self.browser.getControl(name="form.password").value = 'spwd' 574 self.browser.getControl("Login").click() 575 self.assertTrue( 576 'You entered invalid credentials.' in self.browser.contents) 577 # We set the password again 578 IUserAccount( 579 self.app['customers'][self.customer_id]).setPassword('spwd') 580 # Customers can't login if their account is suspended/deactivated 581 self.customer.suspended = True 582 self.browser.open(self.login_path) 583 self.browser.getControl(name="form.login").value = self.customer_id 584 self.browser.getControl(name="form.password").value = 'spwd' 585 self.browser.getControl("Login").click() 586 self.assertMatches( 587 '...<div class="alert alert-warning">' 588 'Your account has been deactivated.</div>...', self.browser.contents) 589 # If suspended_comment is set this message will be flashed instead 590 self.customer.suspended_comment = u'Aetsch baetsch!' 591 self.browser.getControl(name="form.login").value = self.customer_id 592 self.browser.getControl(name="form.password").value = 'spwd' 593 self.browser.getControl("Login").click() 594 self.assertMatches( 595 '...<div class="alert alert-warning">Aetsch baetsch!</div>...', 596 self.browser.contents) 597 self.customer.suspended = False 598 # Customers can't login if a temporary password has been set and 599 # is not expired 600 self.app['customers'][self.customer_id].setTempPassword( 601 'anybody', 'temp_spwd') 602 self.browser.open(self.login_path) 603 self.browser.getControl(name="form.login").value = self.customer_id 604 self.browser.getControl(name="form.password").value = 'spwd' 605 self.browser.getControl("Login").click() 606 self.assertMatches( 607 '...Your account has been temporarily deactivated...', 608 self.browser.contents) 609 # The customer can login with the temporary password 610 self.browser.open(self.login_path) 611 self.browser.getControl(name="form.login").value = self.customer_id 612 self.browser.getControl(name="form.password").value = 'temp_spwd' 613 self.browser.getControl("Login").click() 614 self.assertMatches( 615 '...You logged in...', self.browser.contents) 616 # Customer can view the base data 617 self.browser.open(self.customer_path) 618 self.assertEqual(self.browser.headers['Status'], '200 Ok') 619 self.assertEqual(self.browser.url, self.customer_path) 620 # When the password expires ... 621 delta = timedelta(minutes=11) 622 self.app['customers'][self.customer_id].temp_password[ 623 'timestamp'] = datetime.utcnow() - delta 624 self.app['customers'][self.customer_id]._p_changed = True 625 # ... the customer will be automatically logged out 626 self.assertRaises( 627 Unauthorized, self.browser.open, self.customer_path) 628 # Then the customer can login with the original password 629 self.browser.open(self.login_path) 630 self.browser.getControl(name="form.login").value = self.customer_id 631 self.browser.getControl(name="form.password").value = 'spwd' 632 self.browser.getControl("Login").click() 633 self.assertMatches( 634 '...You logged in...', self.browser.contents) 635 636 def test_change_password_request(self): 637 self.browser.open('http://localhost/app/changepw') 638 self.browser.getControl(name="form.identifier").value = '123' 639 self.browser.getControl(name="form.email").value = 'aa@aa.ng' 640 self.browser.getControl("Send login credentials").click() 641 self.assertTrue('An email with' in self.browser.contents) 642 643 class CustomerRequestPWTests(CustomersFullSetup): 644 # Tests for customer registration 645 646 layer = FunctionalLayer 647 648 def test_request_pw(self): 649 # Customer with wrong number can't be found. 650 self.browser.open('http://localhost/app/requestpw') 651 self.browser.getControl(name="form.firstname").value = 'Anna' 652 self.browser.getControl(name="form.number").value = 'anynumber' 653 self.browser.getControl(name="form.email").value = 'xx@yy.zz' 654 self.browser.getControl("Send login credentials").click() 655 self.assertTrue('No customer record found.' 656 in self.browser.contents) 657 # Anonymous is not informed that firstname verification failed. 658 # It seems that the record doesn't exist. 659 self.browser.open('http://localhost/app/requestpw') 660 self.browser.getControl(name="form.firstname").value = 'Johnny' 661 self.browser.getControl(name="form.number").value = '123' 662 self.browser.getControl(name="form.email").value = 'xx@yy.zz' 663 self.browser.getControl("Send login credentials").click() 664 self.assertTrue('No customer record found.' 665 in self.browser.contents) 666 # Even with the correct firstname we can't register if a 667 # password has been set and used. 668 self.browser.getControl(name="form.firstname").value = 'Anna' 669 self.browser.getControl(name="form.number").value = '123' 670 self.browser.getControl("Send login credentials").click() 671 self.assertTrue('Your password has already been set and used.' 672 in self.browser.contents) 673 self.browser.open('http://localhost/app/requestpw') 674 self.app['customers'][self.customer_id].password = None 675 # The firstname field, used for verification, is not case-sensitive. 676 self.browser.getControl(name="form.firstname").value = 'aNNa' 677 self.browser.getControl(name="form.number").value = '123' 678 self.browser.getControl(name="form.email").value = 'new@yy.zz' 679 self.browser.getControl("Send login credentials").click() 680 # Yeah, we succeded ... 681 self.assertTrue('Your password request was successful.' 682 in self.browser.contents) 683 # ... and customer can be found in the catalog via the email address 684 cat = queryUtility(ICatalog, name='customers_catalog') 685 results = list( 686 cat.searchResults( 687 email=('new@yy.zz', 'new@yy.zz'))) 688 self.assertEqual(self.customer,results[0]) 689 logfile = os.path.join( 690 self.app['datacenter'].storage, 'logs', 'main.log') 691 logcontent = open(logfile).read() 692 self.assertTrue('zope.anybody - customers.browser.CustomerRequestPasswordPage - ' 693 '123 (K1000000) - new@yy.zz' in logcontent) 694 return -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/viewlets.py
r11967 r11977 234 234 return "return window.confirm(%s);" % _( 235 235 "'A history message will be added. Are you sure?'") 236 237 class CustomerPasswordActionButton(ManageActionButton): 238 grok.order(2) 239 grok.context(ICustomer) 240 grok.view(CustomerBaseDisplayFormPage) 241 grok.require('waeup.handleCustomer') 242 icon = 'actionicon_key.png' 243 text = _('Change password') 244 target = 'changepassword'
Note: See TracChangeset for help on using the changeset viewer.