def register(name, password, email, create_wiki_account=True): try: a = Account._by_name(name) raise AccountExists except NotFound: a = Account(name=name, password=passhash(name, password, True)) a.email = email a.confirmation_code = random_key(6) a.email_validated = False a.wiki_account = '__error__' a._commit() from r2.lib import emailer emailer.confirmation_email(a) if create_wiki_account: if wiki_account.valid_name(name): def send_wiki_failed_email(): emailer.wiki_failed_email(a) a.create_associated_wiki_account( password, on_request_error=send_wiki_failed_email) else: emailer.wiki_incompatible_name_email(a) # Clear memoization of both with and without deleted clear_memo('account._by_name', Account, name.lower(), True) clear_memo('account._by_name', Account, name.lower(), False) return a
def register(name, password, email): try: a = Account._by_name(name) raise AccountExists except NotFound: a = Account(name = name, password = passhash(name, password, True)) a.email = email a.confirmation_code = random_key(6) a.email_validated = False a.wiki_account = '__error__' a._commit() from r2.lib import emailer emailer.confirmation_email(a) if wiki_account.valid_name(name): def send_wiki_failed_email(): emailer.wiki_failed_email(a) a.create_associated_wiki_account(password, on_request_error=send_wiki_failed_email) else: emailer.wiki_incompatible_name_email(a) # Clear memoization of both with and without deleted clear_memo('account._by_name', Account, name.lower(), True) clear_memo('account._by_name', Account, name.lower(), False) return a
def attempt_wiki_association(self): '''Attempt to find a wiki account with the same name as the user.''' with g.make_lock('wiki_associate_' + self.name): if self.wiki_association_attempted_at is not None: return from r2.models.link import Message self.wiki_association_attempted_at = datetime.now(g.tz) self.wiki_account = '__error__' if wiki_account.valid_name(self.name): try: if wiki_account.exists(self.name): self.wiki_account = self.name else: self.wiki_account = None Message._new(Account._by_name(g.admin_account), self, 'Wiki Account', Account.WIKI_INVITE, None) except urllib2.URLError as e: g.log.error('error in attempt_wiki_association()') self._commit()