def user_add_email(user, email): email = _unicode_fix(email) code = user.add_unconfirmed_email(email) transaction_commit(user, 'AddEmail') # moved from user.ptl/AddEmailForm.commit() message = _(_confirm_email_message) % dict(email=email, base_url=messages.base_url, url=qon.ui.blocks.user.path_to_user(user)[1:] + 'private/confirm', code=code) sendmail("ned.com Confirm New Email", message, [email]) inform = _(_notify_new_email_message) % dict( primary=user.get_primary_email(), new=email) sendmail("ned.com Email Added", inform, [user.get_primary_email()]) qon.search.searchengine.notify_edited_user(user) return (email, message)
def user_data(self, login_bundle, atom_tag, fields): """Return struct containing requested fields for user atom_tag. Parameters: atom_tag: the atom tag of the user for which requesting data fields: array of zero or more of the following: 'name': currently-specified name to be displayed 'fscore': feedback score 'fbank': feedback bank 'fpos': positive feedback received 'fneg': negative feedback received 'fposgiv': positive feedback given 'fneggiv': negative feedback given 'fcom': net comment feedback received 'fcompos': positive comment feedback received 'fcomneg': negative comment feedback received 'membsince': member since date 'lastlogin': last login (may return 'never' or 'inactive') 'idletime': idle time or 'none' if not logged in 'posffrom': positive feedback from (array of user_ids) 'posffromnum': number of positive feedback givers 'negffrom': negative feedback from (if visible) 'neggfromnum': number of negative feedback givers 'emaildomain: domain portion of email 'groupown': groups owned by user 'groupmemb': groups user is a member of 'all': all of the above Returns struct containing one entry per requested field. """ user_db = get_user_database() group_db = get_group_database() cur_user = self._check_login(login_bundle) user = lookup_atom_id(atom_tag) if not user or not isinstance(user, qon.user.User): raise xmlrpclib.Fault(FAULT_INVALID_ITEM, 'Invalid user id') all = 'all' in fields result = {} if all or 'name' in fields: result['name'] = user.display_name() if all or 'fscore' in fields: result['fscore'] = user.get_karma_score() if all or 'fbank' in fields: result['fbank'] = user.get_karma_bank_balance() if all or 'fpos' in fields: result['fpos'] = user.karma_plus_received() if all or 'fneg' in fields: result['fneg'] = user.karma_minus_received() if all or 'fposgiv' in fields: result['fposgiv'] = user.karma_plus_given() if all or 'fneggiv' in fields: result['fneggiv'] = user.karma_minus_given() if all or ('fcom' in fields) or ('fcompos' in fields) or ('fcomneg' in fields): fcompos, fcomneg = get_list_database().karma_user_content_totals(user) if all or 'fcom' in fields: result['fcom'] = fcompos + fcomneg if all or 'fcompos' in fields: result['fcompos'] = fcompos if all or 'fcomneg' in fields: result['fcomneg'] = fcomneg if all or 'membsince' in fields: dt = user.get_user_data().member_since() result['membsince'] = _format_dt(dt) if all or 'lastlogin' in fields: result['lastlogin'] = _format_dt(getattr(user, 'last_login', None)) if all or 'idletime' in fields: if user.is_disabled(): sec = 'inactive' else: idle = user.idle_time() if idle: sec = idle.seconds else: sec = 'none' result['idletime'] = sec if all or 'posffrom' in fields: result['posffrom'] = [atom_id(user_db.get_user(uid)) \ for karma, uid in user.positive_karma_givers()] if all or 'posffromnum' in fields: result['posffromnum'] = len(user.positive_karma_givers()) if all or 'negffrom' in fields: result['negffrom'] = [atom_id(user_db.get_user(uid)) \ for karma, uid in user.negative_karma_givers()] if all or 'negffromnum' in fields: result['negffromnum'] = len(user.negative_karma_givers()) if all or 'emaildomain' in fields: e = user.get_primary_email() result['emaildomain'] = e[e.find('@')+1:] if all or 'groupown' in fields: result['groupown'] = [atom_id(g) \ for g in group_db.owned_groups(user)] if all or 'groupmemb' in fields: result['groupmemb'] = [atom_id(g) \ for g in group_db.member_groups(user)] return result