(self, to, accepted_domains=[], accept_any=False, accepted_pattern=None)
| 766 | |
| 767 | # Select certificate for site |
| 768 | def actionCertSelect(self, to, accepted_domains=[], accept_any=False, accepted_pattern=None): |
| 769 | accounts = [] |
| 770 | accounts.append(["", _["No certificate"], ""]) # Default option |
| 771 | active = "" # Make it active if no other option found |
| 772 | |
| 773 | # Add my certs |
| 774 | auth_address = self.user.getAuthAddress(self.site.address) # Current auth address |
| 775 | site_data = self.user.getSiteData(self.site.address) # Current auth address |
| 776 | |
| 777 | if not accepted_domains and not accepted_pattern: # Accept any if no filter defined |
| 778 | accept_any = True |
| 779 | |
| 780 | for domain, cert in list(self.user.certs.items()): |
| 781 | if auth_address == cert["auth_address"] and domain == site_data.get("cert"): |
| 782 | active = domain |
| 783 | title = cert["auth_user_name"] + "@" + domain |
| 784 | accepted_pattern_match = accepted_pattern and SafeRe.match(accepted_pattern, domain) |
| 785 | if domain in accepted_domains or accept_any or accepted_pattern_match: |
| 786 | accounts.append([domain, title, ""]) |
| 787 | else: |
| 788 | accounts.append([domain, title, "disabled"]) |
| 789 | |
| 790 | # Render the html |
| 791 | body = "<span style='padding-bottom: 5px; display: inline-block'>" + _["Select account you want to use in this site:"] + "</span>" |
| 792 | # Accounts |
| 793 | for domain, account, css_class in accounts: |
| 794 | if domain == active: |
| 795 | css_class += " active" # Currently selected option |
| 796 | title = _("<b>%s</b> <small>({_[currently selected]})</small>") % account |
| 797 | else: |
| 798 | title = "<b>%s</b>" % account |
| 799 | body += "<a href='#Select+account' class='select select-close cert %s' title='%s'>%s</a>" % (css_class, domain, title) |
| 800 | # More available providers |
| 801 | more_domains = [domain for domain in accepted_domains if domain not in self.user.certs] # Domains we not displayed yet |
| 802 | if more_domains: |
| 803 | # body+= "<small style='margin-top: 10px; display: block'>Accepted authorization providers by the site:</small>" |
| 804 | body += "<div style='background-color: #F7F7F7; margin-right: -30px'>" |
| 805 | for domain in more_domains: |
| 806 | body += _(""" |
| 807 | <a href='/{domain}' target='_top' class='select'> |
| 808 | <small style='float: right; margin-right: 40px; margin-top: -1px'>{_[Register]} »</small>{domain} |
| 809 | </a> |
| 810 | """) |
| 811 | body += "</div>" |
| 812 | |
| 813 | script = """ |
| 814 | $(".notification .select.cert").on("click", function() { |
| 815 | $(".notification .select").removeClass('active') |
| 816 | zeroframe.response(%s, this.title) |
| 817 | return false |
| 818 | }) |
| 819 | """ % self.next_message_id |
| 820 | |
| 821 | self.cmd("notification", ["ask", body], lambda domain: self.actionCertSet(to, domain)) |
| 822 | self.cmd("injectScript", script) |
| 823 | |
| 824 | # - Admin actions - |
| 825 |
nothing calls this directly
no test coverage detected